#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, 1, n, l, r);
}
else {
cout<<ol(1, 1, n, l, r)<<"\n";
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |