QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#541789 | #8939. Permutation | ucup-team3877# | WA | 0ms | 3584kb | C++20 | 3.1kb | 2024-08-31 20:57:38 | 2024-08-31 20:57:40 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(),(v).end()
#define pb(a) push_back(a)
#define rep(i, n) for(int i=0;i<n;i++)
#define foa(e, v) for(auto& e : v)
using ll = long long;
const ll MOD7 = 1000000007, MOD998 = 998244353, INF = (1LL << 60);
#define dout(a) cout<<fixed<<setprecision(10)<<a<<endl;
void ques(ll a, ll b) {
cout << "? " << a + 1 << " " << b << endl;
}
void Out(ll n) {
cout << "! " << n << endl;
}
void solve() {
ll n; cin >> n;
// if(n <= 14) {
// int ans = 0;
// int a;
// for(int i = 1; i <= n; i ++) {
// cout << "? " << i << endl;
// cin >> a;
// ans = max(ans, a);
// }
// cout << "! " << ans << endl;
// return;
// }
// vector<int> a(n + 2, -1);
vector<int> f(40, 0);
f[1] = 1;
for(int i = 2; i <= 29; i ++) f[i] = f[i - 1] + f[i - 2];
ll le = 0, id = 25;
ll x;
ques(0, n);
cin >> x;
if(n == 2) {
Out(3 ^ x);
return;
}
x --;
for(int i = 0; i <= 20; i ++) {
if(f[i] == 1597) {
id = i;
break;
}
}
while(f[id] >= 2) {
ll mid2 = le + f[id - 1];
while(id >= 2 and n + 1 <= mid2) {
id --;
mid2 = le + f[id - 1];
}
if(f[id] <= 1) break;
ll mid1 = le + f[id - 2];
ll y;
if(x < mid2) {
ques(le, mid2);
cin >> y;
y --;
if(x == y) {
if(le == mid2 - 2) {
if(le == y) Out(le + 2);
else Out(le + 1);
return;
}
id --;
} else {
ll ri = min(n, le + f[id]);
ques(mid2, ri);
cin >> x;
x --;
if(ri - mid2 == 2) {
if(mid2 == x) Out(mid2 + 2);
else Out(mid2 + 1);
return;
}
le = mid2;
id -= 2;
}
} else {
ll ri = min(n, le + f[id]);
ques(mid1, ri);
ll y;
cin >> y;
y --;
if(x == y) {
if(mid1 == ri - 2) {
if(mid1 == y) Out(mid1 + 2);
else Out(mid1 + 1);
return;
}
id --;
le = mid1;
} else {
id --;
ques(le, mid1);
cin >> x;
x --;
if(mid1 - le == 2) {
if(le == x) Out(le + 2);
else Out(le + 1);
return;
}
id -= 2;
}
}
}
// cout << le << " " << le + f[id] << endl;
// Out();
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int t;
cin >> t;
while(t --) solve();
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3584kb
input:
3 5 3 3 2 5 6 6 5 3
output:
? 1 5 ? 1 5 ? 1 3 ? 4 5 ! 4 ? 1 6 ? 4 6 ? 1 3 ? 2 2
result:
wrong answer Integer 2 violates the range [3, 6] (test case 2)