Submission #1129303

#TimeUsernameProblemLanguageResultExecution timeMemory
1129303zhasynMonkey and Apple-trees (IZhO12_apple)C++20
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
#define pb push_back
#define pf push_front
using namespace std;
#define F first
#define S second
typedef long long ll;
#define pii pair <int, int>
#define pll pair <ll, ll>
typedef long double ld;
const ll N = 1e6 + 100, M = 500 + 10, len = 315, inf = 1e18;
const ll mod = 998244353;
ll um(ll a, ll b){
	return (1LL * a * b) % mod;
}
ll subr(ll a, ll b){
	return ((1LL * a - b) % mod + mod) % mod;
}
ll bp(ll x, ll step){
	ll res = 1;
	while(step){
		if(step & 1) res = um(res, x);
		x = um(x, x);
		step /= 2;
	}
	return res;
}
ll inv(ll x){
	return bp(x, mod - 2);
}
struct ver{
	bool full;
	int p[2], ans;
} a[N];

int ct;
int create(){
	int x = ct++;
	a[x].full = false;
	a[x].p[0] = a[x].p[1] = -1;
	a[x].ans = 0;
	return x;
}
struct segtree {
	int sz;
	void init(int n){
		sz = 1;
		while(sz < n){
			sz *= 2;
		}
	}
	void prop(int x, int lx, int rx){
		if(a[x].full){
			int s1 = a[x].p[0], s2 = a[x].p[1];
			a[s1].full = a[s2].full = true;
			a[s1].ans = a[s2].ans = (rx - lx) / 2;
		}
	}
	void upd(int l, int r, int cur, int lx, int rx){
		if(lx >= r || l >= rx) return;
		if(l <= lx && rx <= r){
			a[cur].full = true;
			a[cur].ans = rx - lx;
			return;
		}
		int mid = (lx + rx) / 2;
		if(a[cur].p[0] == -1){
			a[cur].p[0] = create();
			a[cur].p[1] = create();
		}
		int s1 = a[cur].p[0], s2 = a[cur].p[1];
		prop(cur, lx, rx);
		upd(l, r, s1, lx, mid);
		upd(l, r, s2, mid, rx);
		a[cur].ans = a[s1].ans + a[s2].ans;
	}
	void upd(int l, int r){
		upd(l, r, 0, 0, sz);
	}
	int get(int l, int r, int x, int lx, int rx){
		if(l >= rx || lx >= r) return 0;
		if(l <= lx && rx <= r) return a[x].ans;
		if(a[x].p[0] == -1){
			a[x].p[0] = create();
			a[x].p[1] = create();
		}
		prop(x, lx, rx);
		int mid = (lx + rx) / 2;
		int s1 = get(l, r, a[x].p[0], lx, mid);
		int s2 = get(l, r, a[x].p[1], mid, rx);
		return s1 + s2;
	}
	int get(int l, int r){
		return get(l, r, 0, 0, sz);
	}
};
int main() {
	//ios_base::sync_with_stdio(false);
	//cin.tie(nullptr);
	//cout.tie(nullptr);
	ll n, C = 0;
	cin >> n;
	segtree obj;
	create();
	obj.init(1e10);
	for(ll i = 0, code, x, y; i < n; i++){
		cin >> code >> x >> y;
		x += C;
		y += C;
		if(code == 1){
			int k = obj.get(x, y + 1);
			cout << k << endl;
			C = k;
		}
		else obj.upd(x, y + 1);
	}

Compilation message (stderr)

apple.cpp: In function 'int main()':
apple.cpp:105:18: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+10' to '2147483647' [-Woverflow]
  105 |         obj.init(1e10);
      |                  ^~~~
apple.cpp:116:10: error: expected '}' at end of input
  116 |         }
      |          ^
apple.cpp:97:12: note: to match this '{'
   97 | int main() {
      |            ^