QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#281108#6394. Turn on the LightpiscesTL 0ms0kbC++14883b2023-12-09 21:07:502023-12-09 21:07:50

Judging History

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

  • [2023-12-09 21:07:50]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2023-12-09 21:07:50]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int N=1e6+10;
 
int query(int x)
{
    printf("? %d\\n",x);fflush(stdout);scanf("%d",&x);return x;
}
void print(int x)
{
    printf("! %d\\n",x);
    fflush(stdout);
}
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>>1;
            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();
}

詳細信息

Test #1:

score: 0
Time Limit Exceeded

input:

3

output:

? 1\n

result: