# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
997276 | JuanJL | Monkey and Apple-trees (IZhO12_apple) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 = 1;
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
if(s+1<e){ // propagate to children
if(st[k].l==-1) st[k].l=indice,indice++;
if(st[k].r==-1) st[k].r=indice,indice++;
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){
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++;
if(st[k].r==-1) st[k].r=indice,indice++;
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);
if(s>=a&&e<=b)return st[k].val;
int m=(s+e)/2;
if(st[k].l==-1) st[k].l=indice,indice++;
if(st[k].r==-1) st[k].r=indice,indice++;
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(100000+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;
}