题意: 给一个数组,让你找到 a [ i ] < m i n ( a [ i + 1 ] , a [ i − 1 ] ) a[i]<min(a[i+1],a[i-1]) a[i]<min(a[i+1],a[i−1])位置 i i i,每次询问 i i i可以得到 a [ i ] a[i] a[i],最多询问100次,且 a [ 0 ] = a [ n + 1 ] = + ∞ a[0]=a[n+1]=+∞ a[0]=a[n+1]=+∞。
我们考虑假设我们知道了
a
[
i
]
a[i]
a[i]和
a
[
i
+
1
]
a[i+1]
a[i+1],如果
a
[
i
]
<
a
[
i
+
1
]
a[i]<a[i+1]
a[i]<a[i+1],那么左边一定存在答案,否则右边一定存在答案,按照这个性质二分就好啦。
可以看下面的图理解一下,画出来了
a
[
i
]
<
a
[
i
+
1
]
a[i]<a[i+1]
a[i]<a[i+1]的情况,可以发现两个点连起来延伸的话,因为左边有个边界挡着,所以一定会出现一个
v
v
v字型的图案,
v
v
v字型图案的拐角处就是答案啦。
//#pragma GCC optimize(2)
#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<map>
#include<cmath>
#include<cctype>
#include<vector>
#include<set>
#include<queue>
#include<algorithm>
#include<sstream>
#include<ctime>
#include<cstdlib>
#define X first
#define Y second
#define L (u<<1)
#define R (u<<1|1)
#define pb push_back
#define mk make_pair
#define Mid (tr[u].l+tr[u].r>>1)
#define Len(u) (tr[u].r-tr[u].l+1)
#define random(a,b) ((a)+rand()%((b)-(a)+1))
#define db puts("---")
using namespace std;
//void rd_cre() { freopen("d://dp//data.txt","w",stdout); srand(time(NULL)); }
//void rd_ac() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//AC.txt","w",stdout); }
//void rd_wa() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//WA.txt","w",stdout); }
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
const int N=1000010,mod=1e9+7,INF=0x3f3f3f3f;
const double eps=1e-6;
int n;
int ans;
int query(int x)
{
printf("? %d\n",x); fflush(stdout);
int val; scanf("%d",&val);
return val;
}
int main()
{
// ios::sync_with_stdio(false);
// cin.tie(0);
scanf("%d",&n);
int l=1,r=n;
while(l<r)
{
int mid=l+r>>1;
int a=query(mid),b=query(mid+1);
if(a<b) r=mid;
else l=mid+1;
}
printf("! %d\n",l);
return 0;
}
/*
*/