QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#627548 | #6303. Inversion | TokaiZaopen# | WA | 87ms | 6176kb | C++23 | 2.3kb | 2024-10-10 16:16:55 | 2024-10-10 16:16:56 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
// #define int long long
map<pair<int, int>, int> mp;
int ask(int l, int r)
{
if (l == r)
{
return 0;
}
if (mp.count({l, r}))
{
return mp[{l, r}];
}
else
{
cout << "? " << l + 1 << " " << r + 1 << endl;
int x;
cin >> x;
return mp[{l, r}] = x;
}
}
int solve()
{
int n;
cin >> n;
vector<int> a;
auto cal = [&](int x, int y) {
if (x < y)
{
if (x == y - 1)
{
return ask(x, y) == 0;
}
else
{
return (((ask(x, y) + ask(x + 1, y - 1) - ask(x + 1, y) - ask(x, y - 1))) % 2 == 0);
}
}
else
{
swap(x, y);
if (x == y - 1)
{
return ask(x, y) != 0;
}
else
{
return (((ask(x, y) + ask(x + 1, y - 1) - ask(x + 1, y) - ask(x, y - 1))) % 2) != 0;
}
}
};
vector<int> b(n);
for (int i = 0; i < n; i++)
{
if (a.empty())
{
a.emplace_back(i);
}
else
{
if (cal(a.back(), i))
{
a.emplace_back(i);
}
else
{
int l = 0, r = a.size() - 1;
int ans = 0;
while (l <= r)
{
int mid = l + r >> 1;
if (cal(a[mid], i))
{
l = mid + 1;
}
else
{
ans = mid;
r = mid - 1;
}
}
a.insert(a.begin() + ans, i);
}
}
}
int cnt = 1;
cout << "! ";
for (int i = 0; i < n; i++)
{
b[a[i]] = cnt++;
}
for (int i = 0; i < n; i++)
{
cout << b[i] << " \n"[i == n - 1];
}
return 0;
}
signed main()
{
int test = 1;
while (test--)
{
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3552kb
input:
3 0 1 0
output:
? 1 2 ? 2 3 ? 1 3 ! 2 3 1
result:
ok OK, guesses=3
Test #2:
score: -100
Wrong Answer
time: 87ms
memory: 6176kb
input:
1993 0 0 0 1 1 0 0 0 0 0 0 0 0 0 1 0 0 1 1 0 0 0 1 0 0 0 1 0 1 1 1 1 1 1 0 1 1 1 1 0 1 1 0 1 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 0 0 1 0 0 1 1 1 1 1 0 1 1 0 0 0 0 1 1 0 1 1 1 1 0 1 0 1 0 0 0 0 0 1 0 1 0 0 1 1 0 0 0 0 1 1 1 1 1 1 1 0 0 0 1 1 0 0 1 1 1 1 1 1 1 0 0 1 0 0 0 0 0 0 0...
output:
? 1 2 ? 2 3 ? 3 4 ? 4 5 ? 2 5 ? 3 5 ? 2 4 ? 1 5 ? 1 4 ? 4 6 ? 5 6 ? 2 6 ? 3 6 ? 1 6 ? 4 7 ? 5 7 ? 1 7 ? 2 7 ? 6 7 ? 4 8 ? 5 8 ? 1 8 ? 2 8 ? 3 8 ? 3 7 ? 4 9 ? 5 9 ? 1 9 ? 2 9 ? 8 9 ? 3 9 ? 4 10 ? 5 10 ? 9 10 ? 6 9 ? 6 10 ? 7 10 ? 8 10 ? 7 9 ? 4 11 ? 5 11 ? 1 11 ? 2 10 ? 2 11 ? 1 10 ? 8 11 ? 9 11 ? 10...
result:
wrong output format Unexpected end of file - int32 expected