Submission #154799

#TimeUsernameProblemLanguageResultExecution timeMemory
154799TadijaSebezMatryoshka (JOI16_matryoshka)C++11
100 / 100
998 ms77308 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back const int N=200050; const int M=N*60; const int lim=1e9; int a[N],b[N],x[N],y[N]; int uid[N],qid[N],ans[N]; int ls[M],rs[M],tsz,root[2],sum[M]; void Set(int &c, int ss, int se, int qi) { if(!c) c=++tsz; sum[c]++; if(ss==se) return; int mid=ss+se>>1; if(qi<=mid) Set(ls[c],ss,mid,qi); else Set(rs[c],mid+1,se,qi); } int Get(int c, int ss, int se, int qs, int qe) { if(qs>qe || qs>se || ss>qe) return 0; if(qs<=ss && qe>=se) return sum[c]; int mid=ss+se>>1; return Get(ls[c],ss,mid,qs,qe)+Get(rs[c],mid+1,se,qs,qe); } int main() { int n,q; scanf("%i %i",&n,&q); for(int i=1;i<=n;i++) scanf("%i %i",&a[i],&b[i]),uid[i]=i; for(int i=1;i<=q;i++) scanf("%i %i",&x[i],&y[i]),qid[i]=i; sort(uid+1,uid+1+n,[&](int i, int j){ return a[i]>a[j] || (a[i]==a[j] && b[i]>b[j]);}); sort(qid+1,qid+1+q,[&](int i, int j){ return x[i]>x[j];}); multiset<int> st; int k=1; for(int i=1,j;i<=n;i=j) { while(k<=q && (x[qid[k]]>a[uid[i]])) { ans[qid[k]]=Get(root[0],0,lim,0,y[qid[k]])-Get(root[1],0,lim,0,y[qid[k]]); k++; } vector<int> tmp; for(j=i;j<=n && a[uid[i]]==a[uid[j]];j++) { auto it=st.upper_bound(b[uid[j]]); if(it!=st.end()) { Set(root[1],0,lim,*it); st.erase(it); } Set(root[0],0,lim,b[uid[j]]); tmp.pb(b[uid[j]]); } for(int l:tmp) st.insert(l); } while(k<=q) { ans[qid[k]]=Get(root[0],0,lim,0,y[qid[k]])-Get(root[1],0,lim,0,y[qid[k]]); k++; } for(int i=1;i<=q;i++) printf("%i\n",ans[i]); return 0; }

Compilation message (stderr)

matryoshka.cpp: In function 'void Set(int&, int, int, int)':
matryoshka.cpp:15:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int mid=ss+se>>1;
          ~~^~~
matryoshka.cpp: In function 'int Get(int, int, int, int, int)':
matryoshka.cpp:23:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int mid=ss+se>>1;
          ~~^~~
matryoshka.cpp: In function 'int main()':
matryoshka.cpp:29:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%i %i",&n,&q);
  ~~~~~^~~~~~~~~~~~~~~
matryoshka.cpp:30:50: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=1;i<=n;i++) scanf("%i %i",&a[i],&b[i]),uid[i]=i;
                        ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~
matryoshka.cpp:31:50: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=1;i<=q;i++) scanf("%i %i",&x[i],&y[i]),qid[i]=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...