제출 #347198

#제출 시각아이디문제언어결과실행 시간메모리
347198zaneyu커다란 상품 (IOI17_prize)C++14
90 / 100
116 ms628 KiB
/*input
8
3 2 3 1 3 3 2 3

*/
#include "prize.h"

#include<bits/stdc++.h>
using namespace std;
//order_of_key #of elements less than x
// find_by_order kth element
typedef long long int ll;
#define ld double
#define pii pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
const ll maxn=2e3+5;
const ll maxlg=__lg(maxn)+2;
const ll INF64=4e18;
const int INF=0x3f3f3f3f;
const ll MOD=(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
ll mult(ll a,ll b){
    return (a*b)%MOD;
}
ll mypow(ll a,ll b){
    if(b<=0) return 1;
    a%=MOD;
    ll res=1LL;
    while(b){
        if(b&1) res=mult(res,a);
        a=mult(a,a);
        b>>=1;
    }
    return res;
}
int find_best(int n) {
	int x=0,p=-1;
	REP(i,min(n,500)){
		vector<int> v=ask(i);
		if(v[0]==0 and v[1]==0){
			return i;
		}
		if(x<v[0]+v[1]){
			x=v[0]+v[1];
			p=i;
		}
	}
	while(p<n){
		int l=p,r=n-1;
		vector<int> z=ask(p);
		while(l<r){
			int mid=(l+r+1)/2;
			vector<int> v=ask(mid);
			if(v[1]<z[1]){
				r=mid-1;
			}
			else{
				l=mid;
			}
		}
		p=l+1;
		while(p<n){
			vector<int> v=ask(p);
			if(v[0]+v[1]==x) break;
			if(v[0]+v[1]==0){
				return p;
			}
			++p;
		}
	}
	return -1;
}	
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...