BZOJ 4569: [Scoi2016]萌萌哒【倍增并查集
2016-07-16 15:53
507 查看
倍增并查集,考试naive地写的暴力_(:_ゝ∠)_
#include<cstdio> #include<algorithm> #include<cstring> #include<iostream> using namespace std; int n,m; const int MAXN=100057; const int MOD=1000000007; int f[17][MAXN]; int a,b,c,d,k; long long ans=9; int findfather(int c,int x){ return f[c][x]==x?x:f[c][x]=findfather(c,f[c][x]);} void merge(int c,int x,int y){ if(findfather(c,x)==findfather(c,y)) return ; f[c][f[c][x]]=f[c][y]; if(!c) return ; --c; merge(c,x,y),merge(c,x+(1<<c),y+(1<<c)); } int main(){ scanf("%d%d",&n,&m); if(n==1) return puts("10"),0; for(int i=0;(1<<i)<=n;++i) for(int j=1;j+(1<<i)-1<=n;++j) f[i][j]=j; while(m--){ scanf("%d%d%d%d",&a,&b,&c,&d); if(a==c) continue; for(k=0;(1<<k)<=(b-a+1);++k); --k; // k=31-__builtin_clz(b-a+1); merge(k,a,c),merge(k,b-(1<<k)+1,d-(1<<k)+1); } int cnt=-1; for(int i=1;i<=n;++i) if(findfather(0,i)==i) ++cnt; while(cnt-->0){ ans*=10; if(ans>=MOD) ans%=MOD; } cout<<ans; return 0; }
相关文章推荐
- boost-pretty-printer配置及问题
- hihocoder 第一周 最长回文字串
- AbstractSet抽象类源码解析
- 找出字符串
- Python print输出不换行
- Android M 新的运行时权限开发者需要知道的一切
- volatile关键字
- 文本挖掘,我们想要得到什么
- lnmp一键安装包
- poj 3126 (BFS + 素数打表)
- NOIP提高组2011 观光公车
- HDU 5253 最小生成树 kruscal
- Java多线程经典案例-生产者消费者
- BZOJ 4568 [Scoi2016]幸运数字 【倍增线性基
- 圆周舞蹈 (Standard IO)
- Span【推荐】
- 互斥锁和条件变量
- Set接口源码解析
- html页面通过特殊链接:打电话,发短信,发邮件详细教程
- cas 在 反向代理环境中的https 配置