QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#574768#6394. Turn on the LightGammaRaysCompile Error//C++231.2kb2024-09-19 00:22:492024-09-19 00:22:50

Judging History

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

  • [2024-09-19 00:22:50]
  • 评测
  • [2024-09-19 00:22:49]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

int tag;
int n;
int L, R, LST;
void solve(int l,int r,int lst)
{
    if(tag==1)
    {
        return;
    }
    int mid,x,y;
    mid=(l+r)>>1;
    if (l + 1 < r) {
        L = l;
        R = r;
        LST = lst;
    } else {
        return;
    }
    
    cout<<"? "<<mid<<"\n";
    cout.flush();
    cin>>x;
    if(x==lst)
    {
        tag=1;
        cout<<"! "<<mid;
        cout.flush();
        return;
    }
    
    cout<<"? "<<r<<"\n";
    cout.flush();
    cin>>y;
    if(y==x)
    {
        tag=1;
        cout<<"! "<<r;
        cout.flush();
        return;
    }
    // cout<<x<<" "<<y<<endl;
    if(x<y)
    {
        solve(l,max(l,mid-1),y);
    }
    else
    {
        solve(min(r-1,mid+1),r-1,y);
    }
    return;
}

int main()
{
    int n;
    cin>>n;
    tag=0;
    solve(1,n,0);
    if (flag) return 0;
    int res;
    cout << "? " << L << endl;
    cin >> res;
    if (res == LST) {
        cout<<"! "<< L;
        return 0;
    }
    LST = res;
    cout << "? " << L << endl;
    cin >> res;
    if (res == LST) {
        cout<<"! "<< R; 
    }
    return 0;
}

Details

answer.code: In function ‘int main()’:
answer.code:62:9: error: ‘flag’ was not declared in this scope
   62 |     if (flag) return 0;
      |         ^~~~