From e347e372da74017c9dbfd9bb3d7b03a188377e93 Mon Sep 17 00:00:00 2001 From: hanyixuanten <105723997+hanyixuanten@users.noreply.github.com> Date: Sat, 15 Aug 2026 16:59:01 +0800 Subject: [PATCH] new file: P10451.cpp --- P10451.cpp | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 P10451.cpp diff --git a/P10451.cpp b/P10451.cpp new file mode 100644 index 0000000..34d8702 --- /dev/null +++ b/P10451.cpp @@ -0,0 +1,69 @@ +// 113 +#include +using namespace std; +// --- down for luogu --- +bool compare(int a, int b) +{ + cout << "? " << a << ' ' << b << endl; + bool t; + cin >> t; + return t; +} +// --- up for luogu --- +class Solution +{ +public: + vector tmp, a; + int tot = 0; + void ms(int l, int r) + { + if (l == r) + return; + int mid = l + r >> 1; + ms(l, mid); + ms(mid + 1, r); + int i = l, j = mid + 1, tot = l; + while (i <= mid && j <= r) + if (compare(a[i], a[j])) + tmp[tot++] = a[i++]; + else + tmp[tot++] = a[j++]; + while (i <= mid) + tmp[tot++] = a[i++]; + while (j <= r) + tmp[tot++] = a[j++]; + for (int k = l; k <= r; ++k) + a[k] = tmp[k]; + } + vector specialSort(int N) + { + a.resize(1005); + tmp.resize(1005); + for (int i = 1; i <= N; ++i) + { + a[i] = i; + } + ms(1, N); + vector res(N); + for (int i = 0; i < N; ++i) + { + res[i] = a[i + 1]; + } + return res; + } +}; +// --- down for luogu --- +int main() +{ + int n; + scanf("%d", &n); + Solution k; + vector ans = k.specialSort(n); + printf("! "); + for (int i = 0; i < n; ++i) + { + printf("%d ", ans[i]); + } + return 0; +} +// --- up for luogu --- \ No newline at end of file