bzoj 1453: [Wc]Dface双面棋盘
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双面棋盘的更多相关文章
- 【刷题】BZOJ 1453 [Wc]Dface双面棋盘
Description Input Output Sample Input Sample Output HINT Solution 不强制在线的动态图问题,那就LCT了 类似二分图那道题目 对于四个方 ...
- 【BZOJ1453】[Wc]Dface双面棋盘 线段树+并查集
[BZOJ1453][Wc]Dface双面棋盘 Description Input Output Sample Input Sample Output HINT 题解:话说看到题的第一反应其实是LCT ...
- 【BZOJ1453】[WC] Dface双面棋盘(LCT维护联通块个数)
点此看题面 大致题意: 给你一个\(n*n\)的黑白棋盘,每次将一个格子翻转,分别求黑色连通块和白色连通块的个数. \(LCT\)动态维护图连通性 关于这一部分内容,可以参考这道例题:[BZOJ402 ...
- BZOJ1453:[WC]Dface双面棋盘
浅谈树状数组与线段树:https://www.cnblogs.com/AKMer/p/9946944.html 题目传送门:https://lydsy.com/JudgeOnline/problem. ...
- BZOJ1453: [Wc]Dface双面棋盘
Description Input Output Sample Input Sample Output HINT 线段树套并查集应该是比较好写的做法,时间复杂度为O(N^3+M*NlogN). #in ...
- [Wc]Dface双面棋盘()
题解: 一道维护奇怪信息的线段树... 我刚开始看了标签想的是删去图上一个点后求连通性 发现不会 于是退化成一般图支持删除 插入 维护连通性 发现有2两种做法 1.lct维护 按照结束顺序先后排序,给 ...
- BZOJ1453: [WC2005]Dface双面棋盘
离线LCT维护MST,和3082的方法一样.然而比较码农,适合颓废的时候写. PS:线段树分治要好写得多,LCT比较自娱自乐. #include<bits/stdc++.h> using ...
- [BZOJ1453]Dface双面棋盘
Description Input Output Sample Input Sample Output HINT 线段树+并查集,暴力记录和更新一些信息,详情见代码注解. #include<cm ...
- P4121 [WC2005]双面棋盘
题目 P4121 [WC2005]双面棋盘 貌似是刘汝佳出的题目?? 做法 线段树维护并查集 线段树分治\(1\)~\(n\)行,我们要考虑维护的肯定是黑.白各自的联通块数量 考虑区间合并,其实就与中 ...
随机推荐
- my购物车
sum=0 a=input("请输入“水果”或“衣服”:") if a=="手机": while True: shop = { '蓝葡萄', '水蜜桃', '草 ...
- x mod a=r(N对a,r)
//模数不一定互质,互质才可以用孙子定理. /* https://blog.csdn.net/zmh964685331/article/details/50527894 uu遇到了一个小问题,可是他不 ...
- 浅析win32 Win64 x86 x64 区别 及Eclipse启动报Java was started but returned exit code=13 错误
win32.x86_64是64位 X86就是 32位系统 X64 就是64位系统 最好记得方法就是带有64的就是64位,其余都是32位 为什么要讲这个呢? 如果是绿色版本的eclipse,在打开ec ...
- K-means算法的优缺点
K-means算法的优缺点 优点:原理简单,实现容易 缺点: 收敛较慢 算法时间复杂度比较高 \(O(nkt)\) 不能发现非凸形状的簇 需要事先确定超参数K 对噪声和离群点敏感 结果不一定是全局最优 ...
- Leetcode 472.连接词
连接词 给定一个不含重复单词的列表,编写一个程序,返回给定单词列表中所有的连接词. 连接词的定义为:一个字符串完全是由至少两个给定数组中的单词组成的. 示例: 输入: ["cat" ...
- Django Rest Framework 教程及API向导
Django Rest Framework 教程及API向导. 一.请求(Request)REST_FRAMEWORK 中的 Request 扩展了标准的HttpRequest,为 REST_FRAM ...
- oracle主键自增长
这几天搞Oracle,想让表的主键实现自动增长,查网络实现如下: create table simon_example ( id number(4) not null primary key, nam ...
- 九度oj 题目1358:陈博的平均主义
题目描述: 在JOBDU团队里,陈博是最讲平均主义的人了,但并不是像梁山好汉那样能够做到有钱同花,有肉同吃,毕竟,他还是被家里的领导管着的……陈博的平均主义,就只能体现在他对数字的喜好了.陈博特别喜欢 ...
- hibernate基础工具findBySQL学习
public List<Map<String,Object>> findBySQL(String sql,Map<String,Object> param,int ...
- SiteMapPath控件的使用(ASP.NET)
最近在博客里写了一些日志,主要都是我在实际编程过程中遇到的问题.问题出现后,先自己推敲,搞不定的,就上网去搜,再就是请教同学.同事,从中获益匪浅,也很难得!现在把感觉比较实用的一些功能代码之类的发布到 ...