Submission #673597

# Submission time Handle Problem Language Result Execution time Memory
673597 2022-12-21T09:03:14 Z Baytoro Monkey and Apple-trees (IZhO12_apple) C++17
0 / 100
103 ms 75716 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=12345;
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[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);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 15 ms 37332 KB Output is correct
2 Correct 22 ms 37332 KB Output is correct
3 Correct 15 ms 37352 KB Output is correct
4 Correct 26 ms 37356 KB Output is correct
5 Correct 31 ms 37460 KB Output is correct
6 Correct 29 ms 37432 KB Output is correct
7 Correct 32 ms 37460 KB Output is correct
8 Runtime error 103 ms 75716 KB Execution killed with signal 11
9 Halted 0 ms 0 KB -