# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
89809 | Vardanyan | Monkey and Apple-trees (IZhO12_apple) | C++14 | 570 ms | 133340 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;
struct node{
int val,lz;
};
const int N = 1000*1000+5;
node t[10*N];
int son1[10*N];
int son2[10*N];
int timer = 1;
void push(int v,int s,int e){
if(t[v].lz!=0){
t[v].val = (e-s+1)*(t[v].lz);
if(s!=e){
if(son1[v] == 0){
son1[v] = ++timer;
son2[v] = ++timer;
}
t[son1[v]].lz = 1;
t[son2[v]].lz = 1;
// t[son1[v]]->lz = t[v].lz;
//t[v].r->lz = t[v].lz;
}
}
t[v].lz = 0;
}
void update(int v,int s,int e,int l,int r,int val){
push(v,s,e);
if(l>r) return;
if(s == l && e == r){
t[v].lz = val;
return;
}
int m = (s+e)/2;
if(son1[v] == 0){
son1[v] = ++timer;
son2[v] = ++timer;
}
update(son1[v],s,m,l,min(m,r),val);
update(son2[v],m+1,e,max(l,m+1),r,val);
push(son1[v],s,m);
push(son2[v],m+1,e);
t[v].val = t[son1[v]].val+t[son2[v]].val;
}
int get(int v,int s,int e,int l,int r){
push(v,s,e);
if(l>r) return 0;
if(s == l && e == r) return t[v].val;
int m = (s+e)/2;
return get(son1[v],s,m,l,min(m,r))+
get(son2[v],m+1,e,max(l,m+1),r);
}
int main(){
int m;
scanf("%d",&m);
int C = 0;
while(m--){
int d,x,y;
scanf("%d%d%d",&d,&x,&y);
if(d == 1){
int ans = get(1,1,1000*1000*1000,x+C,y+C);
C = ans;
printf("%d\n",ans);
}
else{
update(1,1,1000*1000*1000,x+C,y+C,1);
}
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |