Submission #426724

# Submission time Handle Problem Language Result Execution time Memory
426724 2021-06-14T09:26:20 Z jeqcho Monkey and Apple-trees (IZhO12_apple) C++17
0 / 100
583 ms 262148 KB
#include <bits/stdc++.h>
using namespace std;

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpi;

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

#define pb push_back
#define rsz resize
#define sz(x) int(x.size())
#define all(x) begin(x), end(x)
#define fi first
#define se second

template <class T>
struct node
{
	int lx,rx;
	T val=0;
	bool lazy=0;
	node<T>*lefchi=nullptr,*rigchi=nullptr;
	
	T comb(T a,T b){return a+b;}
	void extend()
	{
		if(!lefchi && rx-lx!=1)
		{
			int md=(lx+rx)/2;
			lefchi=new node<int>({lx,md});
			rigchi=new node<int>({md,rx});
		}
	}
	void push()
	{
		extend();
		if(!lazy)return;
		val=rx-lx;
		lazy=0;
		if(rx-lx==1)return;
		lefchi->lazy = 1;
		rigchi->lazy = 1;
	}
	
	T query(int lq,int rq)
	{
		push();
		if(lq>=rx || rq<=lx)return 0;
		if(lq<=lx && rq>=rx)return val;
		T lef = lefchi->query(lq,rq);
		T rig = rigchi->query(lq,rq);
		return comb(lef,rig);
	}
	void update(int lq,int rq,T v)
	{
		push();
		if(lq>=rx || rq<=lx)return;
		if(lq<=lx && rq>=rx)
		{
			lazy=v;
			push();
			return;
		}
		lefchi->update(lq,rq,v);
		rigchi->update(lq,rq,v);
		val = comb(lefchi->val,rigchi->val);
	}
};

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int m;
	cin>>m;
	int c=0;
	node<int>seg({0,(int)1e9+3});
	while(m--)
	{
		int d,x,y;
		cin>>d>>x>>y;
		if(d==1)
		{
			c=seg.query(c+x,c+y+1);
			cout<<c<<'\n';
		}
		else
		{
			seg.update(c+x,c+y+1,1);
		}
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 23 ms 8524 KB Output is correct
5 Correct 33 ms 10332 KB Output is correct
6 Correct 27 ms 9972 KB Output is correct
7 Correct 26 ms 10276 KB Output is correct
8 Correct 217 ms 76964 KB Output is correct
9 Correct 493 ms 130708 KB Output is correct
10 Correct 478 ms 146764 KB Output is correct
11 Correct 583 ms 159396 KB Output is correct
12 Correct 505 ms 164768 KB Output is correct
13 Correct 492 ms 204968 KB Output is correct
14 Correct 503 ms 207192 KB Output is correct
15 Runtime error 529 ms 262148 KB Execution killed with signal 9
16 Halted 0 ms 0 KB -