結果
| 問題 | No.3444 Interval Xor MST |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-02-06 22:15:15 |
| 言語 | C++14 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 41 ms / 2,000 ms |
| コード長 | 854 bytes |
| 記録 | |
| コンパイル時間 | 753 ms |
| コンパイル使用メモリ | 75,276 KB |
| 実行使用メモリ | 7,848 KB |
| 最終ジャッジ日時 | 2026-02-06 22:15:18 |
| 合計ジャッジ時間 | 2,574 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 7 |
ソースコード
#include<iostream>
#include<cassert>
using namespace std;
long solve(long l,long r,int k)
{
long ret=0;
for(;--k>=0;)
{
if(l<=r)break;
const long mid=1LL<<k;
assert(0<=r&&r<l&&l<mid*2);
if(r<mid)
{
if(mid<=l)
{
ret+=mid;
l-=mid;
}
}
else
{
l-=mid;
r-=mid;
}
}
return ret;
long msk=(1LL<<k)-1;
//long ret=1e18;
for(long a=l;a<=msk;a++)for(long b=0;b<=r;b++)ret=min(ret,a^b);
return ret;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T;cin>>T;
for(;T--;)
{
long N,M;cin>>N>>M;
long L=M,R=M+N-1;
long cnt=0;
long ans=0;
for(int k=31;k>=0;k--)
{
long l=L>>k,r=R>>k;
if(l<r)
{
if(cnt==0)
{
assert(l+1==r);
const long msk=(1LL<<k)-1;
ans+=solve(L&msk,R&msk,k);
}
ans+=(1LL<<k)*(r-l-cnt);
cnt=r-l;
}
}
cout<<ans<<"\n";
}
}