結果

問題 No.2977 Kth Xor Pair
コンテスト
ユーザー hato336
提出日時 2024-12-01 13:10:17
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 708 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 298 ms
コンパイル使用メモリ 85,396 KB
実行使用メモリ 123,636 KB
最終ジャッジ日時 2026-05-24 14:26:00
合計ジャッジ時間 63,426 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 32 TLE * 2
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import collections,sys,math,functools,operator,itertools,bisect,heapq,decimal,string,time,random
n,k = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
ans = 0
k-=1
cnt = n*(n-1)//2 - k
def calc(x,i):
    z = 0
    for j in a:
        l = (((j ^ x)>>i) & ((1 << 30)-1)) << i
        r = l + (1 << i)

        p = bisect.bisect_left(a,l)
        q = bisect.bisect_left(a,r)
        z += q-p
        #print(x,i,j,l,r,p,q)
        if l <= j < r:
            z -= 1
    z//=2
    #print(x,i,z)
   
    return z
res = 0
for i in reversed(range(30)):
    r = calc(ans+(1<<i),i)
    if res + r >= cnt:
        ans += 1<<i
        cnt -= res
        res = 0
    else:
        res += r

print(ans)
0