This is an interactive problem.
We picked an array of whole numbers a1,a2,…,ana1,a2,…,an (0≤ai≤1090≤ai≤109) and concealed exactly one zero in it! Your goal is to find the location of this zero, that is, to find ii such that ai=0ai=0.
You are allowed to make several queries to guess the answer. For each query, you can think up three distinct indices i,j,ki,j,k, and we will tell you the value of max(ai,aj,ak)−min(ai,aj,ak)max(ai,aj,ak)−min(ai,aj,ak). In other words, we will tell you the difference between the maximum and the minimum number among aiai, ajaj and akak.
You are allowed to make no more than 2⋅n−22⋅n−2 queries, and after that you have two tries to guess where the zero is. That is, you have to tell us two numbers ii and jj and you win if ai=0ai=0 or aj=0aj=0.
Can you guess where we hid the zero?
Note that the array in each test case is fixed beforehand and will not change during the game. In other words, the interactor is not adaptive.
Input
Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤5001≤t≤500). Description of the test cases follows.
The first and only line of each test case contains an integer nn (4≤n≤10004≤n≤1000) — the length of the array that we picked.
It is guaranteed that the sum of nn over all test cases does not exceed 30003000.
Interaction
For each test case, the interaction starts with reading nn.
To make a query, print "? ii jj kk" (without quotes, 1≤i,j,k≤n1≤i,j,k≤n, indices must be distinct). Then you should read our response from standard input, that is, max(ai,aj,ak)−min(ai,aj,ak)max(ai,aj,ak)−min(ai,aj,ak).
If the response is −1−1, it means your program has made an invalid query or has run out of tries. Your program must terminate immediately after reading −1−1, and you will get a verdict Wrong answer. Otherwise you may get any verdict, because the program will continue reading from the closed stream. Note that if the query is correct, the answer will never be −1−1 because max(ai,aj,ak)−min(ai,aj,ak)≥0max(ai,aj,ak)−min(ai,aj,ak)≥0.
To give the final answer, print "! ii jj" (without the quotes). Printing the same number twice (that is, i=ji=j) is allowed. Note that giving this answer is not counted towards the limit of 2⋅n−22⋅n−2 queries. After that, your program must continue to solve the remaining test cases, or exit if all test cases have been solved.
After printing a query, don't forget to output line feed and flush the output buffer. Otherwise you will get the verdict Idleness limit exceeded. To flush the buffer, use:
- fflush(stdout) or cout.flush() in C++;
- System.out.flush() in Java;
- flush(output) in Pascal;
- stdout.flush() in Python;
- Read documentation for other languages.
Hacks
The first line must contain an integer tt (1≤t≤5001≤t≤500) — the count of test cases.
The first line of each test case must contain an integer nn (4≤n≤10004≤n≤1000) — the length of the hidden array.
The second line of each test case must contain nn integers separated by spaces — a1,a2,…,ana1,a2,…,an (0≤ai≤1090≤ai≤109). There must also be exactly one zero in this array.
The sum of nn over all test cases must not exceed 30003000.
Example
input
Copy
1 4 2 3 3 2
output
Copy
? 1 2 3 ? 2 3 4 ? 3 4 1 ? 4 1 2 ! 2 3
Note
Array from sample: [1,2,0,3][1,2,0,3].
思路:这个题让你问2n-2次,那么这个题就一定与交互次数有关,1:可以是从1开始一个一个询问一遍,找出特殊点(特殊点相当一下全找出来),再用特殊点再将数组全循环一遍,得到每个值。 2:先循环一遍找一个特殊的,再循环一遍找第二个特殊的(单个找特殊点)。因为该题返回的是max-min,所以与最大与最小有关,所以用第二种方法,先循环一遍找最大的,再用最大的找差值最大的是最小的那个数。边界是最大最小为前两个数。
交互题的类型:1.二分
2.分组(块)
3.二进制
4.与交互次数有关
比较大小赋值:带不带等号与我是否想改变原来的数(值)有关,观察不改变是否有影响。
完整代码:
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
//#define int long long
#define fir first
#define sec second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)x.size()
#define rep(i, l, r) for (int i = l; i <= r; ++i)
#define repd(i, l, r) for (int i = l; i >= r; --i)
#define pb push_back
//#define mint modint<(int)1e9 + 7>
#define defop(type, op) \
inline friend type operator op (type u, const type& v) { return u op ##= v; } \
type& operator op##=(const type& o)
template<int mod>
struct modint {
int x;
// note that there is no correction, simply for speed
modint(int xx = 0): x(xx) {}
modint(ll xx): x(int(xx % mod)) {}
defop(modint, +) {
if ((x += o.x) >= mod) x -= mod;
return *this;
}
defop(modint, -) {
if ((x -= o.x) < 0) x += mod;
return *this;
}
defop(modint, * ) { return *this = modint(1ll * x * o.x); }
modint pow(ll exp) const {
modint ans = 1, base = *this;
for (; exp > 0; exp >>= 1, base *= base)
if (exp & 1) ans *= base;
return ans;
}
defop(modint, /) { return *this *= o.pow(mod - 2); }
};
//using mint = modint<(int)1e9 + 7>;
typedef modint<(int)1e9 + 7> mint;
const int N=3100;
int query(int i,int j,int k)
{
if(i==j||i==k||j==k)return 0;
cout<<"? "<<i<<" "<<j<<" "<<k<<endl;
int x;
cin>>x;
return x;
}
void ans(int l,int r)
{
if(r<l)swap(l,r);
cout<<"! "<<l<<" "<<r<<endl;
}
int n,pos1=1,pos2=2,pos3=3,opt=-1;
void solve()
{
cin>>n;
pos1=1,pos2=2,pos3=3,opt=-1;
rep(i,3,n)
{
int val=query(pos1,pos2,i);
if(val>opt)//带等号也可以
{
opt=val;
pos3=i;
}
}
rep(i,2,n)
{
if(i==pos3)continue;
int val=query(pos1,pos3,i);
if(val>=opt)//带不带等号与我是否想改变原来的数(值)有关
{
opt=val;
pos2=i;
}
}
int un=1;
rep(i,1,n)
{
if(i!=pos1&&i!=pos2&&i!=pos3)
{
un=i;
break;
}
}
if(query(un,pos2,pos3)==opt)ans(pos2,pos3);
else if(query(un,pos1,pos3)==opt)ans(pos1,pos3);
else ans(pos1,pos2);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin>>t;
while(t--)
{
solve();
}
return 0;
}