#include<bits/stdc++.h>
#define int long long
#define ld long double
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define fi first
#define se second
#define TII tuple<int, int, int>
#define ts to_string
#pragma gcc optimize("O3");
using namespace std;
const int INF=1e18;
struct node{
int l, r, sum=0, lazy=0;
node *left=nullptr, *right=nullptr;
node(int l, int r) : l(l), r(r) {}
void extend() {
if(l==r) return;
int mid=l+r>>1;
if(!left) left=new node(l, mid);
if(!right) right=new node(mid+1, r);
}
void push() {
if(l==r) return;
extend();
if(lazy) {
left->lazy=1;
left->sum=left->r-left->l+1;
right->lazy=1;
right->sum=right->r-right->l+1;
lazy=0;
}
}
void update(int ql, int qr) {
if(max(l, ql)>min(r, qr)) return;
if(ql<=l && r<=qr) {lazy=1; sum=r-l+1; return;}
push();
left->update(ql, qr);
right->update(ql, qr);
sum=left->sum+right->sum;
}
int get(int ql, int qr) {
if(max(l, ql)>min(r, qr)) return 0;
if(ql<=l && r<=qr) return sum;
push();
return left->get(ql, qr)+right->get(ql, qr);
}
};
signed main() {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int m, c=0; cin >> m;
node *root = new node(-INF, INF);
while(m--) {
int type, ql, qr;
cin >> type >> ql >> qr;
if(type==1) c=root->get(ql+c, qr+c), cout << c << '\n';
else root->update(ql+c, qr+c);
}
return 0;
}
Compilation message
apple.cpp:12: warning: ignoring '#pragma gcc optimize' [-Wunknown-pragmas]
12 | #pragma gcc optimize("O3");
|
apple.cpp: In member function 'void node::extend()':
apple.cpp:22:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
22 | int mid=l+r>>1;
| ~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
452 KB |
Output is correct |
4 |
Correct |
11 ms |
6652 KB |
Output is correct |
5 |
Correct |
14 ms |
8184 KB |
Output is correct |
6 |
Correct |
14 ms |
7612 KB |
Output is correct |
7 |
Correct |
14 ms |
8028 KB |
Output is correct |
8 |
Correct |
107 ms |
59088 KB |
Output is correct |
9 |
Correct |
228 ms |
102228 KB |
Output is correct |
10 |
Correct |
257 ms |
112896 KB |
Output is correct |
11 |
Correct |
232 ms |
121168 KB |
Output is correct |
12 |
Correct |
233 ms |
124844 KB |
Output is correct |
13 |
Correct |
216 ms |
145484 KB |
Output is correct |
14 |
Correct |
216 ms |
146548 KB |
Output is correct |
15 |
Runtime error |
326 ms |
262144 KB |
Execution killed with signal 9 |
16 |
Halted |
0 ms |
0 KB |
- |