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