結果
問題 | No.2977 Kth Xor Pair |
ユーザー |
![]() |
提出日時 | 2024-12-01 19:08:26 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 731 ms / 3,000 ms |
コード長 | 1,959 bytes |
コンパイル時間 | 3,412 ms |
コンパイル使用メモリ | 285,628 KB |
実行使用メモリ | 10,580 KB |
最終ジャッジ日時 | 2024-12-01 19:08:38 |
合計ジャッジ時間 | 11,166 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 34 |
ソースコード
#include<bits/stdc++.h>namespace {#pragma GCC diagnostic ignored "-Wunused-function"#include<atcoder/all>#pragma GCC diagnostic warning "-Wunused-function"using namespace std;using namespace atcoder;#define rep(i,n) for(int i = 0; i < (int)(n); i++)#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)#define all(x) begin(x), end(x)#define rall(x) rbegin(x), rend(x)template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; }using ll = long long;using P = pair<int,int>;using VI = vector<int>;using VVI = vector<VI>;using VL = vector<ll>;using VVL = vector<VL>;} int main() {ios::sync_with_stdio(false);cin.tie(0);int n;ll k;cin >> n >> k;VI a(n);rep(i, n) cin >> a[i];sort(all(a));k = 2 * k + n;int ans = 0;struct S {int l1, r1, l2, r2;};vector<S> d{S{0, n, 0, n}}, nd;rrep(i, 30) {auto get_mid = [&](int l, int r) -> int {assert(l < r);return ranges::lower_bound(a, a[l] >> i | 1, {}, [&](int x) { return x >> i; }) - a.begin();};ll cnt = 0;for (auto [l1, r1, l2, r2] : d) {int c1 = get_mid(l1, r1), c2 = get_mid(l2, r2);cnt += ll(c1 - l1) * (c2 - l2) + ll(r1 - c1) * (r2 - c2);}nd.clear();if (cnt >= k) {for (auto [l1, r1, l2, r2] : d) {int c1 = get_mid(l1, r1), c2 = get_mid(l2, r2);if (l1 < c1 && l2 < c2) nd.emplace_back(l1, c1, l2, c2);if (c1 < r1 && c2 < r2) nd.emplace_back(c1, r1, c2, r2);}} else{ans |= 1 << i;k -= cnt;for (auto [l1, r1, l2, r2] : d) {int c1 = get_mid(l1, r1), c2 = get_mid(l2, r2);if (l1 < c1 && c2 < r2) nd.emplace_back(l1, c1, c2, r2);if (c1 < r1 && l2 < c2) nd.emplace_back(c1, r1, l2, c2);}}swap(d, nd);}cout << ans << '\n';}