QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#564087 | #8939. Permutation | ucup-team3691 | WA | 8ms | 3680kb | C++14 | 3.7kb | 2024-09-14 19:46:46 | 2024-09-14 19:46:47 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using namespace chrono;
using ll = long long;
using ull = unsigned long long;
string to_string(const string &s) {
return '"' + s + '"';
}
string to_string(bool b) {
return b ? "true" : "false";
}
template <typename A, typename B>
string to_string(const pair<A, B> &p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename T>
string to_string(const T &v) {
string s = "{";
bool first = true;
for (const auto &it : v) {
if (!first)
s += ", ";
else
first = false;
s += to_string(it);
}
return s += "}";
}
void debug_out() {
cerr << endl;
}
template <typename T, typename... Args>
void debug_out(const T &first, const Args&... rest) {
cerr << to_string(first) << " ";
debug_out(rest...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
auto startTime = high_resolution_clock::now();
int get_time() {
auto stopTime = chrono::high_resolution_clock::now();
auto duration = duration_cast<milliseconds>(stopTime - startTime);
return duration.count(); // in ms
}
int nq, sum_len;
vector<int> v;
int query(int l, int r) {
if (r - l == 0) {
return l;
}
if (v.empty()) {
cout << "? " << l << " " << r << endl;
int x;
cin >> x;
return x;
}
--l; --r;
++nq;
sum_len += r - l + 1;
vector<pair<int, int>> v2;
for (int i = l; i <= r; ++i) {
v2.push_back({v[i], i});
}
sort(v2.rbegin(), v2.rend());
return v2[1].second + 1;
}
void solve_for_n(int n) {
vector<ll> fib(60, 0);
fib[0] = 1;
fib[1] = 1;
for (int i = 2; i < 60; ++i) {
fib[i] = fib[i - 1] + fib[i - 2];
}
int x, y;
int l = 1, r = n;
x = query(l, r);
while (r - l > 2) {
int len = r - l + 1;
int z;
for (int i = 1; i < 60; ++i) {
if (fib[i] >= r - l + 1) {
z = fib[i - 1];
break;
}
}
int mid = l + z - 1;
if (x > mid) {
mid = r - z + 1;
}
if (x <= mid) {
y = query(l, mid);
} else {
y = query(mid + 1, r);
}
if (x != y) {
if (x <= mid) {
x = query(mid + 1, r);
l = mid + 1;
} else {
x = query(l, mid);
r = mid;
}
} else {
if (x <= mid) {
r = mid;
} else {
l = mid + 1;
}
}
}
if (r - l == 0) {
cout << "! " << l << endl;
} else if (r - l == 1) {
cout << "! " << (r + l) - x << endl;
} else if (r - l == 2) {
int oth = l + 1;
if (x == oth) {
oth = l;
}
y = query(min(oth, x), max(x, oth));
if (x == y) {
cout << "! " << oth << endl;
} else {
cout << "! " << (l + l + 1 + l + 2) - x - oth << endl;
}
}
}
void solve() {
int n;
cin >> n;
solve_for_n(n);
}
void gen() {
int nr = 0, bad = 0;
while (1) {
++nr;
int n = 2 + rng() % 30;
int lim_q = ceil(1.5 * log2(n));
int lim_len = 3 * n;
v.clear();
nq = 0;
sum_len = 0;
for (int i = 1; i <= n; ++i) {
v.push_back(i);
}
shuffle(v.begin(), v.end(), rng);
solve_for_n(n);
if (nq > lim_q || lim_len < sum_len) {
++bad;
debug(nr, bad);
debug(n, nq, lim_q);
debug(nq - lim_q, -lim_len + sum_len);
}
}
}
int main() {
cin.tie(NULL);
ios_base::sync_with_stdio(false);
//solve_for_n(200);
//return 0;
//gen();
//return 0;
int t = 1;
cin >> t;
while (t--)
solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3628kb
input:
3 5 3 2 5 6 6 3 1 4 3 2
output:
? 1 5 ? 1 3 ? 4 5 ! 4 ? 1 6 ? 3 6 ? 1 2 ! 2 ? 1 4 ? 1 3 ! 4
result:
ok Correct (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 8ms
memory: 3680kb
input:
10000 10 2 2 2 3 5 10 10 10 7 5 4 10 5 5 1 6 6 10 4 4 4 5 2
output:
? 1 10 ? 1 8 ? 1 5 ? 1 3 ? 4 5 ! 4 ? 1 10 ? 4 10 ? 7 10 ? 4 6 ? 4 5 ! 6 ? 1 10 ? 1 8 ? 1 5 ? 6 8 ? 6 7 ! 7 ? 1 10 ? 1 8 ? 1 5 ? 4 5 ? 1 3 ? 1 2
result:
wrong answer Too many queries , n = 10 , now_q 6 (test case 4)