Submission #254066

#TimeUsernameProblemLanguageResultExecution timeMemory
254066test2Monkey and Apple-trees (IZhO12_apple)C++14
0 / 100
30 ms1024 KiB
#include <bits/stdc++.h> using namespace std; const int N = (1 << 21); int t, a, b, c; int rip[N]; int occ[N]; int bit[N]; int tree[N * 4]; int lazy[N * 4]; void update(int node, int L, int R, int l, int r) { if (l > r || l > R || r < L || lazy[node]) return; if (L >= l && R <= r) { lazy[node] = R - L + 1; tree[node] = R - L + 1; return; } int mid = (L + R) >> 1; update(node * 2 + 1, L, mid, l, r); update(node * 2 + 2, mid + 1, R, l, r); tree[node] = tree[node * 2 + 1]+ tree[node * 2 + 2]; } int query(int node, int L, int R, int l, int r) { if (l > r || l > R || r < L) return 0; if (L >= l && R <= r) { if (lazy[node]) return lazy[node]; else return tree[node]; return tree[node] + lazy[node]; } int mid = (L + R) >> 1; int s1 = query(node * 2 + 1, L, mid, l, r); int s2 = query(node * 2 + 2, mid + 1, R, l, r); if (lazy[node]) { return min(r, R) - max(l, L) + 1; } return s1 + s2; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); //freopen("in.in", "r", stdin); cin >> t; int C = 0; while (t--) { int a, b, c; cin >> a >> b >> c; b += C; c += C; if (a == 1) { int ans = query(0, 1, N, b, c); C = ans; cout << ans << "\n"; } else { update(0, 1, N, b, c); } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...