# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
96062 | Shafin666 | Monkey and Apple-trees (IZhO12_apple) | C++14 | 2 ms | 380 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>
#define mp make_pair
#define pb push_back
#define pii pair<int, int>
#define to second
#define cost first
typedef long long ll;
typedef long double ld;
using namespace std;
struct Node {
int sum, lazy;
Node *l, *r;
Node() : sum(0), lazy(0), l(NULL), r(NULL) { }
}; Node *root;
void propagate(Node *v, int len) {
if(v->lazy) {
if(v->l == NULL) v->l = new Node;
v->l->sum = len/2;
v->l->lazy = 1;
if(v->r == NULL) v->r = new Node;
v->r->sum = len/2;
v->r->lazy = 1;
v->sum = len;
v->lazy = 0;
}
}
void add(Node *v, int L, int R, int l, int r) {
if(L > R || r < L || l > R) return;
if(L >= l && R <= r) {
v->sum = (R-L+1);
v->lazy = 1;
return;
}
propagate(v, R-L+1);
int mid = (L+R)/2;
if(l <= mid) {
if(v->l == NULL) v->l = new Node;
add(v->l, L, mid, l, r);
}
if(mid < r) {
if(v->r == NULL) v->r = new Node;
add(v->r, mid+1, R, l, r);
}
v->sum = 0;
if(v->l != NULL) v->sum += v->l->sum;
if(v->r != NULL) v->sum += v->r->sum;
}
int get(Node *v, int L, int R, int l, int r) {
if(v == NULL) return 0;
if(L > R || r < L || l > R) return 0;
int mid = (L+R)/2;
int ans = 0;
propagate(v, R-L+1);
if(L >= l && R <= r) return v->sum;
if(l <= mid) ans += get(v->l, L, mid, l, r);
if(mid < r) ans += get(v->r, mid+1, R, l, r);
return ans;
}
void update(int x, int y) { add(root, 1, (1<<30), x, y); }
int query(int x, int y) { return get(root, 1, (1<<30), x, y); }
int main()
{
int n, c = 0;
int x, l, r;
root = new Node;
cin >> n;
while(n--) {
cin >> x >> l >> r;
if(x == 2) update(l+c, r+c);
else {
int ans = query(l+c, r+c);
c += ans;
cout << ans << endl;
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |