-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmedian_sort.java
54 lines (53 loc) · 1.84 KB
/
median_sort.java
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
import java.io.*;
import java.util.*;
public class Solution{
static int T, N, Q;
static BufferedReader eat;
static PrintWriter moo;
static int qry(int a, int b, int c) throws IOException{
moo.println(a + " " + b + " " + c);
moo.flush();
int res = Integer.parseInt(eat.readLine());
return res;
}
public static void main(String args[]) throws IOException{
eat = new BufferedReader(new InputStreamReader(System.in));
moo = new PrintWriter(System.out);
StringTokenizer st = new StringTokenizer(eat.readLine());
T = Integer.parseInt(st.nextToken());
N = Integer.parseInt(st.nextToken());
Q = Integer.parseInt(st.nextToken());
for(int tc = 1; tc <= T; tc++){
ArrayList<Integer> ord = new ArrayList<Integer>();
ord.add(1); ord.add(2);
for(int i = 3; i <= N; i++){
int lo = -1, hi = ord.size();
while(lo + 1 < hi){
int m1 = Math.max(0, lo + (hi - lo) / 3);
int m2 = Math.min(ord.size()-1, hi - (hi - lo + 2) / 3);
if(m1 == m2) m2++;
int x = qry(ord.get(m1), ord.get(m2), i);
if(x == ord.get(m1)){
hi = m1;
}
if(x == ord.get(m2)){
lo = m2;
}
if(x == i){
hi = m2;
lo = m1;
}
}
ord.add(lo+1, i);
}
for(int i : ord){
moo.print(i + " ");
}
moo.println();
moo.flush();
int status = Integer.parseInt(eat.readLine());
assert status != -1;
}
eat.close(); moo.close();
}
}