ll的问题
查看原帖
ll的问题
313340
nifeng楼主2020/11/18 01:53

为什么开ll会wa第八个点,数据下载下来运行没有问题哇

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <queue>
#include <cstring>
#define debug(x) cout<<#x<<":"<<x<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
const int INF = 0x3f3f3f3f;
const int N = 35;
ll f[N][N]; 

void init(){
    for(int i = 1;i < N;i++){
        f[i - 1][0] = 1;
        for(int j = 1;j <= i;j++)
            f[i][j] = f[i -1][j - 1] + f[i - 1][j];
    }
}

ll sum(int l,int k) {
	ll ans = 0;
	for(int i = l;(i << 1) >= l + k;--i){
		ans += f[l][i];
	}
	return ans;
}

ll solve(ll x){
    vector<int> nums;
    while(x) nums.push_back(x % 2),x /= 2;
    ll res = 0;
    for(int i = 1;i < nums.size();i++) res += sum(i - 1,1);
    int top = 1;
    for(int i = nums.size() - 2;i >= 0;i--){
        if(nums[i]){
            res += sum(i,top - 1);
            top++;
        }
        else top--;
    }
    if(top <= 0) res++;
    return res;
}

int main(){
    ll x,y;
    init();
    scanf("%lld%lld",&x,&y);
    printf("%lld\n",solve(y) - solve(x - 1));
    return 0;
}

/**
*  ┏┓   ┏┓+ +
* ┏┛┻━━━┛┻┓ + +
* ┃       ┃
* ┃   ━   ┃ ++ + + +
*  ████━████+
*  ◥██◤ ◥██◤ +
* ┃   ┻   ┃
* ┃       ┃ + +
* ┗━┓   ┏━┛
*   ┃   ┃ + + + +Code is far away from  
*   ┃   ┃ + bug with the animal protecting
*   ┃    ┗━━━┓ 神兽保佑,代码无bug 
*   ┃        ┣┓
*    ┃        ┏┛
*     ┗┓┓┏━┳┓┏┛ + + + +
*    ┃┫┫ ┃┫┫
*    ┗┻┛ ┗┻┛+ + + +
*/


2020/11/18 01:53
加载中...