一种优化方法,具体例子可以看这里

这里只是存一下手写Bitset的板子

struct Bitset
{
unsigned a[1600];
void reset()
{
memset(a,0,sizeof(a));
}
Bitset()
{
reset();
}
void flip(int x)
{
a[x>>5]^=1<<(x&31);
}
void set(int x)
{
a[x>>5]|=1<<(x&31);
}
void reset(int x)
{
a[x>>5]&=~(1<<(x&31));
}
int test(int x)
{
return (a[x>>5]>>(x&31))&1;
}
Bitset operator ~()const
{
Bitset ret;
for(int i=0;i<1600;i++)ret.a[i]=~a[i];
return ret;
}
Bitset operator &(const Bitset &b)const
{
Bitset ret;
for(int i=0;i<1600;i++)ret.a[i]=a[i]&b.a[i];
return ret;
}
Bitset operator |(const Bitset &b)const
{
Bitset ret;
for(int i=0;i<1600;i++)ret.a[i]=a[i]|b.a[i];
return ret;
}
Bitset operator ^(const Bitset &b)const
{
Bitset ret;
for(int i=0;i<1600;i++)ret.a[i]=a[i]^b.a[i];
return ret;
}
Bitset operator <<(const int t)const
{
Bitset ret;
unsigned last=0;
int high=t>>5,low=t&31;
for(int i=0;i+high<1600;i++)
{
ret.a[i+high]=last|(a[i]<<low);
if(low)last=a[i]>>(32-low);
}
return ret;
}
Bitset operator >>(const int t)const
{
Bitset ret;
unsigned last=0;
int high=t>>5,low=t&31;
for(int i=1600-1;i>=high;i--)
{
ret.a[i-high]=last|(a[i]>>low);
if(low)last=a[i]<<(32-low);
}
return ret;
}
vector<int> ones()const
{
vector<int> ret;
for(int i=0;i<1600;i++)
{
unsigned tmp=a[i];
while(tmp)
{
short t=__builtin_ctz(tmp);
ret.pb((i<<5)|t);
tmp^=1u<<t;
}
}
return ret;
}
}use,trans,cur;

最新文章

  1. iOS学习笔记——多控制器管理
  2. 迭代器和for-of循环 顺便带一下Es5中的.map遍历
  3. HDU 2602 Bone Collector WA谁来帮忙找找错
  4. BestCoder12 1001.So easy(hdu 5058) 解题报告
  5. 深度解析国内O2O模式
  6. vim之pydiction插件
  7. URL地址下载图片到本地
  8. robotframework-FQA
  9. html页面布局 第8节
  10. 爱加密Android APk 原理解析
  11. Java设计模式---工厂模式(简单工厂、工厂方法、抽象工厂)
  12. 清明培训 清北学堂 DAY1
  13. Python:Day55 ORM多表操作
  14. orcle查看表空间数据文件使用情况
  15. Object type TYPE failed to create with error
  16. Swift - EasingAnimation绘制圆环动画
  17. BZOJ2878 NOI2012迷失游乐园(树形dp+环套树+概率期望)
  18. Tomcat *的安装和运行(绿色版和安装版都适用)
  19. 深度学习方法(九):自然语言处理中的Attention Model注意力模型
  20. BZOJ5249:[九省联考2018]IIIDX——题解

热门文章

  1. HCIP-RSTP
  2. 【c++ Prime 学习笔记】第19章 特殊工具与技术
  3. [对对子队]会议记录4.11(Scrum Meeting 2)
  4. [no_code]团队贡献分分配规则
  5. mongodb的聚合操作
  6. CodeForces-1076E Vasya and a Tree
  7. Maven还停留在导jar包?快来探索Nexus私服的新世界
  8. mdev 响应热插拔事件
  9. 第一个只出现一次字符的位置 牛客网 剑指Offer
  10. Get value from agent failed: cannot connect to [[127.0.0.1]:10050]: [111] Connection refused