蒟蒻求助位运算
  • 板块学术版
  • 楼主Shui_Dream
  • 当前回复7
  • 已保存回复7
  • 发布时间2024/1/3 22:07
  • 上次更新2024/1/4 14:18:32
查看原帖
蒟蒻求助位运算
104487
Shui_Dream楼主2024/1/3 22:07

在手写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−12^{63}-1,一个输出 00。

2024/1/3 22:07
加载中...