QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#620308 | #8939. Permutation | zzpcd# | WA | 544ms | 23176kb | C++20 | 2.2kb | 2024-10-07 17:26:52 | 2024-10-07 17:26:54 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define P make_pair
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;
}
pair<int,ll> f[1000001];
int 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()
{
int mx=0;
memset(f,0x3f,sizeof(f));
f[1]=P(0,0);
f[2]=P(0,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(P(f[j].first+1,f[j].second+j),P(f[i-j].first+2,f[i-j].second+i)))
{
f[i]=max(P(f[j].first+1,f[j].second+j),P(f[i-j].first+2,f[i-j].second+i));
deg[i]=j;
}
}
else
{
for(int j=i*k-100;j<=i*k+100;++j)
if(f[i]>max(P(f[j].first+1,f[j].second+j),P(f[i-j].first+2,f[i-j].second+i)))
{
f[i]=max(P(f[j].first+1,f[j].second+j),P(f[i-j].first+2,f[i-j].second+i));
deg[i]=j;
}
}
// if(f[i].first+1>ceil(1.5*log2(i))||f[i].second>2*i)
// {
// cout<<i<<" "<<ceill((long double)1.5*log2l(i))<<" "<<f[i].first+1<<" "<<f[i].second<<endl;
// exit(0);
// }
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T;
cin >> T;
init();
while(T--) {
int n;
cin >> n;
solve(1, n);
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 440ms
memory: 23176kb
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: 544ms
memory: 23112kb
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: 446ms
memory: 23108kb
input:
10000 3 1 2 11 5 5 5 5 2 2 19 3 3 4 11 11 9 7 5 7 1 2 3 3 1 19 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