满足 \(\operatorname{popcount}(x)<3\) 的数实际上很少,直接把所有这些数扔到 set
里面,询问就返回 set
中 \(x\) 的下一个元素即可。记得开 long long
。set
内的元素数量是 \(\log^2w\),所以复杂度是 \(\mathcal O(\log^2w\log\log^2w+T\log\log^2 w)=\mathcal O(\log^2w\log\log w+T\log\log w)\),足矣通过本题。
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<set>
using std::cin;using std::cout;
using lolu=unsigned long long;
std::set<lolu>s;
signed main(){
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
std::ios::sync_with_stdio(false);cin.tie(nullptr);
for(int i=0;i<=63;i++)for(int j=0;j<=63;j++)s.insert((1ull<<i)|(1ull<<j));
int T;cin>>T;for(lolu x;T--;){
cin>>x;
if(__builtin_popcountll(x)>=3)cout<<"No,Commander\n";
else cout<<*next(s.find(x))<<'\n';
}
return 0;
}
标签:std,2w,R1,题解,long,set,ZSHOI,include,log
From: https://www.cnblogs.com/bxjz/p/P9451.html