Code Submission Evaluation System Login

CSES - HIIT Open 2017

HIIT Open 2017

Contest start:2017-05-27 11:00:00
Contest end:2017-05-27 16:00:00

Task list | Submit code | Submissions | Messages | Scoreboard


History
2017-05-27 15:42:47
2017-05-27 15:42:46
2017-05-27 15:35:29
2017-05-27 15:23:15
2017-05-27 14:55:18
2017-05-27 14:50:05
2017-05-27 12:59:43
2017-05-27 12:52:19
2017-05-27 12:44:55
Task:Contest
Sender:oispa opiskelupaikka tefyllä ;...;
Submission time:2017-05-27 15:42:47
Status:READY
Result:WRONG ANSWER

Show test data

Code

#include <bits/stdc++.h>

using namespace std;
int n, k;
unordered_map<int, int> ad, ud;
int getA(int i){
    if(ad.count(i))
        return ad[i];
    cout << "1 " << i+1 << endl;
    cout.flush();
    int re; cin >> re;
    ad[i] = re;
    return re;
}

int getU(int i){
    if(ud.count(i))
        return ud[i];
    cout << "2 " << i+1 << endl;
    cout.flush();
    int re; cin >> re;
    ud[i] = re;
    return re;
}
bool dd = false;
bool endd = false;

int idxa(int lol){
    int cn = getA(lol);
    int i = -1;
    for(int bi = 1<<19; bi > 0; bi/=2){
        while(i+bi < n && cn > getU(i+bi))
            i+=bi;
    }
    return lol+(i+1);
}
void hae1(){
    int i = 0;
    for(int bi = 1<<19; bi > 0; bi/=2){
        while(i+bi < n && idxa(i+bi) <= k)
            i+=bi;
    }
    if(i == k){
        endd = 1;
        cout << "3 " << getA(i) << endl;
    }
}

int idxu(int lol){
    int cn = getU(lol);
    int i = -1;
    for(int bi = 1<<19; bi > 0; bi/=2){
        while(i+bi < n && cn > getA(i+bi))
            i+=bi;
    }
    return lol+(i+1);
}
void hae2(){
    if(endd)
        return;
    int i = 0;
    for(int bi = 1<<19; bi > 0; bi/=2){
        while(i+bi < n && idxu(i+bi) <= k)
            i+=bi;
    }
    if(i == k){
        endd = 1;
        cout << "3 " << getU(i) << endl;
    }
}



int main(){
    cin >> n >> k;
    k--;
    hae1();
    hae2();
    return 0;
}