QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#731048#9570. Binary Treeucup-team5226#AC ✓298ms14160kbC++205.5kb2024-11-09 23:17:152024-11-09 23:17:15

Judging History

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

  • [2024-11-09 23:17:15]
  • 评测
  • 测评结果:AC
  • 用时:298ms
  • 内存:14160kb
  • [2024-11-09 23:17:15]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
template <class T>
using vc = vector<T>;
template <class T>
using vvc = vc<vc<T>>;
template <class T>
using vvvc = vc<vvc<T>>;
#define overload5(a, b, c, d, e, name, ...) name
#define overload4(a, b, c, d, name, ...) name
#define overload3(a, b, c, name, ...) name
#define rep1(n) for (ll i = 0; i < n; ++i)
#define rep2(i, n) for (ll i = 0; i < n; ++i)
#define rep3(i, a, b) for (ll i = a; i < b; ++i)
#define rep4(i, a, b, c) for (ll i = a; i < b; i += c)
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep1(n) for (ll i = n; i--;)
#define rrep2(i, n) for (ll i = n; i--;)
#define rrep3(i, a, b) for (ll i = b; i-- > (a);)
#define rrep(...) overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define each1(i, a) for (auto &&i : a)
#define each2(x, y, a) for (auto &&[x, y] : a)
#define each3(x, y, z, a) for (auto &&[x, y, z] : a)
#define each4(w, x, y, z, a) for (auto &&[w, x, y, z] : a)
#define each(...) overload5(__VA_ARGS__, each4, each3, each2, each1)(__VA_ARGS__)
#define all1(i) begin(i), end(i)
#define all2(i, a) begin(i), begin(i) + a
#define all3(i, a, b) begin(i) + a, begin(i) + b
#define all(...) overload3(__VA_ARGS__, all3, all2, all1)(__VA_ARGS__)
#define rall1(i) rbegin(i), rend(i)
#define rall2(i, a) rbegin(i), rbegin(i) + a
#define rall3(i, a, b) rbegin(i) + a, rbegin(i) + b
#define rall(...) overload3(__VA_ARGS__, rall3, rall2, rall1)(__VA_ARGS__)
template <class T>
bool chmin(T &a, const T &b) {
    if (a <= b) return 0;
    a = b;
    return 1;
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a >= b) return 0;
    a = b;
    return 1;
}
template <class T, class U>
bool chmin(T &a, const U &b) {
    return chmin(a, (T)b);
}
template <class T, class U>
bool chmax(T &a, const U &b) {
    return chmax(a, (T)b);
}
void solve();
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    ll t = 1;
    cin >> t;
    for (int i = 1; i <= t; i++) solve();
    return 0;
}
ll dy[] = {0, 0, 1, 0, -1}, dx[] = {0, 1, 0, -1, 0};
// ll dy[8] = {1, 1, 0, -1, -1, -1, 0, 1}, dx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
void solve() {
    ll n;
    cin >> n;
    vvc<ll> g(n);
    rep(i, n) {
        ll l, r;
        cin >> l >> r;
        l--, r--;
        if (l >= 0) g[i].push_back(l), g[l].push_back(i);
        if (r >= 0) g[i].push_back(r), g[r].push_back(i);
    }
    ll r = 0;
    while (true) {
        vc<ll> dp(n);
        auto dfs = [&](auto &&dfs, ll from, ll par) -> void {
            dp[from] = 1;
            each(to, g[from]) {
                if (to == par) continue;
                dfs(dfs, to, from);
                dp[from] += dp[to];
            }
        };
        dfs(dfs, r, -1);
        ll rem = dp[r];
        if (rem == 1) break;
        dp.assign(n, 0);
        auto dfs2 = [&](auto &&dfs, ll from, ll par) -> void {
            dp[from] = 1;
            each(to, g[from]) {
                if (to == par) continue;
                dfs(dfs, to, from);
                dp[from] += dp[to];
            }
        };
        dfs2(dfs2, r, -1);
        vc<ll> vis(n);
        ll gra = r;
        vis[gra] = 1;
        while (true) {
            bool ok = true;
            for (auto to : g[gra]) {
                if (vis[to]) continue;
                if (dp[to] * 2 > rem) {
                    gra = to;
                    ok = false;
                    vis[gra] = 1;
                    break;
                }
            }
            if (ok) break;
        }
        if (g[gra].size() == 1) {
            ll u = g[gra][0], v = gra;
            cout << "? " << v + 1 << " " << u + 1 << endl;
            ll x;
            cin >> x;
            if (x == 0)
                cout << "! " << v + 1 << endl;
            else
                cout << "! " << u + 1 << endl;
            return;
        }
        vc<pair<ll, ll>> ord;
        for (auto to : g[gra]) {
            if (dp[to] < dp[gra])
                ord.push_back({dp[to], to});
            else
                ord.push_back({rem - dp[gra], to});
        }
        sort(ord.rbegin(), ord.rend());
        ll u = ord[0].second, v = ord[1].second;
        cout << "? " << v + 1 << " " << u + 1 << endl;
        ll x;
        cin >> x;
        if (x == 0) {
            r = v;
            vc<ll> era;
            for (auto to : g[v]) {
                if (to == gra) era.push_back(to);
                if (to == u) era.push_back(to);
            }
            sort(all(era));
            era.erase(unique(all(era)), era.end());
            for (auto e : era) g[v].erase(find(all(g[v]), e));
        } else if (x == 1) {
            r = gra;
            vc<ll> era;
            for (auto to : g[gra]) {
                if (to == u) era.push_back(to);
                if (to == v) era.push_back(to);
            }
            sort(all(era));
            era.erase(unique(all(era)), era.end());
            for (auto e : era) g[gra].erase(find(all(g[gra]), e));
        } else {
            r = u;
            vc<ll> era;
            for (auto to : g[u]) {
                if (to == gra) era.push_back(to);
                if (to == v) era.push_back(to);
            }
            sort(all(era));
            era.erase(unique(all(era)), era.end());
            for (auto e : era) g[u].erase(find(all(g[u]), e));
        }
    }
    cout << "! " << r + 1 << endl;
}

詳細信息

Test #1:

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

input:

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

output:

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

result:

ok OK (2 test cases)

Test #2:

score: 0
Accepted
time: 89ms
memory: 4472kb

input:

5555
8
2 0
8 6
0 0
3 0
0 0
7 0
0 0
5 4
2
2
2
8
0 0
1 4
2 0
0 0
7 8
0 0
3 0
6 0
2
2
2
8
5 8
0 0
1 7
0 0
0 0
4 2
0 0
6 0
2
1
0
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
2
0
5
3 0
5 1
0 0
0 0
4 0
2
2
5
5 0
0 0
0 0
3 0
2 4
1
2
3
3 0
1 0
0 0
2
2
2 0
0 0
2
3
2 3
0 0
0 0
0
10
2 8
9 7
0 0
...

output:

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

result:

ok OK (5555 test cases)

Test #3:

score: 0
Accepted
time: 39ms
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:

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

result:

ok OK (600 test cases)

Test #4:

score: 0
Accepted
time: 196ms
memory: 14160kb

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:

? 43991 70790
? 46637 98261
? 58487 69452
? 15987 33433
? 55639 60027
? 18078 68543
? 87667 23768
? 24325 72504
? 18643 86991
? 60341 70725
? 1601 77039
? 43507 1569
? 42318 83285
? 14683 96786
? 42250 65590
? 65590 70790
! 70790
? 85780 5676
? 57748 39704
? 42043 58489
? 50842 30188
? 24131 36012
?...

result:

ok OK (2 test cases)

Test #5:

score: 0
Accepted
time: 81ms
memory: 9232kb

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
? 2 5
! 5
? 6 9
? 3 7
? 3 6
! 3
? 13 29
? 17 18
? 1 24
? 1 17
! 17
? 8 37
? 10 24
? 12 57
? 4 46
? 46 57
! 34
? 36 89
? 96 110
? 20 79
? 62 106
? 82 86
? 61 82
! 82
? 64 233
? 51 148
? 19 31
? 7 56
? 10 217
? 144 195
? 56 144
! 56
? 48 439
? 437 468
? 3 274
? 277 285
? 125 377
? 104 ...

result:

ok OK (15 test cases)

Test #6:

score: 0
Accepted
time: 101ms
memory: 9112kb

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:

? 1 2
! 2
? 4 3
? 3 2
! 2
? 1 4
? 4 6
? 6 7
! 7
? 1 11
? 10 6
? 6 7
? 7 12
! 7
? 13 16
? 19 29
? 5 7
? 7 27
? 27 8
! 27
? 24 8
? 20 6
? 10 13
? 32 25
? 25 7
? 7 29
! 7
? 113 80
? 115 16
? 112 63
? 50 25
? 89 81
? 81 11
? 11 114
! 114
? 3 106
? 72 82
? 224 78
? 105 13
? 156 44
? 54 184
? 184 212
? 21...

result:

ok OK (16 test cases)

Test #7:

score: 0
Accepted
time: 73ms
memory: 9228kb

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:

? 1 2
! 2
? 2 5
? 5 6
! 6
? 9 4
? 7 10
? 4 7
! 5
? 20 27
? 2 13
? 17 18
? 2 17
! 17
? 30 33
? 4 32
? 11 31
? 19 59
? 11 59
! 37
? 9 94
? 59 69
? 17 52
? 44 111
? 13 125
? 111 125
! 111
? 100 12
? 71 118
? 62 146
? 36 61
? 48 247
? 155 179
? 146 179
! 179
? 449 68
? 190 319
? 141 239
? 50 73
? 331 49...

result:

ok OK (15 test cases)

Test #8:

score: 0
Accepted
time: 41ms
memory: 3684kb

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
1
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:

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

result:

ok OK (600 test cases)

Test #9:

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

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
? 41708 88632
? 40612 63141
? 24579 54568
? 8545 83751
? 58468 97010
? 27367 63737
? 41106 75498
? 75918 88129
? 21204 62215
? 21024 45669
? 65796 79889
? 6771 73169
! 73169
? 78976 72481
? 84675 96633
? 2124 81852
? 13836 79494
? 24965 80643
? 74893 78402
?...

result:

ok OK (2 test cases)

Test #10:

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

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
? 2 7
? 1 5
! 5
? 5 15
? 6 8
? 10 11
! 10
? 17 29
? 6 25
? 15 31
? 10 23
! 23
? 1 2
? 48 53
? 23 28
? 8 34
? 21 49
! 34
? 20 115
? 68 71
? 21 73
? 26 61
? 36 119
? 12 23
! 23
? 70 140
? 78 250
? 4 223
? 35 207
? 170 189
? 50 137
? 69 160
! 69
? 60 121
? 74 414
? 249 474
? 97 321
? 119 279
...

result:

ok OK (15 test cases)

Test #11:

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

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
1
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
2
2
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:

? 1 2
! 2
? 2 4
? 4 3
! 3
? 1 8
? 6 8
? 7 4
! 4
? 15 16
? 12 6
? 10 8
? 8 13
! 8
? 2 19
? 15 3
? 18 25
? 27 13
? 13 30
! 13
? 14 9
? 24 58
? 32 29
? 3 17
? 39 15
? 15 57
! 15
? 83 28
? 21 75
? 7 10
? 30 38
? 64 111
? 11 113
! 113
? 218 221
? 199 243
? 92 202
? 2 233
? 87 208
? 84 140
? 46 236
! 236
...

result:

ok OK (16 test cases)

Test #12:

score: 0
Accepted
time: 68ms
memory: 8336kb

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
0
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
0
0
2
62
0 0
0 0
28 47
7 38
0 0
0 0
17 26...

output:

? 1 2
! 2
? 6 2
? 2 3
! 3
? 6 14
? 3 4
? 5 11
! 3
? 2 28
? 23 26
? 6 18
? 15 20
! 20
? 43 61
? 30 18
? 31 50
? 10 51
? 42 44
! 44
? 44 18
? 53 93
? 45 75
? 58 106
? 74 91
? 25 87
! 91
? 196 253
? 42 224
? 31 178
? 6 58
? 14 64
? 57 160
? 7 105
! 105
? 32 69
? 172 210
? 19 233
? 188 349
? 94 198
? 18...

result:

ok OK (15 test cases)

Test #13:

score: 0
Accepted
time: 42ms
memory: 3924kb

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
0
2
7
0 0
0 0
2 4
5 6
0 0
0 0
1 3
2
2
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
2
2
2
10
3 5
10 7
0 0
0 0
6 2
0 0
4 0
9 1
0 0
0 0
2
2
0
11
9 6
4 1
0 0
0 0
11 ...

output:

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

result:

ok OK (600 test cases)

Test #14:

score: 0
Accepted
time: 141ms
memory: 13548kb

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:

? 96970 71188
? 6820 87538
? 32876 59029
? 20365 46360
? 9490 49372
? 97012 17131
? 47373 63260
? 14744 92007
? 36878 67467
? 18815 97207
? 43042 6457
? 88506 91433
? 74629 74686
? 38322 85169
? 85169 92007
? 92007 24256
! 92007
? 86513 70265
? 36225 11800
? 25987 99536
? 63730 59217
? 29352 84543
?...

result:

ok OK (2 test cases)

Test #15:

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

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
2
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
2
2
1
63
51 35
33 57
...

output:

? 1 3
! 2
? 5 2
? 1 7
! 7
? 4 15
? 15 1
? 2 11
! 2
? 1 14
? 18 10
? 10 29
? 13 30
! 29
? 44 38
? 1 42
? 9 2
? 2 34
? 5 23
! 23
? 31 51
? 62 96
? 8 100
? 89 52
? 52 82
? 57 70
! 70
? 122 124
? 102 162
? 231 84
? 135 110
? 223 147
? 147 236
? 80 201
! 236
? 266 322
? 414 146
? 335 72
? 306 66
? 76 89
...

result:

ok OK (15 test cases)

Test #16:

score: 0
Accepted
time: 63ms
memory: 9292kb

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
0
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:

? 1 2
! 2
? 1 3
? 3 4
! 4
? 7 5
? 8 6
? 6 2
! 6
? 4 8
? 8 16
? 6 9
? 9 3
! 9
? 17 11
? 2 7
? 7 9
? 22 27
? 27 20
! 27
? 10 31
? 60 6
? 22 45
? 45 26
? 4 14
? 14 64
! 14
? 37 24
? 56 55
? 25 61
? 10 115
? 115 85
? 27 120
? 120 21
! 21
? 89 60
? 208 248
? 99 203
? 222 234
? 210 108
? 108 173
? 42 131
...

result:

ok OK (16 test cases)

Test #17:

score: 0
Accepted
time: 69ms
memory: 9436kb

input:

15
2
0 0
1 0
2
6
0 0
5 0
1 2
0 0
0 0
4 3
2
0
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
2
0
0
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
2
0
2
62
0 0
34 33
0 0
0 0
0 0
37 45
0 0
...

output:

? 1 2
! 2
? 2 6
? 6 4
! 6
? 11 14
? 7 14
? 7 10
! 7
? 8 20
? 1 9
? 9 27
? 9 24
! 24
? 42 59
? 12 31
? 19 40
? 12 40
? 40 47
! 47
? 17 40
? 69 77
? 25 84
? 59 90
? 25 90
? 25 31
! 31
? 90 189
? 158 221
? 132 198
? 62 251
? 127 170
? 170 189
? 170 186
! 170
? 60 192
? 29 303
? 190 312
? 241 495
? 35 4...

result:

ok OK (15 test cases)

Test #18:

score: 0
Accepted
time: 122ms
memory: 11292kb

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
? 91694 11494
? 73088 90037
? 21572 90037
? 91442 51091
? 93596 7067
? 14316 75096
? 55875 75096
? 96805 42793
? 42793 59747
? 472 67072
? 59747 64770
! 92650
? 36933 80592
? 68004 50906
? 65219 73367
? 33796 20489
? 19704 74041
? 74041 35779
? 85560 35779
?...

result:

ok OK (2 test cases)

Test #19:

score: 0
Accepted
time: 298ms
memory: 3828kb

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:

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

result:

ok OK (100000 test cases)

Extra Test:

score: 0
Extra Test Passed