「LibreOJ β Round #2」贪心只能过样例

链接-----》bitset应用

 

/*
自己选择的路 ,跪着也要走完。朋友们 , 虽然这个世界日益浮躁起来,只
要能够为了当时纯粹的梦想和感动坚持努力下去 , 不管其它人怎么样,我
们也能够保持自己的本色走下去。
To the world , you will be a person , but to a person , you
will be the world .                               ——AKPower
*/
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <queue>
#include <cstdio>
#include <string>
#include <stack>
#include <set>
#include <bitset>
#define IOS ios::sync_with_stdio(false), cin.tie(0)
using namespace std;
typedef long long ll;
// 本题S最大是1e6
// 所以设置1e6个“位置”来标记每个数而不是二进制表示//这是理解的关键
bitset<1000005> ans, pre;

int main()
{
    IOS;
    pre = 1;
    ll n, a, b;
    cin >> n;
    for (ll i = 1; i <= n; i++)
    {
        cin >> a >> b;
        ans = 0;
        for (ll j = a; j <= b; j++)
        {
            // 前面所有前缀和都加上了j*j,因为每个bitset记录了若干个前缀和
            ans |= (pre << (j * j));
        }
        pre = ans;
    }
    // 统计1的个数就是能取到的状态
    cout << ans.count() << endl;
    getchar();
    getchar();
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值