-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathD1.java
More file actions
109 lines (87 loc) · 2.71 KB
/
Copy pathD1.java
File metadata and controls
109 lines (87 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import java.io.*;
import java.util.*;
public class D1 {
static FastScanner sc;
static PrintWriter out;
static int query(int mid, int[] extra) {
int k = mid + extra.length;
out.print("? " + k);
for (int i = 1; i <= mid; i++)
out.print(" " + i);
for (int x : extra)
out.print(" " + x);
out.println();
out.flush();
int res = sc.nextInt();
if (res == -1) {
System.exit(0);
}
return res;
}
public static void main(String[] args) {
sc = new FastScanner();
out = new PrintWriter(System.out);
int t = sc.nextInt();
if (t == -1) return;
while (t-- > 0) {
int n = sc.nextInt();
if (n == -1) break;
int N = 2 * n + 1;
int lo = 1, hi = N;
while (lo < hi) {
int mid = (lo + hi) / 2;
int ans = query(mid, new int[]{});
if ((ans & 1) != (mid & 1))
hi = mid;
else
lo = mid + 1;
}
int p3 = lo;
lo = 1;
hi = p3 - 1;
while (lo < hi) {
int mid = (lo + hi) / 2;
int ans = query(mid, new int[]{p3});
if ((ans & 1) == (mid & 1))
hi = mid;
else
lo = mid + 1;
}
int p2 = lo;
lo = 1;
hi = p2 - 1;
while (lo < hi) {
int mid = (lo + hi) / 2;
int ans = query(mid, new int[]{p2, p3});
if ((ans & 1) != (mid & 1))
hi = mid;
else
lo = mid + 1;
}
int p1 = lo;
out.println("! " + p1 + " " + p2 + " " + p3);
out.flush();
}
}
static class FastScanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
String next() {
while (!st.hasMoreTokens()) {
try {
String line = br.readLine();
if (line == null) return null;
st = new StringTokenizer(line);
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
String s = next();
if (s == null) return -1;
return Integer.parseInt(s);
}
}
}