Submission #997264

#TimeUsernameProblemLanguageResultExecution timeMemory
997264JuanJLMonkey and Apple-trees (IZhO12_apple)C++17
0 / 100
2071 ms31700 KiB
#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 STree { // example: range sum with range addition vector<int> st,lazy;int n; STree(int n): st(4*n+5,0), 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]=(e-s)*lazy[k]; // update st according to lazy if(s+1<e){ // propagate to children lazy[2*k]=lazy[k]; lazy[2*k+1]=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; upd(2*k,s,m,a,b,v);upd(2*k+1,m,e,a,b,v); st[k]=st[2*k]+st[2*k+1]; // 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]; int m=(s+e)/2; return query(2*k,s,m,a,b)+query(2*k+1,m,e,a,b); // operation } void upd(int a, int b, int v){upd(1,0,n,a,b,v);} int query(int a, int b){return query(1,0,n,a,b);} }; 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){ 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; }
#Verdict Execution timeMemoryGrader output
Fetching results...