QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#883527#9734. Identify Chordlzc0115TL 1ms3456kbC++141.3kb2025-02-05 16:45:402025-02-05 16:45:41

Judging History

This is the latest submission verdict.

  • [2025-02-05 16:45:41]
  • Judged
  • Verdict: TL
  • Time: 1ms
  • Memory: 3456kb
  • [2025-02-05 16:45:40]
  • Submitted

answer

#include<iostream>
#include<algorithm>

using namespace std;

int t, n, w;

int Ask(int x, int y){
  int ans;
  cout << "? " << x + 1 << " " << y + 1 << endl;
  cin >> ans;
  return ans;
}

void Ans(int x, int y){
  int ans;
  cout << "! " << x + 1 << " " << y + 1 << endl;
  cin >> ans;
  if(ans == -1) exit(0);
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
  cin >> t;
  while(t--){
    cin >> n;
    int x = 0, y = (n + 1) / 2, d = 0, p;
    w = Ask(x, y);
    while(w == n / 2){
      if(!(n & 1)) x++, y++;
      else if(y - x == (n + 1) / 2) x++;
      else y++;
      w = Ask(x, y);
    }
    int a = Ask((x + 1) % n, y), b = Ask((x + n - 1) % n, y);
    if(a >= w && b >= w) p = x, d = w - 1;
    else if(a < w){
      int l = 1, r = n / 2;
      while(l <= r){
        int mid = (l + r) >> 1;
        if(Ask((x + mid) % n, y) == w - mid) l = mid + 1;
        else r = mid - 1;
      }
      p = (x + l - 1) % n, d = w - l;
    } else if(b < w){
      int l = 1, r = n / 2;
      while(l <= r){
        int mid = (l + r) >> 1;
        if(Ask((x + n - mid) % n, y) == w - mid) l = mid + 1;
        else r = mid - 1;
      }
      p = (x + n - l + 1) % n, d = w - l;
    }
    if(Ask(p, (y + d) % n) == 1) Ans(p, (y + d) % n);
    else Ans(p, (y + n - d) % n);
  }
  return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3456kb

input:

2
6
2
1
2
1
1
1
1
4
1
1
1
1
1

output:

? 1 4
? 2 4
? 6 4
? 3 4
? 2 4
? 2 4
! 2 4
? 1 3
? 2 3
? 4 3
? 1 3
! 1 3

result:

ok ok (2 test cases)

Test #2:

score: -100
Time Limit Exceeded

input:

1000
15
6
5
6
2
2
3
3
1
19
4
3
5
5
2
3
1
1
17
4
3
5
4
2
3
1
1
15
7
7
7
7
6
7
6
1
1
14
5
4
6
3
5
4
5
1
15
2
1
3
4
2
1
1
1
17
8
8
7
6
7
5
5
4
1
1
20
6
7
7
5
1
13
6
6
6
6
5
4
5
2
2
3
1
1
18
3
4
2
4
3
2
1
1
13
3
4
2
3
2
3
1
1
14
2
3
1
3
2
1
1
1
17
7
6
7
3
3
2
1
1
12
5
4
5
3
4
3
1
1
10
5
5
3
2
4
2
2
1
1
...

output:

? 1 9
? 2 9
? 15 9
? 5 9
? 7 9
? 6 9
? 5 10
! 5 8
? 1 11
? 2 11
? 19 11
? 6 11
? 3 11
? 4 11
? 3 12
! 3 12
? 1 10
? 2 10
? 17 10
? 5 10
? 3 10
? 4 10
? 3 11
! 3 11
? 1 9
? 2 9
? 2 10
? 3 10
? 3 11
? 4 11
? 2 11
? 3 1
! 3 1
? 1 8
? 2 8
? 14 8
? 5 8
? 3 8
? 2 8
? 2 11
! 2 5
? 1 9
? 2 9
? 15 9
? 5 9
? ...

result: