QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#563872 | #8939. Permutation | ucup-team3691# | WA | 1ms | 3584kb | C++14 | 2.6kb | 2024-09-14 16:34:39 | 2024-09-14 16:34:40 |
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
}
void solve() {
int n;
cin >> n;
int x, y;
int l = 1, r = n;
cout << "? " << l << " " << r << endl;
cin >> x;
while (r - l > 2) {
int mid = l + 2 * (r - l) / 3;
if (x > mid) {
mid = r - 2 * (r - l) / 3 - 1;
}
if (x <= mid) {
cout << "? " << l << " " << mid << endl;
} else {
cout << "? " << mid + 1 << " " << r << endl;
}
cin >> y;
if (x != y) {
if (x <= mid) {
cout << "? " << mid + 1 << " " << r << endl;
l = mid + 1;
} else {
cout << "? " << l << " " << mid << endl;
r = mid;
}
cin >> x;
} 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;
}
cout << "? " << min(oth, x) << " " << max(x, oth) << endl;
cin >> y;
if (x == y) {
cout << "! " << oth << endl;
} else {
cout << "! " << (l + l + 1 + l + 2) - x - oth << endl;
}
}
}
int main() {
cin.tie(NULL);
ios_base::sync_with_stdio(false);
int t = 1;
cin >> t;
while (t--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3584kb
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 4
result:
wrong answer Integer 4 violates the range [1, 3] (test case 3)