| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 938971 | vjudge1 | 원숭이와 사과 나무 (IZhO12_apple) | C++17 | 255 ms | 262144 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 sum, l, r, lazy, ll, lr;
	node(): sum(0), lazy(0), l(-1), r(-1){}
};
node tr[1000000];
int temp=1;
void create(int now){
		int mid=(tr[now].ll+tr[now].lr)>>1;
		if (tr[now].l==-1){
			tr[now].l=temp;
			tr[temp].ll=tr[now].ll;
			tr[temp].lr=mid;
			temp++;
		}
		if (tr[now].r==-1){
			tr[now].r=temp;
			tr[temp].ll=mid+1;
			tr[temp].lr=tr[now].lr;
			temp++;
		}
}
void push(int now){
	create(now);
	if (tr[now].lazy){
		tr[now].sum=tr[now].lr-tr[now].ll+1;
		tr[tr[now].l].lazy=1;
		tr[tr[now].r].lazy=1;
		tr[now].lazy=0;
	}
}
void update(int now, int ql, int qr){
	int l=tr[now].ll, r=tr[now].lr;
	push(now);
	if (ql<=l and r<=qr){
		tr[now].lazy=1;
		push(now);
	} else{
		int mid=(tr[now].ll+tr[now].lr)>>1;
		int cl=tr[now].l, cr=tr[now].r;
		if (ql<=mid) update(cl, ql, qr);
		if (qr>mid) update(cr, ql, qr);
		push(cl);
		push(cr);
		tr[now].sum=tr[cl].sum+tr[cr].sum;
	}
}
int get(int now, int ql, int qr){
	int l=tr[now].ll, r=tr[now].lr;
	push(now);
	if (ql<=l and r<=qr){
		return tr[now].sum;
	} else{
		int mid=(tr[now].ll+tr[now].lr)>>1;
		int cl=tr[now].l, cr=tr[now].r;
		push(cl);
		push(cr);
		int a=0, b=0;
		if (ql<=mid) a=get(cl, ql, qr);
		if (qr>mid) b=get(cr, ql, qr);
		return a+b;
	}
}
int main(){
	int m;
	cin>>m;
	tr[0].sum=0;
	tr[0].ll=1;
	tr[0].lr=1e9;
	int c=0;
	while(m--){
		int d, x, y;
		cin>>d>>x>>y;
		if (d==1){
			c=get(0, x+c, y+c);
			cout<<c<<endl;
		} else{
			update(0, x+c, y+c);
		}
	}
	return 0;
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
