-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathC_Max_Xor_Pair..cpp
106 lines (80 loc) · 1.69 KB
/
C_Max_Xor_Pair..cpp
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
#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define pf push_front
#define vi vector
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
using namespace std ;
const ll mod = 1e9 + 7 ;
const ll inf = 1e18;
const int p = 1e5+7;
void solve()
{
int n,a,b,c;
cin >> n;
if(n == 2){
cout << 2 << " " << 1 << endl;
return;
}
cout << 1 << " " << n-2 << " " << n-1 << endl;
cin >> a;
cout << 1 << " " << n-2 << " " << n << endl;
cin >> b;
cout << 1 << " " << n-1 << " " << n << endl;
cin >> c;
int max = a ^ b;
int m1 = max ^ c;
int m2 = m1 ^ a;
ll p = 1;
while(p <= max) p <<= 1;
p >>= 1;
if(!(m1 & p)){
cout << 2 << " " << n-1 << endl;
return;
}
if(!(m2 & p)){
cout << 2 << " " << n-2 << endl;
return;
}
if(n <= 4){
cout << 2 << " " << 1 << endl;
}
int l = 1;
int r = n-3;
int mid;
while(l<r){
mid = (l + r) >> 1;
cout << 1 << " " << mid << " " << n << endl;
cin >> a;
cout << 1 << " " << mid+1 << " " << n <<endl;
cin >> b;
if(!((a&p)^(b&p))){
l = mid+1;
}
else r = mid;
}
cout << 1 << " " << l << " " << l+1 << endl;
cin >> a;
if(l>1){
cout << 1 << " " << l-1 << " " << l << endl;
cin >> b;
}
if(l>1 && b>a)cout<<2<<" "<<l-1<<endl;
else cout<<2<<" "<<l<<endl;
}
int main()
{
ios_base::sync_with_stdio(false) ;
cin.tie(NULL);
cout.tie(NULL) ;
int t = 1 ;
cin >> t ;
while( t-- )
{
solve();
//cout<<"\n";
}
return 0 ;
}