Cod sursa(job #3293054)

Utilizator Alex_DumitrascuAlex Dumitrascu Alex_Dumitrascu Data 10 aprilie 2025 10:57:34
Problema Cbinteractiv Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.53 kb
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin.tie(0); cin.sync_with_stdio(false);
    cin>>n;
    int st=1, dr=n, mid=-1, ans=-1, poz=-1;
    while (st<=dr) {
        mid=(st+dr)/2;
        cout<<"? "<<mid<<'\n'; cout.flush();
        cin>>ans;
        if (ans==0) { //K>x
            st=mid+1;
        }
        else if (ans==1) { //K<=X
            poz=mid;
            dr=mid-1;
        }
        else {
            return 0;
        }
    }
    cout<<"! "<<poz<<'\n';
    cout.flush();
    return 0;
}