在手写bitset的过程中遇到了一些问题。
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ull;
const int W=64;
ull w[105];
inline ull gsub(int l,int r){
if(l/W==r/W) {
int z=r-l+1; cout<<((1ull<<z)-1)<<"sd\n";
return (w[l/W]>>(l%W)) & ((1ull<<z)-1);
}
else {
int x=(l/W+1)*W;
return gsub(l,x-1)|(gsub(x,r)<<(x-l));
}
}
int main(){
gsub(0,63);
return 0;
}
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ull;
const int W=64;
ull w[105];
inline ull gsub(int l,int r){
if(l/W==r/W) {
int z=r-l+1; cout<<((1ull<<z)-1)<<"sd\n";
return (w[l/W]>>(l%W)) & ((1ull<<z)-1);
}
else {
// int x=(l/W+1)*W;
// return gsub(l,x-1)|(gsub(x,r)<<(x-l));
} return 0;
}
int main(){
gsub(0,63);
return 0;
}
为什么以上两个代码一个输出正确答案 263−1,一个输出 0。