Submission #89366

#TimeUsernameProblemLanguageResultExecution timeMemory
89366BadralMonkey and Apple-trees (IZhO12_apple)C++17
0 / 100
2 ms376 KiB
#include<bits/stdc++.h> using namespace std; map<int, int> lazy; map<int, int> tree; void nemeh(int node, int L, int R, int l, int r) { if(lazy[node]) { tree[node] += (R-L+1)*lazy[node]; if(L != R) { lazy[node<<1|1]++; lazy[node<<1]++; } lazy[node] = 0; } if(l > R || r < L || L > R) { return; } if(L >= l && r >= R) { tree[node] += (R-L+1); if (L != R) { lazy[node*2 + 1]++; lazy[node*2 + 2]++; } return; } int mid = (L+R)>>1; nemeh(node<<1, L, mid, l, r); nemeh(node<<1|1, mid+1, R, l, r); tree[node] = tree[node<<1] + tree[node<<1|1]; } int ol(int node, int L, int R, int l, int r) { if(lazy[node]) { tree[node] += (R-L+1)*lazy[node]; if(L != R) { lazy[node<<1|1]++; lazy[node<<1]++; } lazy[node] = 0; } if(l > R || r < L || L > R) { return 0; } if(L <= l && R >= r) { return tree[node]; } int mid = (L+R)>>1; return ol(node<<1, L, mid, l, r) + ol(node<<1|1, mid+1, R, l, r); } int main() { int n = 10000000; int t; cin >>t; while(t--) { int x, l, r; cin >>x >>l >>r; if(x == 2) { nemeh(1, -n, n, l, r); } else { cout<<ol(1, -n, n, l, r)<<"\n"; } } }
#Verdict Execution timeMemoryGrader output
Fetching results...