1453: [Wc]Dface双面棋盘

Time Limit: 10 Sec  Memory Limit: 64 MB
Submit: 617  Solved: 317
[Submit][Status][Discuss]

Description

Input

Output

Sample Input

Sample Output

HINT

 
 
 
用线段树+数组模拟并查集,维护每一列的连通性,然后暴力合并就行了,常数巨大
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define N 210
int father[N<<],tmp[N<<],n,m,a[N][N];
struct Node{
int l,r;
int le[N],ri[N];
int lb[N],rb[N];
int s0,s1;
}tree[N<<]; inline int find(int x){
if(father[x]!=x)father[x]=find(father[x]);
return father[x];
}
void update(int rt){
tree[rt].s0=tree[rt<<].s0+tree[rt<<|].s0;
tree[rt].s1=tree[rt<<].s1+tree[rt<<|].s1;
memcpy(tree[rt].lb,tree[rt<<].lb,sizeof tree[rt].lb);
memcpy(tree[rt].rb,tree[rt<<|].rb,sizeof tree[rt].rb);
for(int i=;i<=n<<;i++) father[i]=i;
for(int i=;i<=n;i++) tree[rt<<|].le[i]+=*n,tree[rt<<|].ri[i]+=*n;
for(int i=;i<=n;i++){
int x=tree[rt<<].ri[i],y=tree[rt<<|].le[i];
if(find(x)!=find(y)&&tree[rt<<].rb[i]==tree[rt<<|].lb[i]){
father[find(x)]=find(y);
if(tree[rt<<].rb[i]){
tree[rt].s1--;
}else{
tree[rt].s0--;
}
}
}
for(int i=;i<=n;i++) tree[rt].le[i]=find(tree[rt<<].le[i]),
tree[rt].ri[i]=find(tree[rt<<|].ri[i]);
for(int i=;i<=n;i++) tmp[i<<]=tree[rt].le[i],tmp[(i<<)-]=tree[rt].ri[i];
sort(tmp+,tmp++*n);
int mxdata=unique(tmp+,tmp++*n)-tmp-;
for(int i=;i<=n;i++) tree[rt].le[i]=lower_bound(tmp+,tmp++mxdata,
tree[rt].le[i])-tmp,tree[rt].ri[i]=lower_bound(tmp+,tmp++mxdata,tree[rt].ri[i])-tmp;
for(int i=;i<=n;i++) tree[rt<<|].le[i]-=*n,tree[rt<<|].ri[i]-=*n;
} void build(int l,int r,int rt){
tree[rt].l=l;tree[rt].r=r;
if(l==r){
int tot=;
for(int i=;i<=n;i++)
{
if(a[i][l]!=a[i-][l])
{
tot++;
if(a[i][l]) tree[rt].s1++;
else tree[rt].s0++;
}
tree[rt].le[i]=tree[rt].ri[i]=tot;
tree[rt].lb[i]=tree[rt].rb[i]=a[i][l];
}
return;
}
int mid=(l+r)>>;
build(l,mid,rt<<);
build(mid+,r,rt<<|);
update(rt);
} void modify(int rt,int pos)
{
if(tree[rt].l==tree[rt].r)
{
int tot=;tree[rt].s1=;tree[rt].s0=;
for(int i=;i<=n;i++)
{
if(a[i][pos]!=a[i-][pos])
{
tot++;
if(a[i][pos]) tree[rt].s1++;
else tree[rt].s0++;
}
tree[rt].le[i]=tree[rt].ri[i]=tot;
tree[rt].lb[i]=tree[rt].rb[i]=a[i][pos];
}
return;
}
int mid=(tree[rt].l+tree[rt].r)>>;
if(pos<=mid) modify(rt<<,pos);
else modify(rt<<|,pos);
update(rt);
} int main(){
scanf("%d",&n);
for(int i=;i<=n;i++){
a[][i]=-;
for(int j=;j<=n;j++){
scanf("%d",&a[i][j]);
}
}
build(,n,);
scanf("%d",&m);
while(m--){
int x,y;
scanf("%d%d",&x,&y);
a[x][y]^=;
modify(,y);
printf("%d %d\n",tree[].s1,tree[].s0);
}
return ;
}

bzoj 1453: [Wc]Dface双面棋盘的更多相关文章

  1. 【刷题】BZOJ 1453 [Wc]Dface双面棋盘

    Description Input Output Sample Input Sample Output HINT Solution 不强制在线的动态图问题,那就LCT了 类似二分图那道题目 对于四个方 ...

  2. 【BZOJ1453】[Wc]Dface双面棋盘 线段树+并查集

    [BZOJ1453][Wc]Dface双面棋盘 Description Input Output Sample Input Sample Output HINT 题解:话说看到题的第一反应其实是LCT ...

  3. 【BZOJ1453】[WC] Dface双面棋盘(LCT维护联通块个数)

    点此看题面 大致题意: 给你一个\(n*n\)的黑白棋盘,每次将一个格子翻转,分别求黑色连通块和白色连通块的个数. \(LCT\)动态维护图连通性 关于这一部分内容,可以参考这道例题:[BZOJ402 ...

  4. BZOJ1453:[WC]Dface双面棋盘

    浅谈树状数组与线段树:https://www.cnblogs.com/AKMer/p/9946944.html 题目传送门:https://lydsy.com/JudgeOnline/problem. ...

  5. BZOJ1453: [Wc]Dface双面棋盘

    Description Input Output Sample Input Sample Output HINT 线段树套并查集应该是比较好写的做法,时间复杂度为O(N^3+M*NlogN). #in ...

  6. [Wc]Dface双面棋盘()

    题解: 一道维护奇怪信息的线段树... 我刚开始看了标签想的是删去图上一个点后求连通性 发现不会 于是退化成一般图支持删除 插入 维护连通性 发现有2两种做法 1.lct维护 按照结束顺序先后排序,给 ...

  7. BZOJ1453: [WC2005]Dface双面棋盘

    离线LCT维护MST,和3082的方法一样.然而比较码农,适合颓废的时候写. PS:线段树分治要好写得多,LCT比较自娱自乐. #include<bits/stdc++.h> using ...

  8. [BZOJ1453]Dface双面棋盘

    Description Input Output Sample Input Sample Output HINT 线段树+并查集,暴力记录和更新一些信息,详情见代码注解. #include<cm ...

  9. P4121 [WC2005]双面棋盘

    题目 P4121 [WC2005]双面棋盘 貌似是刘汝佳出的题目?? 做法 线段树维护并查集 线段树分治\(1\)~\(n\)行,我们要考虑维护的肯定是黑.白各自的联通块数量 考虑区间合并,其实就与中 ...

随机推荐

  1. 通过cookies信息模拟登陆

    import requests # 这个练习演示的是通过传入cookie信息模拟登陆,这样操作的前提是需要预先在浏览器登陆账户抓包得到cookie字段信息 url = "http://www ...

  2. HMAC(Hash-based Message Authentication Code)实现原理

    1.HMAC 概念 HMAC(Hash-based Message Authentication Code)基于 hash 的消息验证码,是 安全通信中必要的组成部件. 主要是 防止消息被篡改,和对称 ...

  3. LeetCode(152) Maximum Product Subarray

    题目 Find the contiguous subarray within an array (containing at least one number) which has the large ...

  4. CodeForce--Benches

    A. Benches   There are nn benches in the Berland Central park. It is known that aiai people are curr ...

  5. Git for Windows 工具的使用(二)

    Git分支  当一个人开发功能A而另一个人开发功能B,之后代码进行整合的时候,使代码既有功能A也有功能B.在Git中,Git给了我们分支的概念. 分支可以使用我们快速的开发协作,并且快速的合并. 分支 ...

  6. CodeForces 500E New Year Domino

    题意: 从左到右排列着\(n\)个多米诺骨牌,它们分别站在\(x\)轴上的位置\(p_i\)上且高度为\(l_i\). 当第\(i\)个多米诺骨牌向右倒下时,如果\(p_i < p_j \leq ...

  7. luogu2763 试题库问题

    倘若某个试题已经被选到某个类型里了,那么它就不可再被选进别的类型了. 所以,对于每个类型,我们将其与汇连边,权值是它的要求的题目数量. 对于每个题目,我们将源与其连边,权值是1,代表只能用一次.然后再 ...

  8. java EE技术体系——CLF平台API开发注意事项(1)——后端开发

    前言:这是一篇帮助小伙伴在本次项目中快速进入到java EE开发的一些说明,为了让同组小伙伴们开发的时候,有个清晰点的思路.昨天给大家演示分享了基本概况,但没有留下文字总结说明,预防后期有人再次问我, ...

  9. 开发者选择短视频SDK,为何青睐七牛云?

    从文字到图片再到视频的互联网内容媒介发展途径,随着 5g 技术的逐渐落地愈发清晰.短视频市场中的角力也随着诸多资本和创业者的涌入,进入到白热化阶段.这样的情况下,选择合适的短视频SDK产品就显得尤为重 ...

  10. 【Luogu】P2602数字计数(数位DP)

    题目链接 数位DP好喵啊.自己yy两个小时的dfs:题解40行代码=10WA:10A. md而且还不是完全理解题解是什么意思. 所以放题解链接. #include<cstdio> #inc ...