Description
在打了1 mol盘majsoul之后,小L和小E决定找一些新游戏来玩.
他们打开了某卡牌游戏,该游戏开始时系统会赠送玩家nn个侍从,第ii名侍从的能力值为[li,ri]中的某一个整数.
在一场战斗中,玩家打出的总伤害和他所拥有的所有侍从的能力值有关,对于能力值为x的侍从,他能打出x2的伤害,一名玩家能打出的伤害即为他所拥有的所有侍从打出的伤害之和.
小L对游戏本身是否好玩并不好奇,但是他好奇对于所有可能的开局情况,玩家总共能打出多少种数值不同的伤害.但是他并不想算,于是他把这个问题丢给了你. Tasks
Input Format
第一行一个正整数n,含义如题面所示.
接下来n行每行两个正整数,第i+1行的两个正整数li,ri含义如题面所示.
Output Format
一个整数,表示小L总共能打出多少种不同的伤害.
Solution:
bitset使用的板子题,学习了以下bitset的使用。
我称bitset为“位运算的机器”,使用起来很顺手。
#include<cmath>
#include<cstring>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<bitset>
#define int long long
#define reg register
using namespace std;
const int maxn=1e6+5;
const int mod=20170408;
inline int read()
{
int x=0,f=1;
char ch=getchar();
while(ch<'0' || ch>'9')
{
if(ch=='-')
f=-1;
ch=getchar();
}
while(ch>='0' && ch<='9')
{
x=x*10+ch-'0';
ch=getchar();
}
return x*f;
}
int n;
int l[maxn];
int r[maxn];
//map<int,int> mp;
bitset<1000005> ans,now;
signed main()
{
n=read();
for(int i=1;i<=n;i++)
{
l[i]=read(),r[i]=read();
}
ans[0]=1;
for(int i=1;i<=n;i++)
{
now.reset();
for(int j=l[i];j<=r[i];j++)
{
now=now | (ans<<j*j);
}
ans=now;
}
//cout<<ans<<endl;
cout<<ans.count()<<endl;
return 0;
}
/*
7
1
1 2 1
1 3 3
2 4 2
2 5 5
2 6 2
3 7 2
*/