#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fr first
#define sc second
#define vec vector
#define ret return
#define ins insert
#define mk make_pair
#define pb push_back
#define pii pair<int,int>
#define all(s) s.begin(), s.end()
#define allr(s) s.rbegin(), s.rend()
const int N = 1e6+12, INF = 1e9, mod = 1e9+7;
int lz[N*4], sum[N*4];
void push(int p, int len) {
if (lz[p] != -1) {
sum[p] = len * lz[p];
if (len > 1) {
lz[2 * p] = lz[2 * p + 1] = lz[p];
}
lz[p] = -1;
}
}
void update(int p, int l, int r, int x, int y) {
push(p, r - l + 1);
if (l > y || r < x) return;
if (l >= x && r <= y) {
lz[p] = 1;
push(p, r - l + 1);
return;
}
int m = (l + r) / 2;
update(2 * p, l, m, x, y);
update(2 * p + 1, m + 1, r, x, y);
sum[p] = sum[2 * p] + sum[2 * p + 1];
}
int get(int p, int l, int r, int x, int y) {
push(p, r - l + 1);
if (l > y || r < x) return 0;
if (l >= x && r <= y) {
return sum[p];
}
int m = (l + r) / 2;
return get(2 * p, l, m, x, y) + get(2 * p + 1, m + 1, r, x, y);
}
main(){
int n;
cin>>n;
memset(lz, -1, sizeof lz);
int c = 0;
for(int i=1; i<=n; i++){
int z, x, y;
cin>>z>>x>>y;
if(z == 2){
update(1, 1, N, x + c, y + c);
}
else{
int ans = get(1, 1, N, x + c, y + c);
cout<<ans<<"\n";
c = ans;
}
}
return 0;
}
Compilation message
apple.cpp:54:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
54 | main(){
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
15948 KB |
Output is correct |
2 |
Correct |
7 ms |
15900 KB |
Output is correct |
3 |
Correct |
7 ms |
15948 KB |
Output is correct |
4 |
Correct |
26 ms |
23188 KB |
Output is correct |
5 |
Correct |
31 ms |
24104 KB |
Output is correct |
6 |
Correct |
33 ms |
23348 KB |
Output is correct |
7 |
Correct |
32 ms |
24012 KB |
Output is correct |
8 |
Incorrect |
106 ms |
24232 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |