답안 #969367

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
969367 2024-04-25T03:51:46 Z tamir1 원숭이와 사과 나무 (IZhO12_apple) C++17
0 / 100
368 ms 262144 KB
#include<bits/stdc++.h>
#define ll int
using namespace std;
ll m,i,x,y,d,c,ans;
struct node{
	node *le,*ri;
	ll val,lazy,l,r;
	void fix(){          
		if(l==r){
			if(lazy==1) val=1;
			return;
		}
		ll mid=(l+r)/2;
		if(le==NULL){
			le=new node;
			le->le=NULL;
			le->ri=NULL;
			le->l=l;
			le->r=mid;
			le->lazy=0;
			le->val=0;
		}
		if(ri==NULL){
			ri=new node;
			ri->le=NULL;
			ri->ri=NULL;
			ri->l=mid+1;
			ri->r=r;
			ri->lazy=0;
			ri->val=0;
		}
		if(lazy==1){
			val=r-l+1;
			le->lazy=1;
			ri->lazy=1;
			lazy=0;
		}
	}
	ll query(ll x,ll y){
		fix();
		if(l>y || r<x) return 0;
		if(l>=x && r<=y) return val;
		return le->query(x,y)+ri->query(x,y);
	}
	void update(ll x,ll y){
		fix();
		if(l>y || r<x) return;
		if(l>=x && r<=y){
			val=r-l+1;
			if(l!=r){
				le->lazy=1;
				ri->lazy=1;
			}
			return;
		}
		le->update(x,y);
		ri->update(x,y);
		val=le->val+ri->val;
	}
};
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin >> m;
	node *s = new node;
	s->le=NULL;
	s->ri=NULL;
	s->val=0;
	s->lazy=0;
	s->l=1;
	s->r=1e9;
	for(i=1;i<=m;i++){
		cin >> d >> x >> y;
		if(d==1){
			ans=s->query(x+c,y+c);
			cout << ans << "\n";
			c=ans;
		}
		else{
			s->update(x+c,y+c);
		}
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 14 ms 8652 KB Output is correct
5 Correct 21 ms 10332 KB Output is correct
6 Correct 16 ms 10076 KB Output is correct
7 Correct 25 ms 10324 KB Output is correct
8 Correct 160 ms 77136 KB Output is correct
9 Correct 274 ms 130864 KB Output is correct
10 Correct 300 ms 146936 KB Output is correct
11 Correct 314 ms 159432 KB Output is correct
12 Correct 333 ms 164840 KB Output is correct
13 Correct 300 ms 205136 KB Output is correct
14 Correct 287 ms 207192 KB Output is correct
15 Runtime error 368 ms 262144 KB Execution killed with signal 9
16 Halted 0 ms 0 KB -