답안 #673596

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
673596 2022-12-21T09:02:23 Z Baytoro 원숭이와 사과 나무 (IZhO12_apple) C++17
0 / 100
259 ms 192420 KB
#include <bits/stdc++.h>
using namespace std;
#define ios ios::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fr first
#define sc second
#define int long long
#define endl '\n'
void fopn(string name){
	freopen((name+".in").c_str(),"r",stdin);
	freopen((name+".out").c_str(),"w",stdout);
}
const int INF=1e18,mod=998244353;
int n,m,k;
const int N=5e5+5;
struct node{
	int sum,lazy,lx,rx,l,r;
	node(): sum(0),lazy(0),l(-1),r(-1) {}
} st[4*N];
int cnt=2;
void push(int x){
	int md=(st[x].rx+st[x].lx)/2;
	if(st[x].l==-1){
		st[x].l=cnt++;
		st[cnt-1].lx=st[x].lx;
		st[cnt-1].rx=md;
	}
	if(st[x].r==-1){
		st[x].r=cnt++;
		st[cnt-1].lx=md+1;
		st[cnt-1].rx=st[x].rx;
	}
	if(st[x].lazy){
		st[x].sum=st[x].rx-st[x].lx+1;
		st[st[x].l].lazy=st[st[x].r].lazy=1;
		st[x].lazy=0;
	}
}
void update(int x, int l, int r){
	push(x);
	if(l==st[x].lx && r==st[x].rx){
		st[x].lazy=1;
		push(x);
		return;
	}
	int md=(st[x].lx+st[x].rx)/2;
	if(l>md)
		update(st[x].r,l,r);
	else if(r<=md)
		update(st[x].l,l,r);
	else{
		update(st[x].l,l,md);
		update(st[x].r,md+1,r);
	}
	push(st[x].l);
	push(st[x].r);
	st[x].sum=st[st[x].l].sum+st[st[x].r].sum;
}
int query(int x, int l, int r){
	push(x);
	if(l==st[x].lx && r==st[x].rx)
		return st[x].sum;
	int md=(st[x].lx+st[x].rx)/2;
	if(l>md)
		return query(st[x].r,l,r);
	else if(r<=md)
		return query(st[x].l,l,r);
	else
		return query(st[x].l,l,md)+query(st[x].r,md+1,r);
}
void solve(){
	int m;
	cin>>m;
	int c=0;
	st[1].sum=0,st[1].lazy=0;
	st[1].lx=1,st[1].rx=1e9;
	for(int i=0;i<m;i++){
		int d, x, y;
		cin>>d>>x>>y;
		if(d==1){
			c=query(1,x+c,y+c);
			cout<<c<<endl;
		}
		else{
			update(1,x+c,y+c);
		}
	}
}
main(){
	//fopn("newbarn");
	ios;
	int T=1;
	//cin>>T;
	while(T--){
		solve();
	}
}

Compilation message

apple.cpp:91:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   91 | main(){
      | ^~~~
apple.cpp: In function 'void fopn(std::string)':
apple.cpp:12:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |  freopen((name+".in").c_str(),"r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
apple.cpp:13:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |  freopen((name+".out").c_str(),"w",stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 94156 KB Output is correct
2 Correct 37 ms 94240 KB Output is correct
3 Correct 36 ms 94156 KB Output is correct
4 Correct 48 ms 94296 KB Output is correct
5 Correct 51 ms 94312 KB Output is correct
6 Correct 54 ms 94420 KB Output is correct
7 Correct 51 ms 94372 KB Output is correct
8 Correct 155 ms 94852 KB Output is correct
9 Runtime error 259 ms 192420 KB Execution killed with signal 11
10 Halted 0 ms 0 KB -