QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#738149#9570. Binary TreewdwAC ✓345ms20964kbC++202.8kb2024-11-12 17:54:292024-11-12 17:54:30

Judging History

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

  • [2024-11-12 17:54:30]
  • 评测
  • 测评结果:AC
  • 用时:345ms
  • 内存:20964kb
  • [2024-11-12 17:54:29]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;
#define int long long
vector<vector<int>> q;
vector<int> fa1;

int js(int a, int b) {
    cout << "? " << a << " " << b << endl;
    int x;
    cin >> x;
    return x;
}

vector<int> ma, vis, siz, pl;
int ans1 = 0, ans2 = 0;
int id1, id2;
int num = 0;

void dfs(int u, int fa) {
    num++;
    siz[u] = 1;
    ma[u] = 0;
    for (auto j: q[u]) {
        if (j == fa || vis[j])continue;
        dfs(j, u);
        siz[u] += siz[j];
        if (ma[u] < siz[j]) {
            pl[u] = j;
            ma[u] = siz[j];
        }
    }
}

void dfs2(int u, int fa) {
    if (ma[u] < num - siz[u]) {
        pl[u] = fa;
        ma[u] = num - siz[u];
    }
    for (auto j: q[u]) {
        if (j == fa || vis[j])continue;
        dfs2(j, u);
    }
    if (ans1 > ma[u]) {
        ans1 = ma[u];
        id1 = u;
    }

}

void solve() {
    int n;
    cin >> n;
    pl = siz = vis = ma = fa1 = vector<int>(n + 5);

    q = vector<vector<int>>(n + 5);
    for (int i = 1, a, b; i <= n; i++) {
        cin >> a >> b;
        if (a) {
            q[i].push_back(a);
            q[a].push_back(i);
        }
        if (b) {
            q[i].push_back(b);
            q[b].push_back(i);
        }
    }
    ans1 = 0, ans2 = 0;
    num = 0;
    ans1 = 1e9;
    dfs(1, 0);
    dfs2(1, 0);
    int cnt = 0;
    int fa1 = id1;
    id2 = pl[id1];
    cnt++;
    for (int i = 0; i < q[fa1].size(); i++) {
        int y = q[fa1][i];
        if (vis[y] || y == id2)continue;
        cnt++;
        if (cnt == 2) {
            id1 = y;
        }
    }
    int q1 = js(id1, id2);
    while (1) {
        if (q1 == 0) {
            if (cnt >= 2) {
                vis[fa1] = 1;
            } else if (cnt == 1) {
                vis[id2] = 1;
            }
        } else if (q1 == 2) {
            if (cnt >= 2) {
                vis[fa1] = 1;
            } else if (cnt == 1) {
                vis[id1] = 1;
            }
            id1 = id2;
        } else {
            vis[id1] = 1, vis[id2] = 1;
            id1 = fa1;
        }
        num = 0;
        ans1 = 1e9;
        dfs(id1, 0);
        if (num == 1) {
            cout << "!" << " " << id1 << endl;
            return;
        }
        dfs2(id1, 0);
        cnt = 0;
        fa1 = id1;
        id2 = pl[id1];
        cnt++;
        for (int i = 0; i < q[fa1].size(); i++) {
            int y = q[fa1][i];
            if (vis[y] || y == id2)continue;
            cnt++;
            if (cnt == 2) {
                id1 = y;
            }
        }
        q1 = js(id1, id2);
    }


}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    int T = 1;
    cin >> T;
    while (T--) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
5
0 0
1 5
2 4
0 0
0 0
2
0
2
0 2
0 0
2

output:

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

result:

ok OK (2 test cases)

Test #2:

score: 0
Accepted
time: 60ms
memory: 4748kb

input:

5555
8
2 0
8 6
0 0
3 0
0 0
7 0
0 0
5 4
2
2
0
8
0 0
1 4
2 0
0 0
7 8
0 0
3 0
6 0
2
1
2
8
5 8
0 0
1 7
0 0
0 0
4 2
0 0
6 0
2
2
2
5
4 5
3 1
0 0
0 0
0 0
1
0
8
0 0
0 0
5 6
0 0
1 4
2 0
3 8
0 0
1
2
5
3 0
5 1
0 0
0 0
4 0
0
0
5
5 0
0 0
0 0
3 0
2 4
2
2
3
3 0
1 0
0 0
2
2
2 0
0 0
2
3
2 3
0 0
0 0
2
10
2 8
9 7
0 0
...

output:

? 5 2
? 7 2
? 1 2
! 1
? 5 3
? 4 1
? 3 2
! 2
? 6 1
? 7 1
? 5 1
! 1
? 4 2
? 5 1
! 5
? 6 5
? 3 8
! 8
? 1 5
? 3 1
! 3
? 1 4
? 3 4
! 4
? 2 3
! 3
? 2 1
! 1
? 3 2
! 2
? 6 2
? 9 1
? 10 9
! 10
? 2 1
! 2
? 9 5
? 8 4
? 5 3
! 5
? 8 5
? 1 7
? 5 3
! 3
? 3 9
? 7 1
? 9 2
! 2
? 2 1
! 1
? 3 4
? 7 1
! 1
? 9 4
? 3 2
? ...

result:

ok OK (5555 test cases)

Test #3:

score: 0
Accepted
time: 59ms
memory: 3976kb

input:

600
2
2 0
0 0
2
3
2 0
3 0
0 0
2
4
4 0
1 0
0 0
3 0
2
2
5
4 0
0 0
1 0
2 0
3 0
0
0
6
4 0
6 0
2 0
5 0
0 0
1 0
2
0
7
7 0
3 0
6 0
5 0
2 0
1 0
0 0
2
0
8
7 0
0 0
2 0
8 0
1 0
5 0
3 0
6 0
2
2
2
9
7 0
4 0
2 0
1 0
0 0
8 0
9 0
5 0
6 0
0
2
2
10
9 0
6 0
8 0
7 0
0 0
10 0
2 0
4 0
5 0
1 0
2
2
2
11
2 0
10 0
6 0
9 0
0 ...

output:

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

result:

ok OK (600 test cases)

Test #4:

score: 0
Accepted
time: 130ms
memory: 20964kb

input:

2
99999
21832 0
77205 0
62668 0
58313 0
14640 0
76941 0
62678 0
8464 0
43145 0
26195 0
46140 0
83205 0
40047 0
81645 0
27077 0
92036 0
14236 0
3576 0
15430 0
75654 0
29049 0
62218 0
83318 0
1116 0
77861 0
9755 0
49236 0
70959 0
62295 0
33580 0
88208 0
55840 0
71061 0
24695 0
88831 0
1891 0
57285 0
9...

output:

? 70790 43991
? 98065 36882
? 89400 44312
? 52881 29266
? 79632 4792
? 60575 42596
? 49462 48047
? 35653 89053
? 5200 97401
? 88604 36002
? 39621 70194
? 42334 66655
? 98852 88973
? 99415 44977
? 43955 35161
? 35161 44977
! 44977
? 46352 44110
? 47168 63067
? 51576 38328
? 60860 75910
? 28720 42451
...

result:

ok OK (2 test cases)

Test #5:

score: 0
Accepted
time: 70ms
memory: 12744kb

input:

15
3
0 0
1 0
2 0
1
7
6 0
3 0
5 0
0 0
7 0
4 0
1 0
2
2
15
6 0
5 0
1 0
7 0
14 0
11 0
15 0
12 0
2 0
4 0
9 0
13 0
0 0
8 0
3 0
0
0
0
31
3 0
31 0
17 0
23 0
4 0
13 0
1 0
12 0
6 0
0 0
20 0
26 0
14 0
29 0
8 0
25 0
21 0
19 0
5 0
15 0
18 0
10 0
22 0
7 0
28 0
2 0
24 0
30 0
27 0
9 0
16 0
2
0
0
2
63
15 0
62 0
5 0
...

output:

? 1 3
! 2
? 1 5
? 5 2
! 2
? 6 9
? 3 7
? 3 6
! 3
? 29 13
? 16 2
? 28 9
? 28 16
! 16
? 37 8
? 30 14
? 55 56
? 19 22
? 22 18
! 6
? 36 89
? 110 96
? 1 81
? 118 10
? 70 75
? 70 118
! 118
? 233 64
? 68 246
? 145 28
? 40 61
? 190 230
? 248 69
? 248 190
! 248
? 48 439
? 468 437
? 37 322
? 112 223
? 467 8
? ...

result:

ok OK (15 test cases)

Test #6:

score: 0
Accepted
time: 64ms
memory: 12924kb

input:

16
2
2 0
0 0
2
4
4 0
3 0
1 0
0 0
2
2
8
5 0
0 0
4 0
8 0
2 0
3 0
6 0
1 0
2
2
2
16
2 0
5 0
1 0
11 0
13 0
14 0
8 0
6 0
0 0
4 0
3 0
7 0
15 0
10 0
16 0
9 0
2
2
2
0
32
15 0
0 0
14 0
18 0
26 0
17 0
25 0
27 0
6 0
9 0
4 0
13 0
23 0
30 0
32 0
12 0
11 0
31 0
28 0
3 0
19 0
10 0
22 0
7 0
5 0
29 0
24 0
20 0
21 0
1...

output:

? 2 1
! 1
? 2 1
? 4 1
! 1
? 3 8
? 2 1
? 8 1
! 1
? 4 3
? 15 5
? 3 2
? 5 2
! 5
? 30 12
? 4 17
? 23 10
? 17 9
? 10 9
! 10
? 3 60
? 49 41
? 31 37
? 35 40
? 37 62
? 40 62
! 40
? 124 57
? 58 48
? 39 69
? 37 31
? 125 76
? 31 14
? 76 14
! 14
? 113 90
? 222 91
? 148 57
? 231 68
? 112 255
? 81 135
? 255 251
?...

result:

ok OK (16 test cases)

Test #7:

score: 0
Accepted
time: 80ms
memory: 13028kb

input:

15
2
2 0
0 0
2
6
5 0
1 0
6 0
2 0
3 0
0 0
2
2
14
12 0
0 0
11 0
5 0
7 0
1 0
8 0
10 0
14 0
13 0
6 0
9 0
2 0
4 0
2
0
1
30
10 0
29 0
23 0
28 0
9 0
14 0
2 0
30 0
19 0
0 0
15 0
1 0
22 0
8 0
18 0
27 0
7 0
24 0
26 0
3 0
20 0
25 0
6 0
17 0
4 0
12 0
21 0
16 0
13 0
5 0
2
0
0
2
62
24 0
22 0
18 0
17 0
49 0
53 0
3...

output:

? 2 1
! 1
? 3 1
? 1 4
! 4
? 5 14
? 12 6
? 12 14
! 9
? 16 21
? 8 5
? 6 3
? 6 8
! 8
? 10 60
? 9 2
? 36 34
? 24 47
? 47 9
! 52
? 84 70
? 37 90
? 56 58
? 116 29
? 80 31
? 31 115
! 31
? 204 159
? 235 47
? 169 248
? 1 84
? 162 87
? 249 222
? 222 1
! 1
? 209 359
? 137 139
? 71 459
? 474 289
? 156 36
? 246 ...

result:

ok OK (15 test cases)

Test #8:

score: 0
Accepted
time: 56ms
memory: 3980kb

input:

600
2
2 0
0 0
2
3
3 2
0 0
0 0
2
4
3 0
0 0
0 0
1 2
2
2
5
0 0
3 1
4 5
0 0
0 0
1
0
6
3 5
1 4
0 0
6 0
0 0
0 0
2
0
7
3 7
0 0
0 0
2 5
0 0
1 4
0 0
2
0
8
0 0
3 7
1 0
2 5
6 8
0 0
0 0
0 0
2
2
2
9
9 8
0 0
7 2
0 0
0 0
0 0
0 0
4 5
3 6
2
1
0
10
3 6
8 0
4 2
5 7
0 0
10 9
0 0
0 0
0 0
0 0
2
1
2
11
0 0
4 9
5 8
6 3
0 0...

output:

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

result:

ok OK (600 test cases)

Test #9:

score: 0
Accepted
time: 88ms
memory: 15724kb

input:

2
99999
0 0
7999 97267
75750 37659
0 0
0 0
33761 92098
90707 18838
13602 27569
0 0
0 0
0 0
0 0
0 0
0 0
0 0
14586 86647
1519 23132
0 0
3430 14643
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
47066 36968
95308 38482
34100 25297
0 0
0 0
0 0
0 0
88902 58991
0 0
0 0
66315 68538
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0...

output:

? 69076 50379
? 11838 79924
? 15463 18079
? 88632 41708
? 89674 37031
? 10610 13061
? 9674 45858
? 79520 8472
? 15283 44732
? 73157 75657
? 69906 50760
? 67104 9677
? 89523 89655
? 93235 70757
? 95546 60320
! 60320
? 78976 72481
? 84675 96633
? 81852 2124
? 84822 64228
? 55776 50823
? 89542 22888
? ...

result:

ok OK (2 test cases)

Test #10:

score: 0
Accepted
time: 57ms
memory: 10244kb

input:

15
3
3 2
0 0
0 0
1
7
0 0
3 6
0 0
7 2
0 0
0 0
5 1
2
2
15
14 12
0 0
0 0
0 0
8 6
10 11
0 0
3 7
2 4
0 0
0 0
0 0
15 5
0 0
9 1
0
0
0
31
4 9
0 0
29 17
0 0
0 0
15 31
5 21
18 14
0 0
0 0
0 0
16 2
12 7
0 0
23 10
0 0
30 13
0 0
24 27
11 26
0 0
0 0
0 0
0 0
19 20
0 0
0 0
0 0
6 25
8 1
28 22
2
0
0
2
63
53 48
40 57
0...

output:

? 2 3
! 1
? 7 2
? 6 3
! 3
? 15 5
? 1 9
? 12 14
! 12
? 17 29
? 25 6
? 20 19
? 26 11
! 11
? 1 2
? 48 53
? 23 28
? 8 34
? 21 49
! 34
? 115 20
? 45 48
? 15 88
? 8 102
? 50 93
? 70 59
! 59
? 140 70
? 196 206
? 130 254
? 150 6
? 191 87
? 82 81
? 86 113
! 86
? 121 60
? 71 305
? 225 284
? 15 251
? 268 276
?...

result:

ok OK (15 test cases)

Test #11:

score: 0
Accepted
time: 55ms
memory: 10080kb

input:

16
2
0 0
1 0
2
4
4 2
0 0
0 0
3 0
2
2
8
3 0
0 0
0 0
0 0
1 2
0 0
6 4
5 7
2
2
2
16
16 15
0 0
0 0
0 0
7 11
8 10
0 0
13 0
0 0
0 0
0 0
3 9
0 0
4 2
5 14
6 12
2
1
1
0
32
0 0
22 21
25 18
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
5 10
30 0
1 24
12 31
0 0
0 0
16 8
3 15
11 26
23 14
28 20
6 9
0 0
13 27
0 0
0 0
7 17
0 0
0 ...

output:

? 2 1
! 1
? 3 1
? 2 1
! 1
? 7 5
? 3 5
? 2 5
! 5
? 6 1
? 1 5
? 2 4
? 15 14
! 15
? 3 32
? 21 22
? 14 23
? 9 6
! 9
? 58 37
? 40 19
? 55 63
? 18 4
? 51 41
! 41
? 13 92
? 57 92
? 102 80
? 52 22
? 125 127
? 40 87
! 125
? 3 245
? 223 245
? 131 150
? 34 193
? 71 164
? 44 86
? 31 118
! 118
? 511 39
? 289 39
...

result:

ok OK (16 test cases)

Test #12:

score: 0
Accepted
time: 56ms
memory: 10252kb

input:

15
2
0 0
1 0
2
6
6 4
1 5
0 0
0 0
3 0
0 0
2
2
14
0 0
1 7
5 11
13 9
0 0
2 8
0 0
10 0
0 0
0 0
0 0
14 6
0 0
3 4
2
2
1
30
7 0
5 13
0 0
0 0
14 30
15 20
0 0
0 0
3 19
0 0
0 0
11 21
9 1
16 24
0 0
0 0
28 2
8 10
0 0
0 0
0 0
0 0
18 6
0 0
4 29
12 25
0 0
23 26
0 0
27 22
2
2
0
0
62
0 0
0 0
28 47
7 38
0 0
0 0
17 26...

output:

? 2 1
! 1
? 5 1
? 4 6
! 6
? 3 12
? 8 2
? 7 1
! 2
? 23 17
? 13 5
? 30 14
? 22 27
! 22
? 57 16
? 43 36
? 4 12
? 38 7
? 5 41
! 41
? 53 125
? 123 17
? 5 15
? 12 52
? 96 88
? 50 35
! 35
? 42 241
? 193 112
? 124 88
? 30 17
? 116 242
? 204 39
? 176 78
! 176
? 376 284
? 32 30
? 159 98
? 40 43
? 387 307
? 22...

result:

ok OK (15 test cases)

Test #13:

score: 0
Accepted
time: 27ms
memory: 3976kb

input:

600
2
0 0
1 0
2
3
0 0
1 3
0 0
2
4
2 4
0 0
0 0
3 0
2
2
5
2 5
0 0
0 0
0 0
4 3
1
0
6
6 4
0 0
0 0
3 0
2 1
0 0
1
0
7
0 0
0 0
2 4
5 6
0 0
0 0
1 3
2
0
8
2 7
0 0
6 0
0 0
8 3
0 0
4 5
0 0
2
2
2
9
5 2
0 0
7 4
6 8
0 0
0 0
0 0
9 1
0 0
1
1
2
10
3 5
10 7
0 0
0 0
6 2
0 0
4 0
9 1
0 0
0 0
2
2
2
11
9 6
4 1
0 0
0 0
11 ...

output:

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

result:

ok OK (600 test cases)

Test #14:

score: 0
Accepted
time: 99ms
memory: 19604kb

input:

2
99999
96748 53986
34197 77552
29863 63559
79099 26449
45078 1051
0 0
27416 4135
0 0
38606 81189
93892 68603
48776 185
79602 18311
51243 83678
89044 40032
28883 35663
0 0
0 0
21603 15821
0 0
51448 75971
70275 8326
0 0
0 0
57049 72937
3297 94939
0 0
59258 39159
3205 34675
54876 24769
0 0
0 0
0 0
851...

output:

? 27459 71188
? 6820 87538
? 32876 59029
? 18644 46360
? 48677 23966
? 25610 92232
? 95643 43298
? 56586 28802
? 69299 55920
? 71925 99638
? 56155 91225
? 48640 38638
? 55952 63410
? 98491 43812
? 82605 63410
? 95799 85550
! 95799
? 6749 50499
? 29635 17715
? 18269 31421
? 89584 64768
? 3526 98628
?...

result:

ok OK (2 test cases)

Test #15:

score: 0
Accepted
time: 57ms
memory: 11632kb

input:

15
3
0 0
1 3
0 0
1
7
0 0
1 7
0 0
6 2
3 4
0 0
0 0
2
2
15
2 11
0 0
13 1
12 14
0 0
0 0
5 8
10 4
0 0
0 0
0 0
0 0
0 0
6 15
9 3
2
1
0
31
24 22
0 0
31 6
0 0
4 3
11 19
0 0
0 0
28 21
25 20
0 0
0 0
0 0
2 16
0 0
27 18
8 10
15 17
26 1
23 29
7 5
12 14
0 0
0 0
0 0
0 0
0 0
0 0
30 13
0 0
0 0
2
1
2
0
63
51 35
33 57
...

output:

? 1 3
! 2
? 6 2
? 7 1
! 1
? 4 15
? 13 1
? 3 9
! 3
? 1 14
? 8 10
? 14 18
? 17 15
! 17
? 15 38
? 1 42
? 9 2
? 2 34
? 23 5
! 5
? 34 51
? 62 96
? 8 100
? 105 52
? 81 82
? 57 70
! 57
? 122 124
? 22 162
? 180 60
? 221 119
? 171 203
? 60 69
? 10 153
! 153
? 266 322
? 386 146
? 106 72
? 265 66
? 481 89
? 16...

result:

ok OK (15 test cases)

Test #16:

score: 0
Accepted
time: 49ms
memory: 12068kb

input:

16
2
0 0
1 0
2
4
0 0
1 0
4 2
0 0
2
2
8
0 0
0 0
0 0
3 5
8 6
2 0
1 4
0 0
2
2
2
16
0 0
7 8
0 0
1 2
0 0
0 0
0 0
5 10
3 0
12 16
14 13
0 0
15 4
0 0
0 0
6 9
2
2
2
0
32
26 17
5 31
28 25
18 7
0 0
0 0
14 12
15 0
22 4
0 0
29 1
19 2
0 0
0 0
0 0
6 8
10 21
0 0
0 0
0 0
13 3
0 0
0 0
0 0
32 30
0 0
20 9
0 0
0 0
23 16...

output:

? 2 1
! 1
? 4 2
? 1 2
! 2
? 8 4
? 1 4
? 3 4
! 4
? 5 2
? 11 4
? 7 4
? 1 4
! 1
? 29 1
? 32 3
? 1 21
? 28 21
? 13 21
! 13
? 39 56
? 16 19
? 36 55
? 42 51
? 50 51
? 21 51
! 51
? 79 38
? 53 17
? 103 117
? 45 113
? 30 123
? 109 123
? 102 123
! 102
? 255 133
? 138 75
? 92 14
? 211 1
? 103 3
? 190 95
? 40 9...

result:

ok OK (16 test cases)

Test #17:

score: 0
Accepted
time: 57ms
memory: 12204kb

input:

15
2
0 0
1 0
2
6
0 0
5 0
1 2
0 0
0 0
4 3
1
2
14
8 14
0 0
0 0
0 0
0 0
12 11
10 0
0 0
2 7
0 0
4 1
0 0
3 6
5 9
1
1
1
30
29 21
6 9
0 0
0 0
0 0
0 0
0 0
19 17
24 30
0 0
14 26
23 0
0 0
0 0
25 18
0 0
7 20
16 12
0 0
13 11
28 8
10 15
0 0
0 0
0 0
3 22
5 2
0 0
0 0
4 1
0
1
1
2
62
0 0
34 33
0 0
0 0
0 0
37 45
0 0
...

output:

? 2 1
! 1
? 1 2
? 3 4
! 4
? 8 14
? 12 11
? 6 3
! 13
? 8 20
? 4 9
? 28 1
? 21 19
! 19
? 48 42
? 55 12
? 20 43
? 6 58
? 10 46
! 58
? 41 40
? 108 69
? 53 84
? 112 103
? 21 17
? 76 4
! 76
? 59 90
? 158 221
? 225 198
? 93 32
? 178 181
? 157 132
? 168 115
! 115
? 468 60
? 352 44
? 489 36
? 196 451
? 203 4...

result:

ok OK (15 test cases)

Test #18:

score: 0
Accepted
time: 102ms
memory: 15476kb

input:

2
99999
0 0
88119 0
72740 0
6901 19702
0 0
10620 84889
0 0
9552 63972
45156 60768
9152 72379
0 0
59875 97207
48193 0
17282 54916
65927 27713
80083 15817
36966 75381
0 0
77279 56298
0 0
11554 61779
0 0
89976 0
65282 42151
95206 62876
97329 86772
0 0
0 0
0 0
11820 0
0 0
20432 0
50520 39907
0 0
46948 1...

output:

? 35226 52174
? 16093 26122
? 10853 11494
? 37465 11494
? 73088 90037
? 21572 90037
? 99968 51091
? 37874 7067
? 14316 75096
? 11485 75096
? 41734 42793
? 42793 59747
? 67072 472
? 64770 59747
! 92650
? 91773 80592
? 68004 50906
? 65219 73367
? 33796 20489
? 19704 74041
? 56446 35779
? 85560 35779
?...

result:

ok OK (2 test cases)

Test #19:

score: 0
Accepted
time: 345ms
memory: 3540kb

input:

100000
2
0 0
0 1
2
2
0 0
0 1
0
2
0 0
0 1
2
2
0 0
0 1
0
2
0 0
0 1
2
2
0 0
0 1
0
2
0 0
0 1
0
2
0 0
0 1
0
2
0 0
0 1
0
2
0 0
0 1
2
2
0 0
0 1
0
2
0 0
0 1
0
2
0 0
0 1
2
2
0 0
0 1
2
2
0 0
0 1
0
2
0 0
0 1
2
2
0 0
0 1
2
2
0 0
0 1
2
2
0 0
0 1
2
2
0 0
0 1
0
2
0 0
0 1
0
2
0 0
0 1
0
2
0 0
0 1
2
2
0 0
0 1
0
2
0 0...

output:

? 2 1
! 1
? 2 1
! 2
? 2 1
! 1
? 2 1
! 2
? 2 1
! 1
? 2 1
! 2
? 2 1
! 2
? 2 1
! 2
? 2 1
! 2
? 2 1
! 1
? 2 1
! 2
? 2 1
! 2
? 2 1
! 1
? 2 1
! 1
? 2 1
! 2
? 2 1
! 1
? 2 1
! 1
? 2 1
! 1
? 2 1
! 1
? 2 1
! 2
? 2 1
! 2
? 2 1
! 2
? 2 1
! 1
? 2 1
! 2
? 2 1
! 2
? 2 1
! 1
? 2 1
! 1
? 2 1
! 1
? 2 1
! 1
? 2 1
! 1
...

result:

ok OK (100000 test cases)

Extra Test:

score: 0
Extra Test Passed