牛客练习赛22C Bitset

牛客练习赛22C

一共有 n个数,第 i 个数是 x i 
x i 可以取 [l i , r i] 中任意的一个值。

,求 S 种类数。

感觉二进制真是一个神奇的东西。

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <string>
#include <bitset>

using namespace std;

bitset<1000090>a[2];

        //  a[i][j]表示累加完第i个数之后S为j是否可行,由于只涉及0和1所以考虑bitset优化瞎搞。

int main(){
            int n;
            scanf("%d", &n);
            a[0][0] = 1;
            int l,r;
            for(int i=1; i<=n; i++){
                scanf("%d%d", &l, &r);
                a[i%2].reset();
                for(int j=l; j<=r; j++){
                    a[i%2] |= a[(i%2)^1] << (j*j);
                }

            }
            printf("%lu\n",a[n%2].count());
            return 0;
}
View Code

猜你喜欢

转载自www.cnblogs.com/ckxkexing/p/9357194.html