Submission #898699

#TimeUsernameProblemLanguageResultExecution timeMemory
898699penguin133Monkey and Apple-trees (IZhO12_apple)C++17
100 / 100
248 ms220812 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pi pair<int, int>
#define pii pair<int, pi>
#define fi first
#define se second
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

struct node{
	int s, e, m, val, lz;
	node *l, *r;
	node(int _s, int _e){
		s = _s, e = _e, m = (s + e) >> 1;
		val = lz = 0;
		l = r = nullptr;
	}
	
	void mc(){
		if(l != nullptr || s == e)return;
		l = new node(s, m);
		r = new node(m+1, e);
	}
	
	void prop(){
		if(lz){
			val = lz * (e - s + 1);
			if(s != e)mc(), l->lz = lz, r->lz = lz;
			lz = 0;
		}
	}
	
	void upd(int a, int b, int c){
		if(val == e - s + 1)return;
		prop();
		if(a == s && b == e)lz = c;
		else{
			mc();
			if(b <= m)l->upd(a, b, c);
			else if(a > m)r->upd(a, b, c);
			else l->upd(a, m, c), r->upd(m+1, b, c);
			l->prop(), r->prop();
			val = l->val + r->val;
		}
	}
	
	int qry(int a, int b){
		prop();
		if(l == nullptr)return val;
		if(a == s && b == e)return val;
		else if(b <= m)return l->qry(a, b);
		else if(a > m)return r->qry(a, b);
		else return l->qry(a, m) + r->qry(m+1, b);
	}
}*root = new node(0, 1e9 + 5);

void solve(){
	int q; cin >> q;
	int c = 0;
	while(q--){
		int d, x, y; cin >> d >> x >> y;
		if(d == 1){
			c = root->qry(x + c, y + c);
			cout << c << '\n';
		}
		else{
			root->upd(x+c, y+c, 1);
		}
	}
}

main(){
	ios::sync_with_stdio(0);cin.tie(0);
	int tc = 1;
	//cin >> tc;
	for(int tc1=1;tc1<=tc;tc1++){
		// cout << "Case #" << tc1 << ": ";
		solve();
	}
}

Compilation message (stderr)

apple.cpp:76:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   76 | main(){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...