QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#607495 | #8939. Permutation | UESTC_Snow_Halation# | TL | 0ms | 0kb | C++14 | 2.8kb | 2024-10-03 15:03:52 | 2024-10-03 15:03:53 |
Judging History
answer
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#define FOR() ll le=e[u].size();for(ll i=0;i<le;i++)
#define QWQ cout<<"QwQ\n";
#define ll long long
#include <vector>
#include <queue>
#include <map>
using namespace std;
const ll N=1201010;
const ll qwq=303030;
const ll inf=0x3f3f3f3f;
inline ll read() {
ll sum = 0, ff = 1; char c = getchar();
while(c<'0' || c>'9') { if(c=='-') ff = -1; c = getchar(); }
while(c>='0'&&c<='9') { sum = sum * 10 + c - '0'; c = getchar(); }
return sum * ff;
}
int T,n;
int f[N],fen[N];
int ans;
int cnt = 0;
void ask(int l,int r) {
cnt++;
if(cnt>(ll)ceil((double)(1.5*log2(n)))) cout<<cnt/0;
cout<<"? "<<l<<" "<<r<<"\n";
fflush(stdout);
}
void DFS(int cl,int wei,int l,int r) {
int len = r-l+1;
if(len<=1) { cout<<wei/0; }
if(len==2) {
ask(l,r);
int xia = read();
if(xia==l) ans = r;
else ans = l;
return ;
}
if(cl==0) {
ask(l,r);
wei = read();
}
if(len==3) {
if(wei==l) {
ask(l,l+1);
int xia = read();
if(xia==l) ans = l+1;
else ans = r;
}
else if(wei==l+1) {
ask(l,l+1);
int xia = read();
if(xia==l) ans = r;
else ans = l;
}
else {
ask(l+1,r);
int xia = read();
if(xia==r) ans = l+1;
else ans = l;
}
return ;
}
int mid = l+fen[len]-1;
if(wei<=mid) {
ask(l,mid);
int xia = read();
if(xia==wei) DFS(1,wei,l,mid);
else DFS(0,0,mid+1,r);
}
else {
mid = r-fen[len]+1;
ask(mid,r);
int xia = read();
if(xia==wei) DFS(1,wei,mid,r);
else DFS(0,0,l,mid-1);
}
}
int main() {
f[1] = inf;
f[2] = 1; fen[2] = 1;
f[3] = 1; fen[3] = 1;
f[4] = 2; fen[4] = 2;
f[5] = 3; fen[5] = 3;
for(int i=6;i<=3000;i++) {
f[i] = inf;
int mid = (i+1)/2;
for(int j=mid;j<=i-2;j++) {
int need = max(f[j]+1,f[i-j]+1+1);
if(need <= f[i]) f[i] = need, fen[i] = j;
}
if(i<=1000) cout<<i<<" f = "<<f[i]<<" fen = "<<fen[i]<<"\n";
if(f[i]>(ll)ceil((double)(1.5*log2(i)))) while(1) {i++;}
}
for(int i=3001;i<=N-10;i++) fen[i] = i*2/3;
T = read();
while(T--) {
n = read();
cnt = 0;
DFS(0,0,1,n);
cout<<"! "<<ans<<"\n";
fflush(stdout);
}
return 0;
}
/*
3
2 3
1 2
2 2
4 5 100
5
1 1
2 2
2 5
3 5
3 3
3 5
1 2 3 4 5
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Time Limit Exceeded
input:
3 5
output:
6 f = 3 fen = 4 7 f = 3 fen = 4 8 f = 4 fen = 6 9 f = 4 fen = 7 10 f = 4 fen = 7 11 f = 4 fen = 7 12 f = 5 fen = 10 13 f = 5 fen = 11 14 f = 5 fen = 11 15 f = 5 fen = 11 16 f = 5 fen = 11 17 f = 5 fen = 11 18 f = 5 fen = 11 19 f = 6 fen = 17 20 f = 6 fen = 18 21 f = 6 fen = 18 22 f = 6 fen = 18 23 f...