Submission #151820

#TimeUsernameProblemLanguageResultExecution timeMemory
151820junodeveloperRobots (IOI13_robots)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> #define sz(x) ((int)x.size()) #define all(x) (x).begin(), (x).end() #define fi first #define se second using namespace std; typedef long long ll; typedef long double ld; typedef pair<int,int> pii; typedef pair<ll,ll> pll; const int offset=1<<20; int A,B,T; int X[50010],Y[50010]; int a[1000010],b[1000010]; pii tree[2][4*1000010]; set<pii> st[2][1000010]; void Up(int t,int p) { while(p>0) { if(tree[t][p*2].fi>tree[t][p*2+1].fi) tree[t][p]=tree[t][p*2]; else tree[t][p]=tree[t][p*2+1]; p/=2; } } void Add(int t,int p,int x,int i) { st[t][p].insert({x,i}); p+=offset; tree[t][p]=*st[t][p-offset].rbegin(); Up(t,p/2); } void Remove(int t,int p,int x,int i) { st[t][p].erase({x,i}); p+=offset; if(!st[t][p-offset].empty()) tree[t][p]=*st[t][p-offset].rbegin(); else tree[t][p]={-1,-1}; Up(t,p/2); } pii query(int t,int l,int r) { pii ret={-1,-1}; l+=offset,r+=offset; while(1) { if(ret.fi<tree[t][l].fi) ret=tree[t][l]; if(ret.fi<tree[t][r].fi) ret=tree[t][r]; if(l==r) break; l=(l+1)>>1; r=(r-1)>>1; } return ret; } int main() { scanf("%d%d%d",&A,&B,&T); int i,j; for(i=0;i<4*1000010;i++) tree[0][i]=tree[1][i]={-1,-1}; vector<int> v,w; for(i=0;i<A;i++) scanf("%d",X+i); for(i=0;i<B;i++) scanf("%d",Y+i); sort(X,X+A); sort(Y,Y+B); for(i=0;i<T;i++) { scanf("%d%d",a+i,b+i); v.push_back(a[i]); w.push_back(b[i]); } sort(all(v)); v.erase(unique(all(v)),v.end()); sort(all(w)); w.erase(unique(all(w)),w.end()); for(i=0;i<A;i++) { X[i]=lower_bound(all(v),X[i])-v.begin(); } for(i=0;i<B;i++) { Y[i]=lower_bound(all(w),Y[i])-v.begin(); } for(i=0;i<T;i++){ a[i]=lower_bound(all(v),a[i])-v.begin()+1; b[i]=lower_bound(all(w),b[i])-v.begin()+1; Add(0,a[i],b[i],i); Add(1,b[i],a[i],i); } int ans=0; while(1) { bool flag=false; for(i=0;T&&i<A;i++) { pii q=query(0,0,X[i]); if(q.se==-1) continue; Remove(0,a[q.se],b[q.se],q.se); Remove(1,b[q.se],a[q.se],q.se); T--; flag=true; } for(i=0;T&&i<B;i++) { pii q=query(1,0,Y[i]); if(q.se==-1) continue; Remove(0,a[q.se],b[q.se],q.se); Remove(1,b[q.se],a[q.se],q.se); T--; flag=true; } ans++; if(!T) break; if(!flag) { puts("-1"); return 0; } } printf("%d", ans); return 0; }

Compilation message (stderr)

robots.cpp: In function 'int main()':
robots.cpp:53:8: warning: unused variable 'j' [-Wunused-variable]
  int i,j;
        ^
robots.cpp:52:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%d",&A,&B,&T);
  ~~~~~^~~~~~~~~~~~~~~~~~~
robots.cpp:57:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(i=0;i<A;i++) scanf("%d",X+i);
                   ~~~~~^~~~~~~~~~
robots.cpp:58:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(i=0;i<B;i++) scanf("%d",Y+i);
                   ~~~~~^~~~~~~~~~
robots.cpp:61:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d",a+i,b+i);
   ~~~~~^~~~~~~~~~~~~~~~
/tmp/ccuRYplW.o: In function `main':
robots.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccJdMh8F.o:grader.c:(.text.startup+0x0): first defined here
/tmp/ccJdMh8F.o: In function `main':
grader.c:(.text.startup+0x17e): undefined reference to `putaway'
collect2: error: ld returned 1 exit status