Submission #1114419

# Submission time Handle Problem Language Result Execution time Memory
1114419 2024-11-18T20:22:54 Z nikolashami Monkey and Apple-trees (IZhO12_apple) C++17
100 / 100
161 ms 72008 KB
#include <bits/stdc++.h>
using namespace std;

const int N=1e7;
int lc[N],rc[N],ans,m,c,id=1;
struct{int s=0,lz=0;}st[N];

void make(int&node){
	if(!node)node=++id;
}

void push(int node,int l,int r){
	if(!st[node].lz)
		return;
	int mid=(l+r)/2;
	st[lc[node]].s=mid-l+1;
	st[rc[node]].s=r-mid;
	st[lc[node]].lz=1;
	st[rc[node]].lz=1;
	st[node].lz=0;
}

void qry(int l,int r,int node=1,int tl=1,int tr=1e9){
	if(tl>=l&&tr<=r){
		ans+=st[node].s;
		return;
	}
	make(lc[node]);
	make(rc[node]);
	push(node,tl,tr);
	int mid=(tl+tr)/2;
	if(mid>=l)qry(l,r,lc[node],tl,mid);
	if(mid+1<=r)qry(l,r,rc[node],mid+1,tr);
}

void upd(int l,int r,int node=1,int tl=1,int tr=1e9){
	if(tl>=l&&tr<=r){
		st[node].s=tr-tl+1;	
		st[node].lz=1;
		return;
	}
	make(lc[node]);
	make(rc[node]);
	push(node,tl,tr);
	int mid=(tl+tr)/2;
	if(mid>=l)upd(l,r,lc[node],tl,mid);
	if(mid+1<=r)upd(l,r,rc[node],mid+1,tr);
	st[node].s=st[lc[node]].s+st[rc[node]].s;
}

signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    cin>>m;
    while(m--){
    	int tp,l,r;
    	cin>>tp>>l>>r;
    	if(tp==1){
    		ans=0;
    		qry(l+c,r+c);
    		c=ans;
    		cout<<ans<<'\n';
    	}else
    		upd(l+c,r+c);
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 7 ms 1872 KB Output is correct
5 Correct 8 ms 2128 KB Output is correct
6 Correct 8 ms 2128 KB Output is correct
7 Correct 8 ms 2140 KB Output is correct
8 Correct 49 ms 15908 KB Output is correct
9 Correct 100 ms 27464 KB Output is correct
10 Correct 103 ms 28760 KB Output is correct
11 Correct 116 ms 31900 KB Output is correct
12 Correct 108 ms 32448 KB Output is correct
13 Correct 100 ms 37108 KB Output is correct
14 Correct 97 ms 37132 KB Output is correct
15 Correct 144 ms 69204 KB Output is correct
16 Correct 152 ms 71040 KB Output is correct
17 Correct 100 ms 42056 KB Output is correct
18 Correct 107 ms 42056 KB Output is correct
19 Correct 152 ms 72008 KB Output is correct
20 Correct 161 ms 72008 KB Output is correct