# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1129304 | zhasyn | Monkey and Apple-trees (IZhO12_apple) | C++20 | 0 ms | 0 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;
ll p[2], ans;
} a[N];
ll ct;
ll create(){
ll x = ct++;
a[x].full = false;
a[x].p[0] = a[x].p[1] = -1;
a[x].ans = 0;
return x;
}
struct segtree {
ll sz;
void init(ll n){
sz = 1;
while(sz < n){
sz *= 2;
}
}
void prop(ll x, ll lx, ll rx){
if(a[x].full){
ll 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(ll l, ll r, ll cur, ll lx, ll rx){
if(lx >= r || l >= rx) return;
if(l <= lx && rx <= r){
a[cur].full = true;
a[cur].ans = rx - lx;
return;
}
ll mid = (lx + rx) / 2;
if(a[cur].p[0] == -1){
a[cur].p[0] = create();
a[cur].p[1] = create();
}
ll 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(ll l, ll r){
upd(l, r, 0, 0, sz);
}
ll get(ll l, ll r, ll x, ll lx, ll 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);
ll mid = (lx + rx) / 2;
ll s1 = get(l, r, a[x].p[0], lx, mid);
ll s2 = get(l, r, a[x].p[1], mid, rx);
return s1 + s2;
}
ll get(ll l, ll 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(1e1);
for(ll i = 0, code, x, y; i < n; i++){
cin >> code >> x >> y;
x += C;
y += C;
if(code == 1){
ll k = obj.get(x, y + 1);
cout << k << endl;
C is = k;
}
else obj.upd(x, y + 1);
}
return 0;
}