Submission #673603

# Submission time Handle Problem Language Result Execution time Memory
673603 2022-12-21T09:48:23 Z Baytoro Monkey and Apple-trees (IZhO12_apple) C++17
0 / 100
95 ms 262144 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=123456;
struct node{
	int sum,lazy,lx,rx,l,r;
	node(): sum(0),lazy(0),l(-1),r(-1) {}
} st[64*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[st[x].l].lx=st[x].lx;
		st[st[x].l].rx=md;
	}
	if(st[x].r==-1){
		st[x].r=cnt++;
		st[st[x].r].lx=md+1;
		st[st[x].r].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=1e10;
	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();
	}
}
/*
3
2 1 1000000000
1 1 1000000000
1 1 1000000000
*/

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);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 95 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -