QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#858168 | #8939. Permutation | oXUo | TL | 0ms | 3712kb | C++14 | 1019b | 2025-01-16 14:38:46 | 2025-01-16 14:39:53 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,ll>
#define fi first
#define in inline
#define se second
#define mp make_pair
#define pb push_back
const int N = 2e5+10;
ll read(){
ll x = 0,f = 1;char c = getchar();
for(;c < '0' || c > '9';c = getchar())if(c == '-')f = -1;
for(;c >= '0' && c <= '9';c = getchar())x = (x<<1) + (x<<3) + c-'0';
return x * f;
}
int n;
int ask(int l,int r){
if(l == r)return 0;
printf("? %d %d\n",l,r);
cout.flush();
int x = read();
return x;
}
void solve(){
n = read();
int p = ask(1,n);
int l = 1,r = n;
while(l < r){
int mid = l + ((double)r - l) * (1 - 0.618);
if(p <= mid){
int x = ask(l,mid);
if(x == p)r = mid;
else l = mid + 1,p = ask(mid + 1,r);
}
else{
int x = ask(mid + 1,r);
if(x == p)l = mid + 1;
else r = mid,p = ask(l,mid);
}
}
printf("! %d\n",l);
cout.flush();
}
int main(){
int t = read();
while(t--)solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3712kb
input:
3 5 3 3 5 6 6 3 1 4 3 3
output:
? 1 5 ? 3 5 ? 4 5 ! 4 ? 1 6 ? 3 6 ? 1 2 ! 2 ? 1 4 ? 3 4 ! 4
result:
ok Correct (3 test cases)
Test #2:
score: -100
Time Limit Exceeded
input:
10000 10 2 2 1 3 10 10 10 7 5 10 5 5 6 10 9
output:
? 1 10 ? 1 4 ? 1 2 ? 3 4 ! 4 ? 1 10 ? 5 10 ? 7 10 ? 5 6 ! 6 ? 1 10 ? 5 10 ? 5 6 ? 7 10 ? 9 10 ? 7 8