Submission #938971

# Submission time Handle Problem Language Result Execution time Memory
938971 2024-03-06T02:14:00 Z vjudge1 Monkey and Apple-trees (IZhO12_apple) C++17
0 / 100
255 ms 262144 KB
#include<bits/stdc++.h>
using namespace std;

struct node{
	int sum, l, r, lazy, ll, lr;
	node(): sum(0), lazy(0), l(-1), r(-1){}
};

node tr[1000000];
int temp=1;

void create(int now){
		int mid=(tr[now].ll+tr[now].lr)>>1;
		if (tr[now].l==-1){
			tr[now].l=temp;
			tr[temp].ll=tr[now].ll;
			tr[temp].lr=mid;
			temp++;
		}
		if (tr[now].r==-1){
			tr[now].r=temp;
			tr[temp].ll=mid+1;
			tr[temp].lr=tr[now].lr;
			temp++;
		}
}

void push(int now){
	create(now);
	if (tr[now].lazy){
		tr[now].sum=tr[now].lr-tr[now].ll+1;
		tr[tr[now].l].lazy=1;
		tr[tr[now].r].lazy=1;
		tr[now].lazy=0;
	}
}

void update(int now, int ql, int qr){
	int l=tr[now].ll, r=tr[now].lr;
	push(now);
	if (ql<=l and r<=qr){
		tr[now].lazy=1;
		push(now);
	} else{
		int mid=(tr[now].ll+tr[now].lr)>>1;
		int cl=tr[now].l, cr=tr[now].r;

		if (ql<=mid) update(cl, ql, qr);
		if (qr>mid) update(cr, ql, qr);

		push(cl);
		push(cr);
		tr[now].sum=tr[cl].sum+tr[cr].sum;
	}
}

int get(int now, int ql, int qr){
	int l=tr[now].ll, r=tr[now].lr;
	push(now);
	if (ql<=l and r<=qr){
		return tr[now].sum;
	} else{
		int mid=(tr[now].ll+tr[now].lr)>>1;
		int cl=tr[now].l, cr=tr[now].r;

		push(cl);
		push(cr);
		int a=0, b=0;
		if (ql<=mid) a=get(cl, ql, qr);
		if (qr>mid) b=get(cr, ql, qr);

		return a+b;
	}
}

int main(){
	int m;
	cin>>m;

	tr[0].sum=0;
	tr[0].ll=1;
	tr[0].lr=1e9;

	int c=0;

	while(m--){
		int d, x, y;
		cin>>d>>x>>y;
		if (d==1){
			c=get(0, x+c, y+c);
			cout<<c<<endl;
		} else{
			update(0, x+c, y+c);
		}
	}
	return 0;
}

Compilation message

apple.cpp: In constructor 'node::node()':
apple.cpp:5:17: warning: 'node::lazy' will be initialized after [-Wreorder]
    5 |  int sum, l, r, lazy, ll, lr;
      |                 ^~~~
apple.cpp:5:11: warning:   'int node::l' [-Wreorder]
    5 |  int sum, l, r, lazy, ll, lr;
      |           ^
apple.cpp:6:2: warning:   when initialized here [-Wreorder]
    6 |  node(): sum(0), lazy(0), l(-1), r(-1){}
      |  ^~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 24056 KB Output is correct
2 Correct 4 ms 23932 KB Output is correct
3 Correct 5 ms 23900 KB Output is correct
4 Correct 21 ms 23896 KB Output is correct
5 Correct 26 ms 23900 KB Output is correct
6 Correct 26 ms 24196 KB Output is correct
7 Correct 33 ms 23900 KB Output is correct
8 Runtime error 255 ms 262144 KB Execution killed with signal 9
9 Halted 0 ms 0 KB -