This documentation is automatically generated by online-judge-tools/verification-helper
View the Project on GitHub beet-aizu/library
#define PROBLEM "http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2842" #include<bits/stdc++.h> using namespace std; #define call_from_test #include "../../segtree/count/dynamic_offline.cpp" #undef call_from_test #ifdef SANITIZE #define IGNORE #endif signed main(){ cin.tie(0); ios::sync_with_stdio(0); int h,w,t,q; cin>>h>>w>>t>>q; RangeCount<int, int> beet(h),ushi(h); vector<int> ts(q),cs(q); vector<int> y1(q),x1(q),y2(q),x2(q); for(int i=0;i<q;i++){ cin>>ts[i]>>cs[i]>>y1[i]>>x1[i]; y1[i]--;x1[i]--; if(cs[i]==0||cs[i]==1){ beet.preupdate(y1[i],x1[i]); ushi.preupdate(y1[i],x1[i]); } if(cs[i]==2) cin>>y2[i]>>x2[i]; } beet.build(); ushi.build(); using P = pair<int, int>; queue<P> que; for(int i=0;i<q;i++){ while(!que.empty()&&que.front().first<=ts[i]){ int k=que.front().second;que.pop(); beet.update(y1[k],x1[k],-1); ushi.update(y1[k],x1[k],+1); } if(cs[i]==0){ beet.update(y1[i],x1[i],+1); que.emplace(ts[i]+t,i); } if(cs[i]==1){ if(ushi.query(y1[i],y1[i]+1,x1[i],x1[i]+1)==0) continue; ushi.update(y1[i],x1[i],-1); } if(cs[i]==2){ cout<<ushi.query(y1[i],y2[i],x1[i],x2[i])<<" "; cout<<beet.query(y1[i],y2[i],x1[i],x2[i])<<"\n"; } } cout<<flush; return 0; }
#line 1 "test/aoj/2842.test.cpp" #define PROBLEM "http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2842" #include<bits/stdc++.h> using namespace std; #define call_from_test #line 1 "segtree/count/dynamic_offline.cpp" #line 3 "segtree/count/dynamic_offline.cpp" using namespace std; #endif //BEGIN CUT HERE template<typename Key,typename T> struct RangeCount{ struct BIT{ vector<T> dat; BIT(int n){dat.assign(++n,0);} T sum(int k){ T res=0; for(;k;k-=k&-k) res+=dat[k]; return res; } void add(int k,T v){ for(++k;k<(int)dat.size();k+=k&-k) dat[k]+=v; } }; int n; vector< vector<Key> > val; vector<BIT> dat; RangeCount(int n):n(n){ val.assign(n<<1,vector<Key>()); dat.reserve(n<<1); } void preupdate(int a,Key x){ a+=n; while(a){ val[a].emplace_back(x); a>>=1; } } void build(){ for(int i=0;i<n*2;i++){ auto &vs=val[i]; sort(vs.begin(),vs.end()); vs.erase(unique(vs.begin(),vs.end()),vs.end()); dat.emplace_back(vs.size()); } } void update(int a,Key x,T z){ a+=n; while(a){ auto &vs=val[a]; int k=lower_bound(vs.begin(),vs.end(),x)-vs.begin(); dat[a].add(k,z); a>>=1; } } T calc(int k,Key x,Key y){ auto &vs=val[k]; int p=lower_bound(vs.begin(),vs.end(),x)-vs.begin(); int q=lower_bound(vs.begin(),vs.end(),y)-vs.begin(); return dat[k].sum(q)-dat[k].sum(p); } // [a, b) * [x, y) T query(int a,int b,Key x,Key y){ T res=0; for(int l=a+n,r=b+n;l<r;l>>=1,r>>=1){ if(l&1) res+=calc(l++,x,y); if(r&1) res+=calc(--r,x,y); } return res; } }; //END CUT HERE #ifndef call_from_test //INSERT ABOVE HERE //END CUT HERE signed main(){ return 0; } #endif #line 8 "test/aoj/2842.test.cpp" #undef call_from_test #ifdef SANITIZE #define IGNORE #endif signed main(){ cin.tie(0); ios::sync_with_stdio(0); int h,w,t,q; cin>>h>>w>>t>>q; RangeCount<int, int> beet(h),ushi(h); vector<int> ts(q),cs(q); vector<int> y1(q),x1(q),y2(q),x2(q); for(int i=0;i<q;i++){ cin>>ts[i]>>cs[i]>>y1[i]>>x1[i]; y1[i]--;x1[i]--; if(cs[i]==0||cs[i]==1){ beet.preupdate(y1[i],x1[i]); ushi.preupdate(y1[i],x1[i]); } if(cs[i]==2) cin>>y2[i]>>x2[i]; } beet.build(); ushi.build(); using P = pair<int, int>; queue<P> que; for(int i=0;i<q;i++){ while(!que.empty()&&que.front().first<=ts[i]){ int k=que.front().second;que.pop(); beet.update(y1[k],x1[k],-1); ushi.update(y1[k],x1[k],+1); } if(cs[i]==0){ beet.update(y1[i],x1[i],+1); que.emplace(ts[i]+t,i); } if(cs[i]==1){ if(ushi.query(y1[i],y1[i]+1,x1[i],x1[i]+1)==0) continue; ushi.update(y1[i],x1[i],-1); } if(cs[i]==2){ cout<<ushi.query(y1[i],y2[i],x1[i],x2[i])<<" "; cout<<beet.query(y1[i],y2[i],x1[i],x2[i])<<"\n"; } } cout<<flush; return 0; }