BZOJ 4569: [Scoi2016]萌萌哒 倍增思维并查集
来源:互联网 发布:java后端框架 编辑:程序博客网 时间:2024/05/29 12:26
Time Limit: 10 Sec Memory Limit: 256 MB
Submit: 1110 Solved: 528
Description
一个长度为n的大数,用S1S2S3…Sn表示,其中Si表示数的第i位,S1是数的最高位,告诉你一些限制条件,每个条
件表示为四个数,l1,r1,l2,r2,即两个长度相同的区间,表示子串Sl1Sl1+1Sl1+2…Sr1与Sl2Sl2+1Sl2+2…S
r2完全相同。比如n=6时,某限制条件l1=1,r1=3,l2=4,r2=6,那么123123,351351均满足条件,但是12012,13
1141不满足条件,前者数的长度不为6,后者第二位与第五位不同。问满足以上所有条件的数有多少个。
Input
第一行两个数n和m,分别表示大数的长度,以及限制条件的个数。接下来m行,对于第i行,有4个数li1,ri1,li2
,ri2,分别表示该限制条件对应的两个区间。
1≤n≤10^5,1≤m≤10^5,1≤li1,ri1,li2,ri2≤n;并且保证ri1-li1=ri2-li2。
Output
一个数,表示满足所有条件且长度为n的大数的个数,答案可能很大,因此输出答案模10^9+7的结果即可。
Sample Input
4 2
1 2 3 4
3 3 3 3
Sample Output
90
HINT
Source
直接倍增思维并查集就可以了,对于每个大小的块维护并查集即可,然后最后来pushdown,然后再计数就可以了,具体的可以看这篇博客 机房模拟赛
#include<cstdio>#include<cctype>#include<cstring>#include<algorithm>using namespace std;long long p;const long long mod = 1000000007LL;const int MAXN = 100000;int fa[20][ MAXN * 2 ], pow[ MAXN * 2 ], n, m, L, R, l, r, len;long long fast_pow( long long x ) { long long BASE = 10LL, tmp = 1LL; while( x ) { if( x & 1 ) tmp = tmp * BASE % mod; x >>= 1; BASE = BASE * BASE % mod; } return tmp;}int find( int M, int x ) { if( fa[M][x] == x ) return x; else return fa[M][x] = find( M, fa[M][x] );}void Union( int M, int x, int y ) { x = find( M, x ), y = find( M, y ); if( x != y ) fa[M][x] = fa[M][y];}int main( ) { scanf( "%d", &n ); for( register int i = 2; i <= n; i++ ) pow[i] = pow[ i >> 1 ] + 1; for( register int i = pow[n]; i >= 0; i-- ) for( register int j = 1; j <= n; j++ ) fa[i][j] = j; scanf( "%d", &m ); while( m-- ) { scanf( "%d%d%d%d", &L, &R, &l, &r ); int M = pow[ R - L + 1 ]; Union( M, L, l ); Union( M, R - ( 1 << M ) + 1, r - ( 1 << M ) + 1 ); } for( register int j = pow[n]; j; j-- ) { for( register int i = 1; i + ( 1 << j ) - 1 <= n; i++ ) { int fat = find( j, i ); Union( j - 1, i, fat ); Union( j - 1, i + ( 1 << ( j - 1 ) ), fat + ( 1 << ( j - 1 ) ) ); } } int tmp = 0; for( register int i = 1; i <= n; i++ ) if( find( 0, i ) == i ) tmp++; printf( "%lld\n", 9LL * fast_pow( tmp - 1 ) % mod ); return 0;}
阅读全文
0 0
- BZOJ 4569: [Scoi2016]萌萌哒 倍增思维并查集
- BZOJ 4569: [Scoi2016]萌萌哒【倍增并查集
- BZOJ 4569: [Scoi2016]萌萌哒 并查集+倍增
- 4569: [Scoi2016]萌萌哒 倍增+并查集
- 【bzoj 4569】[Scoi2016]萌萌哒 (并查集)
- 【bzoj4569】[Scoi2016]萌萌哒 倍增+并查集
- bzoj 4569: [Scoi2016]萌萌哒 (st表+并查集)
- bzoj 4569: [Scoi2016]萌萌哒 ST表+并查集
- BZOJ 4569: [Scoi2016]萌萌哒 ST表 并查集
- 【BZOJ 4569】【SCOI】【萌萌哒】【并查集】【倍增均摊优化】
- [BZOJ]4569 [SCOI2016] 萌萌哒 并查集神题
- bzoj 4569: [Scoi2016]萌萌哒
- BZOJ 4569: [Scoi2016]萌萌哒
- BZOJ 4569 [Scoi2016]萌萌哒
- BZOJ 4569: [Scoi2016]萌萌哒
- BZOJ 4569 [Scoi2016]萌萌哒
- BZOJ 4569 [Scoi2016] 萌萌哒
- BZOJ 4569: [Scoi2016]萌萌哒
- C++删除字符串中出现的连续的k个0
- python 基础第四天(模块 序列化)
- android返回键不销毁应用返回主界面
- comparator接口与Comparable接口的区别
- 一款很好用的,免费的外网映射工具Ngrok 国内版,可以满足基本的开发测试需求
- BZOJ 4569: [Scoi2016]萌萌哒 倍增思维并查集
- Xcode程序异常崩溃情况事故记录
- htaccess 正则规则整理常见的htaccess的正则规则
- mybatis简单案例源码详细【注释全面】——测试层(UserMapperTest.java)
- 【JavaScript】——之实践中应用
- 转载:java合并文件
- SVN匿名访问的设置
- 【技术分享】Java反序列化漏洞从理解到实践
- mybatis 3.x 缓存Cache的使用