#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;
vector<int>sum, d, e;
int create(){
sum.push_back(0);
e.push_back(0);
d.push_back(0);
return sum.size() - 1;
}
void update(int v, int l, int r, int a, int b, int val){
if(b < l || r < a) return;
int m = (l + r) >> 1;
if(a <= l && r <= b){
sum[v] = (r - l + 1) * val;
return;
}
if(m < a){
if(!e[v]) e[v] = create();
update(e[v], m+1, r, a, b, val);
}
else if(m >= b){
if(!d[v]) d[v] = create();
update(d[v], l, m, a, b, val);
}
else{
if(!d[v]) d[v] = create();
if(!e[v]) e[v] = create();
update(d[v], l, m, a, b, val);
update(e[v], m+1, r, a, b, val);
}
sum[v] = max(sum[v], sum[d[v]] + sum[e[v]]);
}
int query(int v, int l, int r, int a, int b){
if(b < l || r < a) return 0;
if(v == 0) return 0;
if(a <= l && r <= b) return sum[v];
int m = (l + r) >> 1;
return query(d[v], l, m, a, b) + query(e[v], 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?)
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |