# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
38717 | Talant | Monkey and Apple-trees (IZhO12_apple) | C++14 | 603 ms | 122328 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 fr first
#define sc second
#define OK puts("OK");
#define pb push_back
#define mk make_pair
using namespace std;
typedef long long ll;
const int inf = (int)1e9 + 7;
const int N = (int)7e6 + 7e5;
int n;
int type,x,y,c;
int cnt = 1;
struct node {
int l,r,sum,add;
node () {
l = r = add = sum = 0;
}
}t[N];
void push (int v,int tl,int tr) {
if (t[v].add != 0) {
if (!t[v].l)
t[v].l = ++cnt;
if (!t[v].r)
t[v].r = ++cnt;
t[t[v].l].add = t[v].add;
t[t[v].r].add = t[v].add;
t[v].sum = (tr - tl + 1);
}
t[v].add = 0;
}
void update (int l,int r,int v = 1,int tl = 1,int tr = 1e9 + 7) {
if (tl > r || tr < l)
return;
if (t[v].add != 0)
push (v,tl,tr);
if (l <= tl && tr <= r) {
t[v].add = 1;
}
else {
int tm = (tl + tr) >> 1;
if (t[v].l == 0)
t[v].l = ++cnt;
if (t[v].r == 0)
t[v].r = ++cnt;
update (l,r,t[v].l,tl,tm);
update (l,r,t[v].r,tm + 1,tr);
push (v,tl,tr);
push (t[v].l,tl,tm);
push (t[v].r,tm + 1,tr);
t[v].sum = t[t[v].l].sum + t[t[v].r].sum;
}
}
int get (int l,int r,int v = 1,int tl = 1,int tr = 1e9 + 7) {
if (tl > r || tr < l)
return 0;
push (v,tl,tr);
if (l <= tl && tr <= r)
return t[v].sum;
int tm = (tl + tr) >> 1;
return get (l,r,t[v].l,tl,tm) + get(l,r,t[v].r,tm + 1,tr);
}
int main () {
scanf ("%d", &n);
for (int i = 1; i <= n; i ++) {
scanf ("%d%d%d", &type,&x,&y);
x += c;
y += c;
if (type == 1) {
c = get(x,y);
printf("%d\n", c);
}
else {
update (x,y);
}
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |