QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#620240 | #8939. Permutation | zzpcd# | WA | 285ms | 11464kb | C++20 | 1.7kb | 2024-10-07 17:07:33 | 2024-10-07 17:07:42 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int n;
const double k = 0.629;
int ask(int l, int r) {
if(l == r) return -1;
cout << "? " << l << ' ' << r << endl;
int x;
cin >> x;
return x;
}
void answer(int x) {
cout << "! " << x << endl;
return;
}
int f[1000001],deg[1000001];
void solve(int l, int r, int sec = -1) {
if(l == r) {
answer(l);
return;
}
if(sec == -1) sec = ask(l, r);
if(l + 1 == r) {
answer(l == sec ? r : l);
return;
}
int mid = deg[r-l+1];
if(l + mid - 1 >= sec) {
mid = l + mid - 1;
int u = ask(l, mid);
if(u == sec) {
return solve(l, mid, sec);
} else return solve(mid + 1, r, -1);
} else {
mid = r - mid + 1;
int u = ask(mid, r);
if(u == sec) {
return solve(mid, r, sec);
} else return solve(l, mid - 1, -1);
}
}
void init()
{
memset(f,0x3f,sizeof(f));
f[1]=0;
f[2]=0,deg[2]=1;
for(int i=3;i<=1000000;++i)
{
if(i<=1000)
for(int j=i/2;j<=i;++j)
{
if(f[i]>max(f[j],f[i-j]+1)+1)
{
f[i]=max(f[j],f[i-j]+1)+1;
deg[i]=j;
}
}
else
{
for(int j=i*k-100;j<=i*k+100;++j)
{
if(f[i]>max(f[j],f[i-j]+1)+1)
{
f[i]=max(f[j],f[i-j]+1)+1;
deg[i]=j;
}
}
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T;
cin >> T;
init();
while(T--) {
int n;
cin >> n;
solve(1, n);
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 197ms
memory: 11464kb
input:
3 5 3 2 5 6 6 3 1 4 3 3
output:
? 1 5 ? 1 3 ? 4 5 ! 4 ? 1 6 ? 3 6 ? 1 2 ! 2 ? 1 4 ? 3 4 ! 4
result:
ok Correct (3 test cases)
Test #2:
score: 0
Accepted
time: 285ms
memory: 11404kb
input:
10000 10 2 2 2 1 3 10 10 10 7 5 10 5 1 10 9 8 10 4 4 4 4 10 10 6 3 4 2 10 3 3 3 4 2 10 1 5 9 10 7 10 1 3 8 8 10 2 4 9 9 10 3 3 3 3 10 4 1 7 8 9 10 8 7 1 2 4 10 4 1 9 9 10 7 7 7 8 6 10 5 1 7 8 10 10 8 8 6 9 10 2 2 1 5 10 6 4 10 10 10 1 3 8 8 10 7 9 4 4 10 7 8 4 4 10 3 4 7 8 10 10 4 4 1 6 10 8 7 4 3 2...
output:
? 1 10 ? 1 6 ? 1 4 ? 1 2 ? 3 4 ! 4 ? 1 10 ? 5 10 ? 7 10 ? 5 6 ! 6 ? 1 10 ? 1 6 ? 7 10 ? 9 10 ? 7 8 ! 7 ? 1 10 ? 1 6 ? 1 4 ? 3 4 ! 3 ? 1 10 ? 5 10 ? 1 4 ? 3 4 ? 1 2 ! 1 ? 1 10 ? 1 6 ? 1 4 ? 3 4 ? 1 2 ! 1 ? 1 10 ? 1 6 ? 7 10 ? 9 10 ? 7 8 ! 8 ? 1 10 ? 1 6 ? 7 10 ? 7 8 ! 7 ? 1 10 ? 1 6 ? 7 10 ? 9 10 ! 1...
result:
ok Correct (10000 test cases)
Test #3:
score: -100
Wrong Answer
time: 209ms
memory: 11404kb
input:
10000 3 1 2 11 5 3 8 8 9 7 2 2 19 3 4 13 13 13 12 11 7 5 7 1 2 4 3 3 1 19 6 6 7 1 2 4 2 2 15 11 11 11 11 10 14 1 1 1 2 3 16 4 4 4 1 5 3 3 2 19 13 17 5 5 5 6 4 2 2 4 1 2 3 7 2 2 2 3 2 2 17 1 1 2 8 7 6 14 9 9 9 9 20 9 3 18 17 13 14 11 6 4 2 5 18 7 7 7 5 9 8 8 6 3 3 8 6 7 1 2 3 16 10 10 10 10 10 6 1 1 ...
output:
? 1 3 ? 2 3 ! 3 ? 1 11 ? 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