Académique Documents
Professionnel Documents
Culture Documents
// main.cpp
// practice
//
// Created by Mahmud on 01/31/18.
// Copyright © 2017 Mahmud. All rights reserved.
//
// https://www.e-olymp.com/en/problems/2310
#include <iostream>
#include <cmath>
#include <algorithm>
#include <ctime>
#include <climits>
#include <functional>
#include <cassert>
struct node {
int value;
int priority;
long long subtreeSum;
node *leftChild;
node *rightChild;
node () {
}
};
typedef node* tree;
tree t = NULL;
int queries, value, low, high;
int last = INT_MIN;
char type;
int main() {
srand(unsigned(time(NULL)));
fastInput(queries);
while (queries --) {
type = getchar_unlocked();
if (type == '+') {
fastInput(value);
if (last != INT_MIN) value = (value + last) % MODULO;
Insert(t, value);
last = INT_MIN;
}
else {
fastInput(low);
fastInput(high);
long long result = getSum(t, high) - getSum(t, low - 1);
//cerr << "sum to high: " << getSum(t, high) << endl;
//cerr << "sum to low - 1: " << getSum(t, low - 1) << endl;
last = result % MODULO;
printf("%lld\n", result);
}
}
return 0;
}