結果
| 問題 |
No.2977 Kth Xor Pair
|
| コンテスト | |
| ユーザー |
vjudge1
|
| 提出日時 | 2025-02-14 18:56:40 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,429 bytes |
| コンパイル時間 | 2,073 ms |
| コンパイル使用メモリ | 191,484 KB |
| 実行使用メモリ | 72,728 KB |
| 最終ジャッジ日時 | 2025-02-14 18:57:58 |
| 合計ジャッジ時間 | 77,756 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 20 TLE * 14 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:82:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
82 | scanf("%d%lld",&n,&k);
| ~~~~~^~~~~~~~~~~~~~~~
main.cpp:83:32: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
83 | for(i=1;i<=n;i++) scanf("%d",&a[i]);
| ~~~~~^~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX=2e5+10;
struct Trie
{
#define type ll
static const int LOG=33;
static const int K=LOG+2;
int rt,root[MAX],tot,ch[MAX*K][2],cnt[MAX*K];
Trie &operator[](const int _rt){this->rt=_rt;return *this;}
int newnode()
{
tot++;
memset(ch[tot],0,sizeof ch[tot]);
cnt[tot]=0;
return tot;
}
void init(int n=1)
{
ch[0][0]=ch[0][1]=cnt[0]=0;
tot=1;
for(int i=0;i<=n;i++) root[i]=0;
rt=1;
}
void insert(type x)
{
int id,t,i;
if(!root[rt]) root[rt]=newnode();
id=root[rt];
for(i=LOG;~i;i--)
{
cnt[id]++;
t=(x>>i)&1;
if(!ch[id][t]) ch[id][t]=newnode();
id=ch[id][t];
}
cnt[id]++;
}
type count_y(type x,type limt) // count y: x xor y <= limt
{
int id,i;
type res,t;
if(!root[rt]) return 0;
id=root[rt];
res=0;
for(i=LOG;~i;i--)
{
t=(x>>i)&1;
if((limt>>i)&1)
{
res+=cnt[ch[id][t]];
id=ch[id][t^1];
}
else id=ch[id][t];
}
res+=cnt[id];
return res;
}
#undef type
}tr;
int a[MAX],n;
ll k;
int ck(ll x)
{
int i;
ll res;
tr.init();
res=0;
for(i=1;i<=n;i++)
{
res+=tr.count_y(a[i],x);
if(res>=k) return 1;
tr.insert(a[i]);
}
return res>=k;
}
int main()
{
int i;
ll l,r,mid;
scanf("%d%lld",&n,&k);
for(i=1;i<=n;i++) scanf("%d",&a[i]);
l=0;
r=2e9;
while(l<r)
{
mid=(l+r)>>1;
if(ck(mid)) r=mid;
else l=mid+1;
}
printf("%lld\n",l);
return 0;
}
vjudge1