QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#728274#9570. Binary Treeucup-team159#AC ✓778ms15884kbC++235.0kb2024-11-09 14:53:302024-11-09 14:53:31

Judging History

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

  • [2024-11-09 14:53:31]
  • 评测
  • 测评结果:AC
  • 用时:778ms
  • 内存:15884kb
  • [2024-11-09 14:53:30]
  • 提交

answer

#line 1 "G.cpp"
// #pragma GCC target("avx2,avx512f,avx512vl,avx512bw,avx512dq,avx512cd,avx512vbmi,avx512vbmi2,avx512vpopcntdq,avx512bitalg,bmi,bmi2,lzcnt,popcnt")
// #pragma GCC optimize("Ofast")

#line 2 "/home/sigma/comp/library/template.hpp"

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using uint = unsigned int;
using ull = unsigned long long;
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<=int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define all(c) c.begin(),c.end()
#define si(x) int(x.size())
#define pb push_back
#define eb emplace_back
#define fs first
#define sc second
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
template<class T,class U> bool chmax(T& x, U y){
	if(x<y){ x=y; return true; }
	return false;
}
template<class T,class U> bool chmin(T& x, U y){
	if(y<x){ x=y; return true; }
	return false;
}
template<class T> void mkuni(V<T>& v){sort(all(v));v.erase(unique(all(v)),v.end());}
template<class T> int lwb(const V<T>& v, const T& a){return lower_bound(all(v),a) - v.begin();}
template<class T>
V<T> Vec(size_t a) {
    return V<T>(a);
}
template<class T, class... Ts>
auto Vec(size_t a, Ts... ts) {
  return V<decltype(Vec<T>(ts...))>(a, Vec<T>(ts...));
}
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
void dmpr(ostream& os){os<<endl;}
template<class T,class... Args>
void dmpr(ostream&os,const T&t,const Args&... args){
	os<<t<<" ~ ";
	dmpr(os,args...);
}
#define shows(...) cerr << "LINE" << __LINE__ << " : ";dmpr(cerr,##__VA_ARGS__)
#define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {";  \
	for(auto v: x) cerr << v << ","; cerr << "}" << endl;
#else
#define show(x) void(0)
#define dump(x) void(0)
#define shows(...) void(0)
#endif

template<class D> D divFloor(D a, D b){
	return a / b - (((a ^ b) < 0 && a % b != 0) ? 1 : 0);
}
template<class D> D divCeil(D a, D b) {
	return a / b + (((a ^ b) > 0 && a % b != 0) ? 1 : 0);
}
#line 5 "G.cpp"
using P = pair<int,int>;

void answer(int v){
	cout << "! " << v+1 << endl;
}
int ask(int x, int y){
	cout << "? " << x+1 << " " << y+1 << endl;
	int t; cin >> t; return t;
}

void solve(){
	int N; cin >> N;	
	VV<int> G(N);
	rep(i,N){
		rep(_,2){
			int c; cin >> c; c--;
			if(c == -1) continue;
			G[i].pb(c); G[c].pb(i);
		}
	}
	auto get_dist = [&](int r) -> V<int> {
		V<int> dist(N);
		auto dfs = [&](auto self, int v, int p, int d) -> void {
			dist[v] = d;
			for(int u : G[v]) if(u != p){
				self(self,u,v,d+1);
			}
		};
		dfs(dfs,r,-1,0);
		return dist;
	};
	V<bool> on(N,true);
	while(true){
		int num_on = count(all(on),true);
		show(num_on);
		if(num_on == 1){
			answer(find(all(on),true)-on.begin());
			return;
		}
		V<int> sz(N);
		V<int> par(N);
		auto dfs = [&](auto self, int v, int p) -> void {
			par[v] = p;
			sz[v] = on[v] ? 1 : 0;
			for(int u : G[v]) if(u != p){
				self(self,u,v);
				sz[v] += sz[u];
			}
		};
		dfs(dfs,0,-1);
		rep(x,N) if(on[x]){
			for(auto y: G[x]) if(on[y] && y != par[x]){
				int Y = sz[y], X = num_on - Y;
				if(max(X,Y) <= num_on/2){
					int t = ask(x,y);
					assert(t != 1);
					auto d0 = get_dist(x);
					auto d1 = get_dist(y);
					rep(v,N) if(on[v]){
						if(t==0 && d0[v] > d1[v]) on[v] = false;
						if(t==2 && d0[v] < d1[v]) on[v] = false;
					}
					goto done;
				}
			}
		}
		rep(r,N) if(on[r]){
			for(auto x: G[r]) if(on[x] && x != par[r]){
				for(auto y: G[r]) if(on[y]){
					if(x == y) continue;
					if(y != par[r]){
						// r -> x,y
						int X = sz[x], Y = sz[y], R = num_on - X - Y;
						if(max({X,Y,R}) <= num_on/2){
							int t = ask(x,y);
							auto d0 = get_dist(x);
							auto d1 = get_dist(y);
							rep(v,N){
								bool valid = false;
								if(t == 0 && d0[v] < d1[v]) valid = true;
								if(t == 1 && d0[v] == d1[v]) valid = true;
								if(t == 2 && d0[v] > d1[v]) valid = true;
								on[v] = on[v] && valid;
							}
							goto done;
						}
					}else{
						// y -> r -> x
						int X = sz[x], R = sz[r] - X, Y = num_on - X - R;
						if(max({X,Y,R}) <= num_on/2){
							int t = ask(x,y);
							auto d0 = get_dist(x);
							auto d1 = get_dist(y);
							rep(v,N){
								bool valid = false;
								if(t == 0 && d0[v] < d1[v]) valid = true;
								if(t == 1 && d0[v] == d1[v]) valid = true;
								if(t == 2 && d0[v] > d1[v]) valid = true;
								on[v] = on[v] && valid;
							}
							goto done;
						}
					}
				}
			}
		}
		assert(false);
		done:;
	}
}

int main(){
	int T; cin >> T;
	while(T--) solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 163ms
memory: 4352kb

input:

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

output:

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

result:

ok OK (5555 test cases)

Test #3:

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

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

output:

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

result:

ok OK (600 test cases)

Test #4:

score: 0
Accepted
time: 778ms
memory: 15884kb

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
? 98261 46637
? 86742 20402
? 93018 13737
? 65869 183
? 78859 33708
? 37526 26633
? 17223 64102
? 19396 10221
? 92919 37873
? 53388 93563
? 30685 56704
? 33112 81259
? 96468 14500
? 40194 900
? 40194 14500
! 14500
? 44110 5676
? 22364 39704
? 94893 58489
? 59542 85216
? 58438 22200
? 7...

result:

ok OK (2 test cases)

Test #5:

score: 0
Accepted
time: 386ms
memory: 9896kb

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:

? 3 1
! 2
? 5 1
? 4 1
! 1
? 9 6
? 8 5
? 13 8
! 13
? 13 29
? 18 17
? 23 5
? 10 23
! 23
? 8 37
? 10 24
? 12 57
? 46 4
? 4 8
! 36
? 89 36
? 6 71
? 101 116
? 64 57
? 14 59
? 116 14
! 14
? 64 233
? 148 51
? 176 1
? 6 178
? 100 16
? 180 168
? 178 180
! 178
? 439 48
? 144 457
? 142 376
? 10 241
? 87 237
? ...

result:

ok OK (15 test cases)

Test #6:

score: 0
Accepted
time: 392ms
memory: 9776kb

input:

16
2
2 0
0 0
2
4
4 0
3 0
1 0
0 0
0
2
8
5 0
0 0
4 0
8 0
2 0
3 0
6 0
1 0
0
2
0
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
0
0
0
2
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
? 1 3
? 1 4
! 4
? 8 4
? 1 5
? 5 2
! 5
? 3 11
? 5 13
? 1 2
? 1 3
! 3
? 12 16
? 11 17
? 1 31
? 18 4
? 4 11
! 4
? 60 8
? 61 6
? 57 13
? 4 25
? 30 7
? 25 30
! 25
? 57 80
? 72 48
? 69 93
? 24 31
? 111 73
? 106 37
? 37 24
! 24
? 90 106
? 116 82
? 98 78
? 129 13
? 12 189
? 180 127
? 94 149
? 78 9...

result:

ok OK (16 test cases)

Test #7:

score: 0
Accepted
time: 388ms
memory: 10076kb

input:

15
2
2 0
0 0
2
6
5 0
1 0
6 0
2 0
3 0
0 0
0
1
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
0
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
0
2
0
2
62
24 0
22 0
18 0
17 0
49 0
53 0
3...

output:

? 1 2
! 2
? 1 5
? 4 1
! 2
? 14 4
? 10 7
? 2 10
! 2
? 21 27
? 8 5
? 19 12
? 5 19
! 19
? 60 33
? 4 32
? 11 31
? 55 5
? 5 4
! 4
? 70 94
? 90 37
? 58 56
? 29 116
? 124 117
? 116 124
! 124
? 159 12
? 118 71
? 62 146
? 36 61
? 177 229
? 138 199
? 229 138
! 229
? 359 68
? 137 139
? 71 459
? 342 188
? 44 38...

result:

ok OK (15 test cases)

Test #8:

score: 0
Accepted
time: 111ms
memory: 3752kb

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
0
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
0
2
7
3 7
0 0
0 0
2 5
0 0
1 4
0 0
0
2
8
0 0
3 7
1 0
2 5
6 8
0 0
0 0
0 0
2
1
0
9
9 8
0 0
7 2
0 0
0 0
0 0
0 0
4 5
3 6
2
1
2
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
? 3 2
! 2
? 1 4
? 1 3
! 3
? 4 2
? 3 5
! 3
? 1 2
? 3 5
! 5
? 4 1
? 2 5
! 5
? 2 4
? 6 4
? 5 8
! 5
? 3 1
? 4 1
? 8 5
! 5
? 4 1
? 10 1
? 6 9
! 9
? 2 6
? 5 8
? 4 3
! 4
? 11 1
? 4 1
? 4 10
! 4
? 7 13
? 12 9
? 6 5
! 6
? 14 12
? 5 10
? 2 6
! 6
? 8 14
? 4 9
? 3 1
! 3
? 15 10
? 15 9
? 3 1
? 11 15
! ...

result:

ok OK (600 test cases)

Test #9:

score: 0
Accepted
time: 370ms
memory: 10636kb

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:

? 22163 69076
? 11838 89914
? 18079 15463
? 72017 29994
? 80147 27856
? 80763 26264
? 39876 84186
? 73287 34615
? 43462 43070
? 38721 85806
? 84940 93114
? 3443 79116
? 49016 68555
? 56289 87545
? 32426 3887
! 3887
? 78976 42261
? 84675 32955
? 81852 2124
? 64228 84822
? 19229 57178
? 58509 46889
? ...

result:

ok OK (2 test cases)

Test #10:

score: 0
Accepted
time: 205ms
memory: 7824kb

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:

? 3 2
! 1
? 2 7
? 5 1
! 1
? 5 15
? 8 6
? 3 7
! 3
? 29 17
? 13 30
? 12 7
? 16 2
! 2
? 2 1
? 40 57
? 6 44
? 32 52
? 4 47
! 52
? 20 115
? 71 68
? 67 3
? 18 16
? 123 55
? 117 104
! 104
? 70 140
? 250 78
? 99 222
? 162 154
? 253 38
? 156 108
? 167 39
! 167
? 60 121
? 414 74
? 99 184
? 301 403
? 425 477
?...

result:

ok OK (15 test cases)

Test #11:

score: 0
Accepted
time: 201ms
memory: 7744kb

input:

16
2
0 0
1 0
2
4
4 2
0 0
0 0
3 0
0
2
8
3 0
0 0
0 0
0 0
1 2
0 0
6 4
5 7
0
2
0
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
0
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:

? 1 2
! 2
? 1 4
? 1 2
! 2
? 5 8
? 1 5
? 5 2
! 5
? 1 16
? 5 1
? 4 2
? 15 14
! 15
? 32 19
? 22 21
? 23 14
? 6 9
! 9
? 37 9
? 9 58
? 46 9
? 61 27
? 59 44
! 44
? 92 28
? 75 21
? 10 7
? 30 38
? 111 64
? 65 51
! 65
? 245 221
? 199 243
? 66 123
? 247 165
? 94 171
? 160 129
? 103 231
! 103
? 39 81
? 324 39
...

result:

ok OK (16 test cases)

Test #12:

score: 0
Accepted
time: 202ms
memory: 7888kb

input:

15
2
0 0
1 0
2
6
6 4
1 5
0 0
0 0
3 0
0 0
0
1
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
0
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
0
0
2
0
62
0 0
0 0
28 47
7 38
0 0
0 0
17 26...

output:

? 1 2
! 2
? 1 2
? 6 4
! 1
? 12 14
? 3 4
? 5 11
! 5
? 17 28
? 5 13
? 14 30
? 27 22
! 27
? 16 61
? 18 30
? 31 50
? 3 32
? 28 47
! 47
? 125 18
? 53 93
? 51 69
? 122 21
? 43 98
? 55 16
! 43
? 241 253
? 193 112
? 124 88
? 254 99
? 91 200
? 206 25
? 215 1
! 1
? 284 69
? 30 32
? 98 159
? 43 40
? 307 387
? ...

result:

ok OK (15 test cases)

Test #13:

score: 0
Accepted
time: 111ms
memory: 3956kb

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

output:

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

result:

ok OK (600 test cases)

Test #14:

score: 0
Accepted
time: 502ms
memory: 13404kb

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
? 24680 87538
? 11855 13278
? 64417 35922
? 19381 58885
? 2264 12579
? 33592 76097
? 52143 37008
? 47951 17658
? 58138 34974
? 36037 22603
? 71693 25917
? 67812 39226
? 1240 46572
? 50009 67812
? 80341 42687
! 46572
? 50499 70265
? 30583 11800
? 64399 99536
? 59356 59217
? 29352 21877
...

result:

ok OK (2 test cases)

Test #15:

score: 0
Accepted
time: 280ms
memory: 8980kb

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

output:

? 3 1
! 2
? 6 2
? 7 1
! 1
? 4 15
? 13 1
? 9 3
! 9
? 12 14
? 31 6
? 6 1
? 24 22
! 22
? 15 38
? 48 42
? 43 20
? 20 1
? 51 35
! 35
? 34 51
? 33 108
? 124 30
? 75 102
? 76 15
? 114 40
! 40
? 83 124
? 22 162
? 230 84
? 112 110
? 51 147
? 3 236
? 190 200
! 190
? 266 322
? 386 146
? 81 102
? 473 135
? 263 ...

result:

ok OK (15 test cases)

Test #16:

score: 0
Accepted
time: 258ms
memory: 9180kb

input:

16
2
0 0
1 0
2
4
0 0
1 0
4 2
0 0
0
2
8
0 0
0 0
0 0
3 5
8 6
2 0
1 4
0 0
0
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
0
0
0
2
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
? 2 3
? 1 2
! 2
? 4 5
? 7 4
? 4 3
! 4
? 2 8
? 4 13
? 4 2
? 1 4
! 4
? 1 11
? 3 25
? 17 21
? 21 3
? 3 28
! 3
? 56 31
? 3 6
? 7 45
? 13 26
? 26 14
? 26 4
! 26
? 38 24
? 17 66
? 59 105
? 119 57
? 53 104
? 104 119
? 119 29
! 29
? 133 60
? 118 248
? 192 203
? 252 234
? 175 23
? 16 237
? 203 16
?...

result:

ok OK (16 test cases)

Test #17:

score: 0
Accepted
time: 269ms
memory: 9360kb

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
1
1
1
2
62
0 0
34 33
0 0
0 0
0 0
37 45
0 0
...

output:

? 1 2
! 2
? 2 1
? 4 3
! 3
? 8 14
? 12 11
? 3 6
! 13
? 7 8
? 10 26
? 16 15
? 23 18
! 18
? 48 42
? 55 12
? 20 43
? 6 58
? 46 10
! 58
? 40 41
? 69 108
? 20 54
? 38 80
? 74 19
? 122 120
! 80
? 59 90
? 158 221
? 225 198
? 93 32
? 4 49
? 242 240
? 50 203
! 50
? 60 468
? 352 44
? 36 489
? 443 63
? 245 295
...

result:

ok OK (15 test cases)

Test #18:

score: 0
Accepted
time: 500ms
memory: 10596kb

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 88409
? 16093 26122
? 11494 10853
? 37465 11494
? 73088 33972
? 21572 91343
? 51091 99968
? 37874 7067
? 75096 14316
? 11485 55875
? 42793 41734
? 59747 42793
? 472 67072
? 64770 59747
! 92650
? 80592 91773
? 68004 50906
? 65219 69818
? 33796 56485
? 61722 19704
? 56446 35779
? 85560 35779
?...

result:

ok OK (2 test cases)

Test #19:

score: 0
Accepted
time: 387ms
memory: 3608kb

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