#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, x, y;
ll l,r;
Node(ll v, ll x, ll y) : val(v), x(x), y(y) { l = r = -1; }
};
struct STree{
ll n;
ll indice;
vector<ll> st;
vector<ll> lazy;
STree(ll n) : n(n) , st(4*n+5,0), lazy(4*n+5,0) { indice=2; }
void push_lazy(ll k, ll l, ll r){
if(!lazy[k]) return;
//cout<<k<<" ("<<l<<" "<<r<<") "<<'\n';
ll mid = (l+r)/2;
st[k]=lazy[k]*(r-l);
if(l+1!=r){
lazy[2*k]=lazy[k];
lazy[2*k+1]=lazy[k];
}
lazy[k]=0;
}
void upd(ll k, ll l, ll r, ll L, ll R, ll v){
//cout<<k<<'\n';
push_lazy(k,l,r);
if(l>=R||r<=L) return;
if(l>=L&&r<=R){
//cout<<k<<" ("<<l<<" "<<r<<") "<<" ("<<L<<" "<<R<<") "<<'\n';
lazy[k]=v;
push_lazy(k,l,r);
return;
}
ll mid = (l+r)/2;
st[k]=0;
//if(st[k].l!=-1){
upd(2*k,l,mid,L,R,v);
st[k]+=st[2*k];
//}
//if(st[k].r!=-1){
upd(2*k+1,mid,r,L,R,v);
st[k]+=st[2*k+1];
//}
}
ll query(ll k, ll l, ll r, ll L, ll R){
//cout<<k<<" ("<<l<<" "<<r<<")"<<'\n';
if(l>=R||r<=L) return 0;
push_lazy(k,l,r);
//cout<<k<<" ("<<l<<" "<<r<<") "<<" ("<<L<<" "<<R<<") "<<'\n';
if(l>=L&&r<=R){ return st[k];}
ll mid = (l+r)/2;
ll res = 0;
//if(st[k].l!=-1){
res+=query(2*k,l,mid,L,R);
//}
//if(st[k].r!=-1){
res+=query(2*k+1,mid,r,L,R);
//}
return res;
}
void upd(ll l, ll r, ll v){ upd(1,0,n,l,r,v); }
ll query(ll l, ll r){ return query(1,0,n,l,r); }
};
int main(){FIN;
ll m; cin>>m;
ll t,c,pC; c=0;
ll l,r;
STree stree(1000000+5);
while(m--){
cin>>t>>l>>r;
if(c+r+1>=1000000) return 0;
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 member function 'void STree::push_lazy(ll, ll, ll)':
apple.cpp:38:6: warning: unused variable 'mid' [-Wunused-variable]
38 | ll mid = (l+r)/2;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
63064 KB |
Output is correct |
2 |
Correct |
9 ms |
63068 KB |
Output is correct |
3 |
Correct |
9 ms |
63068 KB |
Output is correct |
4 |
Correct |
14 ms |
63068 KB |
Output is correct |
5 |
Incorrect |
8 ms |
63068 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |