#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fst first
#define snd second
#define pb push_back
#define forn(i,a,b) for(int i = a; i < b; i++)
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
#define mset(a,v) memset((a),(v),sizeof(a))
#define FIN ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define dbg(v) cout<<"Line("<<__LINE__<<"): "<<#v<<" = "<<v<<'\n';
#define pi pair<int,int>
#define pll pair<ll,ll>
typedef long long ll;
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_multiset;
struct Node{
ll val, l,r;
Node(){ val=0; l = r = -1; }
};
struct STree { // example: range sum with range addition
int indice = 2;
vector<Node> st;
vector<int> lazy;int n;
int M;
STree(int n, int m): M(m), st(4*n+5,Node()), lazy(4*n+5,0), n(n) {}
void push(int k, int s, int e){
if(!lazy[k])return; // if neutral, nothing to do
st[k].val=(e-s)*lazy[k]; // update st according to lazy
//cout<<"("<<st[k].val<<") "<<s<<" <-> "<<e<<" -- "<<k<<'\n';
if(s+1<e){ // propagate to children
if(st[k].l==-1){ st[k].l=indice; indice+=1; }
if(st[k].r==-1){ st[k].r=indice; indice+=1; }
lazy[st[k].l]=lazy[k];
lazy[st[k].r]=lazy[k];
}
lazy[k]=0; // clear node lazy
}
void upd(int k, int s, int e, int a, int b, int v){
push(k,s,e);
if(s>=b||e<=a)return;
if(s>=a&&e<=b){
//cout<<s<<" <-> "<<e<<'\n';
lazy[k]=v; // accumulate lazy
push(k,s,e);return;
}
int m=(s+e)/2;
if(st[k].l==-1){ st[k].l=indice; indice+=1; }
if(st[k].r==-1){ st[k].r=indice; indice+=1;}
upd(st[k].l,s,m,a,b,v);upd(st[k].r,m,e,a,b,v);
st[k].val=st[st[k].l].val+st[st[k].r].val; // operation
}
int query(int k, int s, int e, int a, int b){
if(s>=b||e<=a)return 0; // operation neutral
push(k,s,e);
//cout<<k<<" -> "<<s<<" <-> "<<e<<'\n';
if(s>=a&&e<=b)return st[k].val;
int m=(s+e)/2;
if(st[k].l==-1){ st[k].l=indice; indice+=1; }
if(st[k].r==-1){ st[k].r=indice; indice+=1; }
return query(st[k].l,s,m,a,b)+query(st[k].r,m,e,a,b); // operation
}
void upd(int a, int b, int v){upd(1,0,M,a,b,v);}
int query(int a, int b){return query(1,0,M,a,b);}
};
int main(){FIN;
ll m; cin>>m;
ll t,c,pC; c=0;
ll l,r;
STree stree(1000000+5,1000000000+5);
while(m--){
cin>>t>>l>>r;
/*if(c+r+1>=1000000+2){
while(true){}
}*/
if(t==2){
stree.upd(c+l,c+r+1,1);
}else{
//cout<<"QUERY\n";
pC=stree.query(l+c,r+c+1);
cout<<pC<<'\n';
c=pC;
}
}
return 0;
}
Compilation message
apple.cpp: In constructor 'STree::STree(int, int)':
apple.cpp:31:6: warning: 'STree::M' will be initialized after [-Wreorder]
31 | int M;
| ^
apple.cpp:29:15: warning: 'std::vector<Node> STree::st' [-Wreorder]
29 | vector<Node> st;
| ^~
apple.cpp:32:2: warning: when initialized here [-Wreorder]
32 | STree(int n, int m): M(m), st(4*n+5,Node()), lazy(4*n+5,0), n(n) {}
| ^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
109916 KB |
Output is correct |
2 |
Correct |
14 ms |
110040 KB |
Output is correct |
3 |
Correct |
13 ms |
110020 KB |
Output is correct |
4 |
Correct |
20 ms |
109936 KB |
Output is correct |
5 |
Correct |
24 ms |
109912 KB |
Output is correct |
6 |
Correct |
23 ms |
109916 KB |
Output is correct |
7 |
Correct |
22 ms |
109912 KB |
Output is correct |
8 |
Correct |
70 ms |
110164 KB |
Output is correct |
9 |
Correct |
147 ms |
111952 KB |
Output is correct |
10 |
Correct |
151 ms |
112144 KB |
Output is correct |
11 |
Correct |
159 ms |
112212 KB |
Output is correct |
12 |
Correct |
149 ms |
112096 KB |
Output is correct |
13 |
Correct |
133 ms |
112468 KB |
Output is correct |
14 |
Correct |
136 ms |
112464 KB |
Output is correct |
15 |
Runtime error |
167 ms |
224080 KB |
Execution killed with signal 11 |
16 |
Halted |
0 ms |
0 KB |
- |