【bzoj3563】DZY Loves Chinese 在线cdq分治+并查集
来源:互联网 发布:枪球联动算法 编辑:程序博客网 时间:2024/05/01 21:14
和3237做法差不多,把cdq分治改成在线的就可以了。
至于怎么在线cdq分治?这个只可意会,不可言传。
#include<cstdio>#include<cstring>#include<cstdlib>#include<cmath>#include<iostream>#include<algorithm>#define maxn 500010using namespace std;struct yts{int x,y;bool flag;}e[maxn];int ans[maxn],f[maxn],c[20];int n,m,k,T;char s[maxn];int find(int x){if (x==f[x]) return x;else return f[x]=find(f[x]);}bool check(char x){return x>='0' && x<='9';}int cal(int l,int r){int x=0;for (int i=l;i<=r;i++) x=x*10+s[i]-'0';return x;}int main(){scanf("%d%d",&n,&m);for (int i=1;i<=m;i++) scanf("%d%d",&e[i].x,&e[i].y);scanf("%d",&T);for (int i=1;i<=T;i++){int kk,k=0;scanf("%d",&kk);gets(s+1);int len=strlen(s+1);for (int j=1;j<=len;j++) if (check(s[j]) && !check(s[j+1])) k++;ans[i-1]=k^kk;if (i==T) {for (int j=1;j<=len;j++) if (check(s[j])) {int k=j;while (check(s[k])) k++;e[cal(j,k-1)^ans[i-1]].flag=1;j=k-1; }}}for (int i=1;i<T;i++) if (ans[i]-ans[i-1]) printf("Connected\n"); else printf("Disconnected\n");for (int i=1;i<=n;i++) f[i]=i;for (int i=1;i<=m;i++) if (!e[i].flag) { int f1=find(e[i].x),f2=find(e[i].y); if (f1!=f2) f[f1]=f2; }int num=f[1];for (int i=2;i<=n;i++) if (f[i]!=num) {printf("Disconnected\n");return 0;}printf("Connected\n");return 0;}
0 0
- 【bzoj3563】DZY Loves Chinese 在线cdq分治+并查集
- BZOJ3563/3569 DZY Loves Chinese II/DZY Loves Chinese
- BZOJ 3563 DZY Loves Chinese 并查集
- [乱搞 暴力 并查集] BZOJ 3563 DZY Loves Chinese
- bzoj 3563: DZY Loves Chinese 并查集+乱搞
- [ CDQ分治 并查集 ][ AHOI2013 ] BZOJ3237
- CodeForces 445B. DZY Loves Chemistry(并查集)
- Codeforces 445B DZY Loves Chemistry(并查集)
- CodeForces 445B DZY Loves Chemistry(并查集)
- CodeForces 445B DZY Loves Chemistry (并查集)
- CodeForces 445B - DZY Loves Chemistry(并查集)
- Codeforces 455B DZY Loves Chemistry【并查集】
- 【codeforces 445B - DZY Loves Chemistry 】 + 并查集
- CodeForces 445B DZY Loves Chemistry (并查集)
- codeforces 445 B. DZY Loves Chemistry (并查集)
- 【Codeforces】-DZY Loves Chemistry(并查集变形)
- 【CodeForces】445B - DZY Loves Chemistry(并查集)
- CF445B:DZY Loves Chemistry(并查集)
- TCP/IP SOCKET HTTP及HTTPS之间的关系及各自特性之总结
- selenium---webdriver窗口跳转
- 敌兵布阵(点更新)
- zookeeper运维
- VS2013链接mysql问题二(基础)
- 【bzoj3563】DZY Loves Chinese 在线cdq分治+并查集
- 第十二周阅读程序(1)
- 搭建Windows下的Git Server
- hdu 1285 拓扑排序 入门
- DataX 在异构的数据库/文件系统之间高速交换数据的工具
- poj 2506
- 548 Tree
- IDL create a empty string
- hdu 2647 拓扑排序变形