제출 #1325631

#제출 시각아이디문제언어결과실행 시간메모리
1325631eri16커다란 상품 (IOI17_prize)C++20
0 / 100
26 ms400 KiB
#include <bits/stdc++.h>
using namespace std;

vector<int> ask(int i);

vector <int> pos;

int find_best(int n){
    //let us denote the number of item of u as f(u)
    //from simple algebra we know that f(v-1)<500
    //and since 17<log2(200000)<18 we know we need 18 operation
    //for each query -- hence we can find every item of value
    //higher than v at 18*500 = 9000 queries
    
    int mx = 0;
    
    for (int ind = 0; ind < 500; ind++){
        vector <int> v = ask(ind);
        if (v[0]+v[1]==0){return ind;}
        mx=max(mx,v[0]+v[1]);
    }
    
    while (true){
        
        int l=0;
        int r=n-1;
        
        while (l<r){
            int m = (l+r)/2;
            vector <int> v = ask(m);
            
            if (v[0]+v[1]==0){return m;}            
            if (v[0]+v[1]<mx){
                auto it = lower_bound(pos.begin(), pos.end(), m);
                pos.insert(it, m);  
                r=m;
                continue;
            }
            
            int lower=lower_bound(pos.begin(), pos.end(), m ) - pos.begin();
            v[0]-=lower;
            if (v[0]){r=m;}
            else{l=m+1;}
        }
        
        if (l==r){
            //justincase
            if (binary_search(pos.begin(), pos.end(), l)){continue;}
            else{
                auto it = lower_bound(pos.begin(), pos.end(), l);
                pos.insert(it, l);                 
            }
        }
    }
    
    return -1;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...