QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#106201#6394. Turn on the Lightblzgods#TL 0ms0kbC++11849b2023-05-16 21:39:002023-05-16 21:39:03

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-16 21:39:03]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2023-05-16 21:39:00]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+10;

int query(int x)
{
    printf("? %d\n",x);scanf("%d",&x);return x;
}
void print(int x)
{
    printf("! %d\n",x);
}
void solve()
{
    int n;scanf("%d",&n);
    int lst=0;
    int l=1,r=n;
    while(1)
    {
        int now=query(l);
        if(now==lst){print(l);return ;}
        l=l+1;
        lst=now;
        while(l<r)
        {
            int mid=(l+r)/2;
            int now=query(mid);
            if(now==lst){print(mid);return ;}
            if(now>lst)
            {
                l=mid+1;lst=now;
            }
            else
            {
                r=mid-1;lst=now;break;
            }
        }
        if(l==r){print(l);return ;}
    }
}
int main()
{
    int T=1;
    while(T--)solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Time Limit Exceeded

input:

3

output:


result: