QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#378694#6394. Turn on the Lightgogo11#WA 1ms3708kbC++171.8kb2024-04-06 14:14:172024-04-06 14:14:17

Judging History

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

  • [2024-04-06 14:14:17]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3708kb
  • [2024-04-06 14:14:17]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ui = unsigned int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define lowbit(x) ((x) & (-x))
constexpr int N = 2e5 + 10;
constexpr int M = 5e5 + 10;
constexpr ll mod = (1LL<<20);
constexpr int INF = 0x3f3f3f3f;
constexpr ll Base = 131;
constexpr int MAXBIT = 19;

int ans;
int query(int x) {
    cout << "? " << x << endl;
    int res;
    cin >> res;
    return res;
}
void print(int ans)
{
    cout << "! " << ans << endl;
}


void solve()
{   
    int n;
    cin >> n;
    ans = 0;
    int l = 1, r = n;
    while(1)
    {
        int mid = l + r >> 1;

        if(ans == 0)
        {
            ll t = query(mid);
            if(t == ans)
            {
                // cout << mid << endl;
                print(mid);
                return;
            }
            else 
            {
                t = query(l);
                if(t == 1)
                {
                    // cout << mid << endl;
                    print(l);
                    return;
                }
                else if(t == 2) l = mid + 1;
                else if(t == 0) ++ l, r = mid - 1;
            }

            ans = t;
            continue;
        }

        
        ll t = query(mid);
        if(t == ans) 
        {
            // cout << mid << endl;
            print(mid);
            return;
        }
        else if(t > ans) l = mid + 1;
        else r = mid - 1;

        ans = t;
    }
}
int main()
{
    std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    // #ifndef ONLINE_JUDGE
    // freopen("in.txt","r",stdin);
    // freopen("out.txt","w",stdout);
    // #endif
    int _ = 1;
    // cin >> _;
    while (_--)
        solve();
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3636kb

input:

3
1
2
2

output:

? 2
? 1
? 3
! 3

result:

ok Correct position at 3

Test #2:

score: 0
Accepted
time: 1ms
memory: 3656kb

input:

10
1
2
3
3

output:

? 5
? 1
? 8
? 9
! 9

result:

ok Correct position at 9

Test #3:

score: 0
Accepted
time: 1ms
memory: 3596kb

input:

9
1
2
3
3

output:

? 5
? 1
? 7
? 8
! 8

result:

ok Correct position at 8

Test #4:

score: 0
Accepted
time: 1ms
memory: 3672kb

input:

8
1
2
3
3

output:

? 4
? 1
? 6
? 7
! 7

result:

ok Correct position at 7

Test #5:

score: 0
Accepted
time: 1ms
memory: 3588kb

input:

7
1
2
3
3

output:

? 4
? 1
? 6
? 7
! 7

result:

ok Correct position at 7

Test #6:

score: 0
Accepted
time: 1ms
memory: 3652kb

input:

6
1
2
3
3

output:

? 3
? 1
? 5
? 6
! 6

result:

ok Correct position at 6

Test #7:

score: 0
Accepted
time: 0ms
memory: 3664kb

input:

5
1
2
3
3

output:

? 3
? 1
? 4
? 5
! 5

result:

ok Correct position at 5

Test #8:

score: 0
Accepted
time: 1ms
memory: 3596kb

input:

4
1
2
3
3

output:

? 2
? 1
? 3
? 4
! 4

result:

ok Correct position at 4

Test #9:

score: 0
Accepted
time: 0ms
memory: 3708kb

input:

3
1
1

output:

? 2
? 1
! 1

result:

ok Correct position at 1

Test #10:

score: -100
Wrong Answer
time: 0ms
memory: 3648kb

input:

2
1
1

output:

? 1
? 1
! 1

result:

wrong answer Wrong favorite light!