結果
問題 | No.2085 Directed Complete Graph |
ユーザー |
![]() |
提出日時 | 2022-09-27 03:55:31 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 163 ms / 2,000 ms |
コード長 | 3,021 bytes |
コンパイル時間 | 4,304 ms |
コンパイル使用メモリ | 252,708 KB |
最終ジャッジ日時 | 2025-02-07 16:56:19 |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 15 |
ソースコード
#include <bits/extc++.h>int main() {using namespace std;unsigned long N;cin >> N;auto cmp{[](auto i, auto j) mutable -> bool {cout << "? " << i << " " << j << endl;unsigned long t;cin >> t;return t;}};// from "Improved Average Complexity for Comparison-Based Sorting"// Kazuo Iwama, Junichi Teruyama (2017)const auto one_two_insertion{[fill{[](unsigned long i){i |= i >> 1;i |= i >> 2;i |= i >> 4;i |= i >> 8;i |= i >> 16;i |= i >> 32;return i;}}](auto&& seq, auto&& cmp = std::less<>{}){const auto binary_search_insert{[&fill, &seq](unsigned long L, unsigned long R, unsigned long idx, auto&& cmp){const auto V{seq[idx]};rotate(begin(seq) + R, begin(seq) + idx, begin(seq) + idx + 1);idx = R++;while(L + 1 < R){unsigned long x{R - L - 1};unsigned long y{fill(x) + 1};unsigned long z{3 * y / 4};unsigned long M{L + (x < z ? y / 4 : x - y / 2 + 1)};(cmp(seq[M - 1], V) ? L : R) = M;}rotate(begin(seq) + L, begin(seq) + idx, begin(seq) + idx + 1);return L;}};const auto two_merge{[&seq, &binary_search_insert, alpha{[&fill](unsigned long x, unsigned long r){if(~r & 1)return x - (x >> (r / 2));const auto y{fill(x) + 1};if(3 * y < 4 * x)return x - (x >> (r / 2)) + (y >> (r / 2 + 2));return x - (x >> (r / 2 + 1)) - (y >> (r / 2 + 3));}}](unsigned long L, unsigned long R, unsigned long idx_0, unsigned long idx_1, auto&& cmp){if(cmp(seq[idx_1], seq[idx_0]))swap(idx_0, idx_1);const auto V{seq[idx_0]};unsigned long x{R - L};unsigned long l{~0UL}, r{alpha(x, 1)};unsigned long now{1};while(cmp(seq[L + r], V)){l = r;r = alpha(x, ++now);}unsigned long K{binary_search_insert(L + l + 1, L + r, idx_0, cmp)};if(idx_0 > idx_1)++idx_1;binary_search_insert(K, R + 1, idx_1, cmp);}};const auto N{size(seq)};if(N == 1)return;if(cmp(seq[1], seq[0]))swap(seq[0], seq[1]);if(N == 2)return;for(unsigned long i{2}; i + 1 < N; i += 2){if(2093258 * i >= 1142659 * (fill(i) + 1) && 4628523 * i >= 4139462 * (fill(i) + 1))two_merge(0, i, i, i + 1, cmp);else{binary_search_insert(0, i, i, cmp);binary_search_insert(0, i + 1, i + 1, cmp);}}if(N & 1)binary_search_insert(0, N - 1, N - 1, cmp);}};vector<unsigned long> A(N);iota(begin(A), end(A), 1);one_two_insertion(A, cmp);cout << "!" << endl;cout << N - 1 << endl;for(const auto a : A)cout << a << " ";cout << endl;return 0;}