QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#627592 | #6303. Inversion | MCdyc | WA | 82ms | 7516kb | C++23 | 1.6kb | 2024-10-10 16:24:45 | 2024-10-10 16:24:47 |
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 (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) {
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
{
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() + l, 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;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3540kb
input:
3 0 0 1
output:
? 1 2 ? 1 3 ? 2 3 ! 2 3 1
result:
ok OK, guesses=3
Test #2:
score: -100
Wrong Answer
time: 82ms
memory: 7516kb
input:
1993 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 1 0 1 0 1 0 0 0 1 1 1 1 1 0 1 1 1 1 1 1 0 1 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 1 0 1 0 1 1 0 0 1 1 1 1 1 0 1 0 0 0 1 1 0 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 0 1 0 0 0 1 1 0 1 1 1 1 1 1 0 0 1 0 0 0 0 0 1 0 0 1 1 1 1 0 0 0 0 1 0 0 1...
output:
? 1 2 ? 1 3 ? 2 3 ? 2 4 ? 3 4 ? 2 5 ? 3 5 ? 1 5 ? 1 4 ? 2 6 ? 3 6 ? 5 6 ? 1 6 ? 1 7 ? 2 7 ? 5 7 ? 6 7 ? 1 8 ? 2 8 ? 3 8 ? 4 7 ? 4 8 ? 3 7 ? 1 9 ? 2 9 ? 8 9 ? 3 9 ? 9 10 ? 5 10 ? 6 9 ? 6 10 ? 5 9 ? 7 10 ? 8 10 ? 7 9 ? 1 11 ? 2 10 ? 2 11 ? 1 10 ? 8 11 ? 9 11 ? 10 11 ? 11 12 ? 8 12 ? 9 12 ? 10 12 ? 2 1...
result:
wrong output format Unexpected end of file - int32 expected