Submission #102202

#TimeUsernameProblemLanguageResultExecution timeMemory
102202PajarajaExamination (JOI19_examination)C++17
100 / 100
1035 ms28840 KiB
#include <bits/stdc++.h> #define MAXN 1000007 using namespace std; int n,q,bit[2*MAXN],qx[MAXN],qy[MAXN],qxy[MAXN],x[MAXN],y[MAXN],a[MAXN],b[MAXN],c[MAXN],d[MAXN],sol[MAXN],ans[MAXN]; bool t[MAXN]; pair<int,int> r[2*MAXN]; pair<pair<int,int>,int> l[2*MAXN]; void upd(int x) {while(x<2*MAXN) {bit[x]++; x+=(x&-x);} } int val(int x) { int s=0; while(x) { s+=bit[x]; x-=(x&-x); } return s; } map<int,int> m; void calc1() { for(int i=0;i<n;i++) r[i]=make_pair(a[i],1); for(int i=0;i<q;i++) r[n+i]=make_pair(b[i],-i); sort(r,r+n+q); int cnt=0; for(int i=0;i<n+q;i++) { if(r[i].second==1) cnt++; else sol[-r[i].second]=cnt; } } void calc2() { fill(bit,bit+2*MAXN,0); m.clear(); vector<int> zk; for(int i=0;i<n;i++) zk.push_back(b[i]); for(int i=0;i<q;i++) zk.push_back(d[i]); sort(zk.begin(),zk.end()); for(int i=0;i<zk.size();i++) m[zk[i]]=i+1; for(int i=0;i<n;i++) l[i]=make_pair(make_pair(a[i],m[b[i]]),-1); for(int i=0;i<q;i++) l[n+i]=make_pair(make_pair(c[i]-1,m[d[i]]-1),i); sort(l,l+n+q); for(int i=0;i<n+q;i++) { if(l[i].second==-1) upd(l[i].first.second); else sol[l[i].second]=val(l[i].first.second); } } int main() { scanf("%d%d",&n,&q); for(int i=0;i<n;i++) scanf("%d%d",&x[i],&y[i]); for(int i=0;i<q;i++) scanf("%d%d%d",&qx[i],&qy[i],&qxy[i]); for(int i=0;i<q;i++) t[i]=(qx[i]+qy[i]<qxy[i]); for(int i=0;i<n;i++) a[i]=x[i]; for(int i=0;i<q;i++) b[i]=qx[i]; calc1(); for(int i=0;i<q;i++) ans[i]+=sol[i]; for(int i=0;i<n;i++) a[i]=y[i]; for(int i=0;i<q;i++) b[i]=qy[i]; calc1(); for(int i=0;i<q;i++) ans[i]+=sol[i]; for(int i=0;i<n;i++) a[i]=x[i]+y[i]; for(int i=0;i<q;i++) b[i]=qxy[i]; calc1(); for(int i=0;i<q;i++) if(t[i]) ans[i]+=sol[i]; for(int i=0;i<n;i++) a[i]=x[i]; for(int i=0;i<n;i++) b[i]=y[i]; for(int i=0;i<q;i++) c[i]=qx[i]; for(int i=0;i<q;i++) d[i]=qy[i]; calc2(); for(int i=0;i<q;i++) if(!t[i]) ans[i]-=sol[i]; for(int i=0;i<n;i++) a[i]=x[i]; for(int i=0;i<n;i++) b[i]=x[i]+y[i]; for(int i=0;i<q;i++) c[i]=qx[i]; for(int i=0;i<q;i++) d[i]=qxy[i]; calc2(); for(int i=0;i<q;i++) if(t[i]) ans[i]-=sol[i]; for(int i=0;i<n;i++) a[i]=x[i]+y[i]; for(int i=0;i<n;i++) b[i]=y[i]; for(int i=0;i<q;i++) c[i]=qxy[i]; for(int i=0;i<q;i++) d[i]=qy[i]; calc2(); for(int i=0;i<q;i++) if(t[i]) ans[i]-=sol[i]; for(int i=0;i<q;i++) printf("%d\n",n-ans[i]); }

Compilation message (stderr)

examination.cpp: In function 'void calc2()':
examination.cpp:40:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<zk.size();i++) m[zk[i]]=i+1;
              ~^~~~~~~~~~
examination.cpp: In function 'int main()':
examination.cpp:52:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&n,&q);
  ~~~~~^~~~~~~~~~~~~~
examination.cpp:53:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=0;i<n;i++) scanf("%d%d",&x[i],&y[i]);
                       ~~~~~^~~~~~~~~~~~~~~~~~~~
examination.cpp:54:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=0;i<q;i++) scanf("%d%d%d",&qx[i],&qy[i],&qxy[i]);
                       ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...