답안 #998409

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
998409 2024-06-14T00:11:19 Z amirhoseinfar1385 원숭이와 사과 나무 (IZhO12_apple) C++17
100 / 100
50 ms 3164 KB
#include<bits/stdc++.h>
using namespace std;
int c;
struct node{
	int cl,cr;
	int res=0,f=0;
	node(){
		cl=cr=-1;
		res=f=0;
	}
}fakenode;
vector<node>all(1);

int getl(int u){
	if(all[u].cl==-1){
		all[u].cl=(int)all.size();
		all.push_back(fakenode);
	}
	return all[u].cl;
}

int getr(int u){
	if(all[u].cr==-1){
		all[u].cr=(int)all.size();
		all.push_back(fakenode);
	}
	return all[u].cr;
}

void upd(int u,int l,int r,int tl,int tr){
	if(l>r||l>tr||r<tl||tl>tr||all[u].f==1){
		return ;
	}
	if(l>=tl&&r<=tr){
		all[u].cl=all[u].cr=-1;
		all[u].res=r-l+1;
		all[u].f=1;
		return ;
	}
	int m=(l+r)>>1;
	upd(getl(u),l,m,tl,tr);
	upd(getr(u),m+1,r,tl,tr);
	all[u].res=(all[getr(u)]).res+(all[getl(u)].res);
}

int pors(int u,int l,int r,int tl,int tr){
	if(l>r||l>tr||r<tl||tl>tr||all[u].res==0){
		return 0;
	}
	if((all[u].f)==1){
		return min(r,tr)-max(l,tl)+1;
	}
	int m=(l+r)>>1;
	return pors(getl(u),l,m,tl,tr)+pors(getr(u),m+1,r,tl,tr);
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin>>t;
	for(int asd=0;asd<t;asd++){
		int qq;
		cin>>qq;
		int l,r;
		cin>>l>>r;
		l+=c;
		r+=c;
		if(qq==1){
			int res=pors(0,0,1073741824-1,l,r);
			cout<<res<<"\n";
			c=res;
		}else{
			upd(0,0,1073741824-1,l,r);
		}
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 4 ms 604 KB Output is correct
5 Correct 5 ms 464 KB Output is correct
6 Correct 5 ms 648 KB Output is correct
7 Correct 5 ms 604 KB Output is correct
8 Correct 16 ms 1512 KB Output is correct
9 Correct 32 ms 2396 KB Output is correct
10 Correct 43 ms 2384 KB Output is correct
11 Correct 31 ms 2588 KB Output is correct
12 Correct 30 ms 2620 KB Output is correct
13 Correct 47 ms 2832 KB Output is correct
14 Correct 50 ms 2792 KB Output is correct
15 Correct 28 ms 2900 KB Output is correct
16 Correct 28 ms 3164 KB Output is correct
17 Correct 47 ms 2872 KB Output is correct
18 Correct 48 ms 2900 KB Output is correct
19 Correct 34 ms 3012 KB Output is correct
20 Correct 28 ms 2908 KB Output is correct