제출 #152851

#제출 시각아이디문제언어결과실행 시간메모리
152851junodeveloper로봇 (IOI13_robots)C++14
90 / 100
3086 ms42700 KiB
#include <bits/stdc++.h> #include "robots.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 *val[2]; int sum[1000010]; int tree[2][offset<<1]; void Up(int t,int h) { while(h>0) { if(tree[t][h*2+1]==-1||(tree[t][h*2]!=-1&&sum[tree[t][h*2]]>sum[tree[t][h*2+1]])) tree[t][h]=tree[t][h*2]; else tree[t][h]=tree[t][h*2+1]; h/=2; } } inline void Add(int t,int p,int i) { tree[t][p+offset]=i; Up(t,(p+offset)/2); } inline void Remove(int t,int p) { tree[t][p+offset]=-1; Up(t,(p+offset)/2); } int query(int t,int l,int r) { if(l>r) return -1; int ret=-1; l+=offset,r+=offset; while(l<=r) { if(ret==-1||(tree[t][l]!=-1&&sum[ret]<sum[tree[t][l]])) ret=tree[t][l]; if(ret==-1||(tree[t][r]!=-1&&sum[ret]<sum[tree[t][r]])) ret=tree[t][r]; if(l==r) break; l=(l+1)>>1; r=(r-1)>>1; } return ret; } int putaway (int A, int B, int T, int X[], int Y[], int W[], int S[]) { int i,j; memset(tree,-1,sizeof(tree)); vector<pii> v,w; sort(X,X+A); sort(Y,Y+B); val[0]=S,val[1]=W; for(i=0;i<T;i++) { v.push_back({W[i],i}); w.push_back({S[i],i}); } sort(all(v)); sort(all(w)); for(i=0;i<A;i++) { X[i]=lower_bound(all(v),make_pair(X[i],0))-v.begin(); } for(i=0;i<B;i++) { Y[i]=lower_bound(all(w),make_pair(Y[i],0))-w.begin(); } for(i=0;i<T;i++) { W[i]=lower_bound(all(v),make_pair(W[i],i))-v.begin()+1; S[i]=lower_bound(all(w),make_pair(S[i],i))-w.begin()+1; sum[i]=(int)(lower_bound(X,X+A,W[i])-X)+(int)(lower_bound(Y,Y+B,S[i])-Y); Add(0,W[i],i); Add(1,S[i],i); } int ans=0,q; bool flag; while(1) { flag=false; for(i=0;T&&i<A;i++) { q=query(0,0,X[i]); if(q==-1) continue; Remove(0,W[q]); Remove(1,S[q]); T--; flag=true; } for(i=0;T&&i<B;i++) { q=query(1,0,Y[i]); if(q==-1) continue; Remove(0,W[q]); Remove(1,S[q]); T--; flag=true; } ans++; if(!T) break; if(!flag) { return -1; } } return ans; }

컴파일 시 표준 에러 (stderr) 메시지

robots.cpp: In function 'int putaway(int, int, int, int*, int*, int*, int*)':
robots.cpp:46:8: warning: unused variable 'j' [-Wunused-variable]
  int i,j;
        ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...