# bitset常用用法&&简单题分析

#### Preface

bitset，还是一个比较好用的STL，可以给一些题目做到神奇的常数优化（$O(\frac{原来的复杂度}{机器的位数(32位or64位)})$

#### Newcoder 132C 简单瞎搞题

CODE

#include<cstdio>
#include<cctype>
#include<bitset>
using namespace std;
const int N=1000005;
int n,q,l,r;
bitset <N> ans,t;
inline char tc(void)
{
static char fl[100000],*A=fl,*B=fl;
}
{
x=0; char ch; while (!isdigit(ch=tc()));
while (x=(x<<3)+(x<<1)+ch-'0',isdigit(ch=tc()));
}
int main()
{
//freopen("CODE.in","r",stdin); freopen("CODE.out","w",stdout);
for (i=1;i<=n;++i)
{
for (j=l;j<=r;++j) t|=ans<<j*j; ans=t;
}
return printf("%d",ans.count()),0;
}


#### POJ 2443

CODE

#include<cstdio>
#include<cctype>
#include<bitset>
using namespace std;
const int N=1005,MAX_SIZE=10005;
int n,q,x,y;
bitset <N> bit[MAX_SIZE],t;
inline char tc(void)
{
static char fl[100000],*A=fl,*B=fl;
}
{
x=0; char ch; while (!isdigit(ch=tc()));
while (x=(x<<3)+(x<<1)+ch-'0',isdigit(ch=tc()));
}
int main()
{
//freopen("CODE.in","r",stdin); freopen("CODE.out","w",stdout);
for (i=1;i<=n;++i)
{
if (t.any()) puts("Yes"); else puts("No");
}
return 0;
}


#### HDU 5036

Tarjan+拓扑排序貌似也可以跑，但是根本没有这个好写啊

CODE

#include<cstdio>
#include<cctype>
#include<bitset>
using namespace std;
const int N=1005;
bitset <N> d[N];
int t,n,x,y; double ans;
inline char tc(void)
{
static char fl[100000],*A=fl,*B=fl;
}
{
x=0; char ch; while (!isdigit(ch=tc()));
while (x=(x<<3)+(x<<1)+ch-'0',isdigit(ch=tc()));
}
inline void floyed(void)
{
for (register int i=1;i<=n;++i)
for (register int j=1;j<=n;++j)
if (d[j].test(i)) d[j]|=d[i];
}
int main()
{
//freopen("CODE.in","r",stdin); freopen("CODE.out","w",stdout);
for (s=1;s<=t;++s)
{