# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
853213 | serifefedartar | Monkey and Apple-trees (IZhO12_apple) | C++17 | 326 ms | 164000 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0);
#define s second
#define f first
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll LOGN = 20;
const ll MAXN = 2e5 + 5;
struct Node {
int l, r;
int sum = 0, lazy = 0;
Node *ptrL, *ptrR;
Node(int a, int b) : l(a), r(b), ptrL(NULL), ptrR(NULL) { };
void add() {
if (ptrL == NULL && l != r) {
int mid = (l + r) / 2;
ptrL = new Node(l, mid);
ptrR = new Node(mid+1, r);
}
}
void push() {
if (lazy) {
sum = r - l + 1;
if (l != r) {
add();
ptrL->lazy = 1;
ptrR->lazy = 1;
}
lazy = 0;
}
}
void update(int a, int b) {
push();
if (l > b || a > r)
return ;
if (a <= l && r <= b) {
lazy = 1;
push();
return ;
}
add();
ptrL->update(a, b);
ptrR->update(a, b);
sum = ptrL->sum + ptrR->sum;
}
int query(int a, int b) {
push();
if (l > b || a > r)
return 0;
if (a <= l && r <= b)
return sum;
add();
return ptrL->query(a, b) + ptrR->query(a, b);
}
};
int main() {
fast
int M;
cin >> M;
Node *root = new Node(1, 1e8);
int C = 0;
while (M--) {
int D, X, Y;
cin >> D >> X >> Y;
X += C;
Y += C;
if (D == 1) {
C = root->query(X, Y);
cout << C << "\n";
} else {
root->update(X, Y);
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |