Submission #1083178

#TimeUsernameProblemLanguageResultExecution timeMemory
1083178StefanSebezExamination (JOI19_examination)C++14
0 / 100
372 ms24772 KiB
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back #define ll long long #define ld long double const int N=1e5+50; struct Query{ int x,y,z,i; bool operator <(Query a){return z<a.z;} }Qs[N+50]; vector<int>T[N+50],vals[N+50]; pair<int,int>a[N+50]; int res[N+50]; void update(int qind,int qind1,int qval){ int lb=lower_bound(vals[qind].begin(),vals[qind].end(),qind1)-vals[qind].begin(); if(lb==0) return; for(int i=lb;i<T[qind].size();i+=i&-i) T[qind][i]+=qval; } void Update(int qind,int qind1,int qval,bool precalc){ if(qind==0) return; if(precalc) for(int i=qind;i<=N;i+=i&-i) vals[i].pb(qind1); else for(int i=qind;i<=N;i+=i&-i) update(i,qind1,qval); } int get(int qind,int qval){ int sum=0; for(int i=T[qind].size()-1;i>=1;i-=i&-i) sum+=T[qind][i]; int lb=lower_bound(vals[qind].begin(),vals[qind].end(),qval)-vals[qind].begin()-1; for(int i=lb;i>=1;i-=i&-i) sum-=T[qind][i]; return sum; } int Get(int qind,int qval){ int sum=0; for(int i=qind;i>=1;i-=i&-i) sum+=get(i,qval); return sum; } vector<int>Vals; int Ind(int x){ return upper_bound(Vals.begin(),Vals.end(),x)-Vals.begin()-1; } int main(){ int n,q;scanf("%i%i",&n,&q); for(int i=1;i<=n;i++) scanf("%i%i",&a[i].fi,&a[i].se); Vals.pb(-1); for(int i=1;i<=n;i++) Vals.pb(a[i].fi); sort(Vals.begin(),Vals.end()); Vals.resize(unique(Vals.begin(),Vals.end())-Vals.begin()); for(int i=1;i<=n;i++) Update(Ind(a[i].fi),a[i].se,1,true); for(int i=0;i<=N;i++){ vals[i].pb(0); sort(vals[i].begin(),vals[i].end()); int m=unique(vals[i].begin(),vals[i].end())-vals[i].begin(); vals[i].resize(m); for(int j=0;j<m;j++) T[i].pb(0); } for(int i=1;i<=n;i++) Update(Ind(a[i].fi),a[i].se,1,false); sort(a+1,a+n+1,[&](pair<int,int> i,pair<int,int> j){return i.fi+i.se<j.fi+j.se;}); for(int i=1;i<=q;i++){ int x,y,z;scanf("%i%i%i",&x,&y,&z); Qs[i]={x,y,z,i}; } sort(Qs+1,Qs+q+1); //for(int i=1;i<=n;i++) printf("%i %i\n",a[i].fi,a[i].se); //for(int i=1;i<=q;i++) printf("%i %i %i\n",Qs[i].x,Qs[i].y,Qs[i].z); for(int i=1,j=1;j<=q;j++){ while(i<=n && a[i].fi+a[i].se<Qs[j].z){ Update(Ind(a[i].fi),a[i].se,-1,false); i++; } res[Qs[j].i]=Get(N,Qs[j].y)-Get(Ind(Qs[j].x-1),Qs[j].y); //printf("*%i %i %i %i %i %i\n",Ind(Qs[j].x-1),Qs[j].x,Qs[j].y,Qs[j].z,Get(N,Qs[j].y),Get(Ind(Qs[j].x-1),Qs[j].y)); } for(int i=1;i<=q;i++) printf("%i ",res[i]); return 0; }

Compilation message (stderr)

examination.cpp: In function 'void update(int, int, int)':
examination.cpp:19:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |     for(int i=lb;i<T[qind].size();i+=i&-i) T[qind][i]+=qval;
      |                  ~^~~~~~~~~~~~~~~
examination.cpp: In function 'int main()':
examination.cpp:43:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |     int n,q;scanf("%i%i",&n,&q);
      |             ~~~~~^~~~~~~~~~~~~~
examination.cpp:44:32: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |     for(int i=1;i<=n;i++) scanf("%i%i",&a[i].fi,&a[i].se);
      |                           ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
examination.cpp:60:24: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |         int x,y,z;scanf("%i%i%i",&x,&y,&z);
      |                   ~~~~~^~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...