Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
43252 Liyiyang1123 【J】T2 C++ 编译错误 0 0 MS 0 KB 1123 2026-10-28 13:57:45

Tests(0/0):


#include <bits/stdc++.h> #define int long long using namespace std; int t,n,x,cnt,ans; signed main(){ // freopen("xor.in","r",stdin); // freopen("xor.out","w",stdout); ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>t; while(t--){ cin>>n>>x,ans=((x>>1)<<1),cnt=__popcount(x); if(n==1){ cout<<x<<"\n"; continue; } if(x&1){ --cnt; if(n&1){ ans+=n; if(cnt&1) --cnt; ans-=cnt; } else{ if(cnt==0) ans+=2; ans+=n-1; if(cnt&1) --cnt; else cnt-=2; ans-=cnt; } } else{ if(n&1){ ans+=n-1; if(cnt&1) --cnt; else cnt-=2; ans-=cnt; } else{ ans+=n; if(cnt&1) --cnt; ans-=cnt; } } cout<<ans<<"\n"; } return 0; }


测评信息: