#include <bits/stdc++.h>
#define st first
#define nd second
using lint = int64_t;
constexpr int mod = int(1e9) + 7;
constexpr int inf = 0x3f3f3f3f;
constexpr int ninf = 0xcfcfcfcf;
constexpr lint linf = 0x3f3f3f3f3f3f3f3f;
const long double pi = acosl(-1.0);
// Returns -1 if a < b, 0 if a = b and 1 if a > b.
int cmp_double(double a, double b = 0, double eps = 1e-9) {
return a + eps > b ? b + eps > a ? 0 : 1 : -1;
}
using namespace std;
struct node{
int sum, lz, l, r;
node(): sum(0), lz(0), l(0), r(0) {}
};
vector<node>seg;
int create(){
seg.push_back(node());
return seg.size() - 1;
}
void push(int v, int l, int r){
if(seg[v].lz){
seg[v].sum = (r - l + 1) * seg[v].lz;
if(!seg[v].l) seg[v].l = create();
if(!seg[v].r) seg[v].r = create();
seg[seg[v].l].lz = seg[seg[v].r].lz = 1;
seg[v].lz = 0;
}
}
void update(int v, int l, int r, int a, int b, int val){
if(b < l || r < a) return;
push(v, l, r);
if(a <= l && r <= b){
seg[v].lz = 1;
push(v, l, r);
return;
}
int m = (l + r) >> 1;
if(!seg[v].l) seg[v].l = create();
if(!seg[v].r) seg[v].r = create();
update(seg[v].l, l, m, a, b, val);
update(seg[v].r, m+1, r, a, b, val);
push(v, l, r);
seg[v].sum = seg[seg[v].l].sum + seg[seg[v].r].sum;
}
int query(int v, int l, int r, int a, int b){
if(b < l || r < a) return 0;
if(v == 0) return 0;
push(v, l, r);
if(a <= l && r <= b){
return seg[v].sum;
}
int m = (l + r) >> 1;
return query(seg[v].l, l, m, a, b) + query(seg[v].r, m+1, r, a, b);
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
create();
create();
int q;
cin>>q;
int c = 0;
for(int i=0;i<q;i++){
int op, x, y;
cin>>op>>x>>y;
if(op == 2) update(1, 1, int(1e9 + 7), x + c, y + c, 1);
else{
int cnt = query(1, 1, int(1e9 + 7), x + c, y + c);
cout<<cnt<<"\n";
c = cnt;
}
}
return 0;
}
/*
[ ]Leu o problema certo???
[ ]Ver se precisa de long long
[ ]Viu o limite dos fors (é n? é m?)
[ ]Tamanho do vetor, será que é 2e5 em vez de 1e5??
[ ]Testar sample
[ ]Testar casos de borda
[ ]1LL no 1LL << i
[ ]Testar mod (é 1e9+7, mesmo?, será que o mod não ficou negativo?)
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Incorrect |
1 ms |
320 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |