#include<bits/stdc++.h>
using namespace std;
int C, M;
const int MAXN = 1e9;
struct Node{
int set, val, l, r;
Node(int val, int set):val(val),set(set),l(-1),r(-1){};
Node():val(0),set(0),l(-1),r(-1){};
};
struct Seg{
vector<Node> V;
Seg(){
V.emplace_back(0, 0);
}
void push_down(int s, int e, int v){
int m = (s+e)>>1;
if(V[v].l == -1){
V[v].l = V.size();
V.emplace_back();
}
if(V[v].r == -1){
V[v].r = V.size();
V.emplace_back();
}
if(V[v].set){
V[V[v].l].val = V[v].set * (m-s+1);
V[V[v].r].val = V[v].set * (e-m);
V[V[v].l].set = V[V[v].r].set = V[v].set;
V[v].set = 0;
}
}
void update(int s, int e, int l, int r, int v, int val){
if(e<l || r<s){
return;
}
if(l<=s && e<=r){
V[v].val = val * (e-s+1);
V[v].set = val;
return;
}
int m = (s+e)>>1;
push_down(s, e, v);
update(s, m, l, r, V[v].l, val);
update(m+1, e, l, r, V[v].r, val);
V[v].val = V[V[v].l].val + V[V[v].r].val;
}
int sum(int s, int e, int l, int r, int v){
if(e<l || r<s){
return 0;
}
if(l<=s && e<=r){
return V[v].val;
}
push_down(s, e, v);
int m = (s+e)>>1;
return sum(s, m, l, r, V[v].l) + sum(m+1, e, l, r, V[v].r);
}
}S;
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
cin>>M;
for(int i=0,t,x,y ; i<M ; i++){
cin>>t;
if(t==1){
cin>>x>>y;
C = S.sum(1, MAXN, x+C, y+C, 0);
cout<<C<<"\n";
}
else if(t==2){
cin>>x>>y;
S.update(1, MAXN, x+C, y+C, 0, 1);
}
}
}
Compilation message
apple.cpp: In constructor 'Node::Node(int, int)':
apple.cpp:6:14: warning: 'Node::val' will be initialized after [-Wreorder]
6 | int set, val, l, r;
| ^~~
apple.cpp:6:9: warning: 'int Node::set' [-Wreorder]
6 | int set, val, l, r;
| ^~~
apple.cpp:7:5: warning: when initialized here [-Wreorder]
7 | Node(int val, int set):val(val),set(set),l(-1),r(-1){};
| ^~~~
apple.cpp: In constructor 'Node::Node()':
apple.cpp:6:14: warning: 'Node::val' will be initialized after [-Wreorder]
6 | int set, val, l, r;
| ^~~
apple.cpp:6:9: warning: 'int Node::set' [-Wreorder]
6 | int set, val, l, r;
| ^~~
apple.cpp:8:5: warning: when initialized here [-Wreorder]
8 | Node():val(0),set(0),l(-1),r(-1){};
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
12 ms |
2504 KB |
Output is correct |
5 |
Correct |
13 ms |
2504 KB |
Output is correct |
6 |
Correct |
17 ms |
2504 KB |
Output is correct |
7 |
Correct |
13 ms |
2476 KB |
Output is correct |
8 |
Correct |
99 ms |
16892 KB |
Output is correct |
9 |
Correct |
227 ms |
33444 KB |
Output is correct |
10 |
Correct |
200 ms |
33368 KB |
Output is correct |
11 |
Correct |
218 ms |
33392 KB |
Output is correct |
12 |
Correct |
226 ms |
33328 KB |
Output is correct |
13 |
Correct |
204 ms |
66512 KB |
Output is correct |
14 |
Correct |
216 ms |
66536 KB |
Output is correct |
15 |
Correct |
329 ms |
132132 KB |
Output is correct |
16 |
Correct |
380 ms |
132212 KB |
Output is correct |
17 |
Correct |
203 ms |
66424 KB |
Output is correct |
18 |
Correct |
208 ms |
66592 KB |
Output is correct |
19 |
Correct |
306 ms |
132316 KB |
Output is correct |
20 |
Correct |
302 ms |
132228 KB |
Output is correct |