#include<bits/stdc++.h>
using namespace std;
const int mxN = 6e7;
struct SegmentTree{
vector<int>sTree, L, R;
vector<bool>lazy;
int nxt = 1;
SegmentTree(){
sTree.resize(mxN);
L.resize(mxN);
R.resize(mxN);
lazy.resize(mxN);
}
void Propagate(int node, int l, int r){
if(!lazy[node])return;
sTree[node] = r - l + 1;
if(l != r){
if(!L[node])L[node] = ++nxt;
if(!R[node])R[node] = ++nxt;
lazy[L[node]] = 1;
lazy[R[node]] = 1;
}
lazy[node] = 0;
}
void Update(int node, int l, int r, int ql, int qr){
Propagate(node, l, r);
if(ql <= l && r <= qr){
lazy[node] = 1;
Propagate(node, l, r);
return;
}
if(ql > r || l > qr)return;
int mid = (l + r) >> 1;
if(!L[node])L[node] = ++nxt;
if(!R[node])R[node] = ++nxt;
Update(L[node], l, mid, ql, qr);
Update(R[node], mid + 1, r, ql, qr);
sTree[node] = sTree[L[node]] + sTree[R[node]];
}
int Query(int node, int l, int r, int ql, int qr){
Propagate(node, l, r);
if(ql <= l && r <= qr)return sTree[node];
if(ql > r || l > qr)return 0;
int mid = (l + r) >> 1;
int lc = 0, rc = 0;
if(L[node])lc = Query(L[node], l, mid, ql, qr);
if(R[node])rc = Query(R[node], mid + 1, r, ql, qr);
return lc + rc;
}
};
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int q, C = 0;
cin >> q;
SegmentTree tree;
while(q--){
int d, x, y;
cin >> d >> x >> y;
x += C;
y += C;
if(d == 1){
int sum = tree.Query(1, 1, 1e9, x, y);
cout << sum << "\n";
C = sum;
}
else{
tree.Update(1, 1, 1e9, x, y);
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
52 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |