제출 #1254270

#제출 시각아이디문제언어결과실행 시간메모리
1254270ssitaramMonkey and Apple-trees (IZhO12_apple)C++20
100 / 100
271 ms133892 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; struct node { node *l, *r; ll cnt; node() : l(nullptr), r(nullptr), cnt(0) {} }; void getch(node& here, ll l, ll r) { if (here.l == nullptr) { here.l = new node(); here.r = new node(); } if (here.cnt == r - l) { here.l->cnt = here.cnt / 2; here.r->cnt = here.cnt / 2; } } void upd(node& here, ll l, ll r, ll a, ll b) { if (l >= b || r <= a) return; if (a <= l && r <= b) { here.cnt = r - l; return; } ll m = (l + r) / 2; getch(here, l, r); upd(*here.l, l, m, a, b); upd(*here.r, m, r, a, b); here.cnt = here.l->cnt + here.r->cnt; } ll cnt(node& here, ll l, ll r, ll a, ll b) { if (l >= b || r <= a) return 0; if (a <= l && r <= b) return here.cnt; ll m = (l + r) / 2; getch(here, l, r); return cnt(*here.l, l, m, a, b) + cnt(*here.r, m, r, a, b); } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); ll p2 = 1; while (p2 < 1e9) p2 *= 2; node root; ll c = 0; ll m; cin >> m; while (m--) { ll d, x, y; cin >> d >> x >> y; --x; --y; x += c; y += c; if (d == 1) { c = cnt(root, 0, p2, x, y + 1); cout << c << '\n'; } else { upd(root, 0, p2, x, y + 1); } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...