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\)行,我们要考虑维护的肯定是黑.白各自的联通块数量 考虑区间合并,其实就与中 ... 
随机推荐
- Geode 集群搭建,快速上手使用
			Geode 介绍: Geode是一个提供实时.一致访问大型分布式云平台下数据密集型应用的数据管理平台. Geode 通过跨多进程,把内存.CPU.网络资源和可选的本地磁盘汇集起来,来管理应用程序对象及 ... 
- Hard problem CodeForces - 706C
			Time limit1000 ms Memory limit262144 kB 题目: Vasiliy is fond of solving different tasks. Today he fou ... 
- POJ:2411-Mondriaan's Dream(矩形拼接方案)
			题目链接:http://poj.org/problem?id=2411 解题心得: 可以说是很经典的一个状压dp了,写dfs遍历肯定是要超时的,这个题的状态转移方程对新手来说有点吃力. 状态转移用的是 ... 
- jmeter switch controller
			工作方式: Switch控制器通过给该控制器中的Value赋值,来指定运行哪个采样器.有两种赋值方式: 1.第一种是数值,Switch控制器下的子节点从0开始计数,通过指定子节点所在的数值来确定执行哪 ... 
- MFC 中 删除一个非空文件夹
			MFC中提供了删除文件夹的一个封装函数 RemoveDirectory(LPCTSTR lpPathName),我们只要把要删除的文件夹的路径传进去就可以删除了,貌似一切如此简单.我象征性的建立一个文 ... 
- Win7里IIS7部署WebService
			最近忙于一个Web的Bug修正,是先人写的一个东东,架构很简单,一个前端的项目,一个WebService的项目,以及后台的一些dll.之前一直很排斥这个产品,因为它没法启动,印象中没有跑得起来过的时候 ... 
- 大数据学习——spark笔记
			变量的定义 val a: Int = 1 var b = 2 方法和函数 区别:函数可以作为参数传递给方法 方法: def test(arg: Int): Int=>Int ={ 方法体 } v ... 
- selenium - 下拉框操作
			# 9. 下拉框操作# (1)等待下拉列表和下拉列表中值存在# (2)在下拉列表中选择一个值 # 三种方式# A. 获取所有的下拉列表值,然后用循环去匹配相同的值 select_by_index(下标 ... 
- 一个TensorFlow例子
			一个TensorFlow的例子 import tensorflow as tf x = tf.constant(1.0, name='input') w = tf.Variable(0.8, name ... 
- hdu 2665 划分树模板题(可作为模板)
			Kth number Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ... 
