結果
問題 | No.2977 Kth Xor Pair |
ユーザー |
👑 |
提出日時 | 2024-12-01 01:44:35 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 536 ms / 3,000 ms |
コード長 | 1,058 bytes |
コンパイル時間 | 1,248 ms |
コンパイル使用メモリ | 114,200 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-12-01 01:44:51 |
合計ジャッジ時間 | 14,811 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 34 |
ソースコード
#include <iostream>#include <vector>#include <algorithm>#include <cmath>using namespace std;// A の中で l 以上 r 以下の要素の個数を数える関数int count(const vector<int>& A, int l, int r) {auto right = upper_bound(A.begin(), A.end(), r);auto left = lower_bound(A.begin(), A.end(), l);return right - left;}int main() {int N;long long K;cin >> N >> K;vector<int> A(N);for (int i = 0; i < N; i++) {cin >> A[i];}sort(A.begin(), A.end()); // ソートlong long ans = 0;long long X = 2 * K + N;for (int i = 30; i >= 0; --i) {long long left = ans;long long right = ans | ((1LL << i) - 1);long long cnt = 0;for (int a : A) {long long l = left ^ (a & ~((1LL << i) - 1));long long r = right ^ (a & ~((1LL << i) - 1));cnt += count(A, l, r);}if (cnt < X) {ans |= 1LL << i;X -= cnt;}}cout << ans << endl;return 0;}