CF368 D - Persistent Bookcase
re了20多发 还是我在测试数据上操作最后了10多发才发现的
其实只需要多加一句就好了
真的愚蠢啊,要不都能进前100了
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 100005;
const int INF = 0x3f3f3f3f; int sh[1005][1005];
int flag[1005];
int sum[1005];
int all;
int vis[MAXN];
vector<int> mp[MAXN];
int n,m,q; struct Node{
int ty; int x,y; int ans;
}as[MAXN]; int cc = 0;
const int Ed = 26;
void dfs(int po,int fa) { int x1,x2; int y1,y2,y3,y4; // sh[x1][x2], all, sum[x1], flag[x1]
for(int i = 0; i < (int)mp[po].size(); ++i) {
int tt = mp[po][i];
int t1 = as[tt].ty; int t2 = as[tt].x; int t3 = as[tt].y; if(t1 == 4) t2 = 0; // 这地方不写会越界 谨记啊
x1 = t2; x2 = t3; y1 = sh[x1][x2]; y2 = all; y3 = sum[x1]; y4 = flag[x1]; if(t1 == 1) {
if( (flag[t2] ^ sh[t2][t3]) == 0) {
all ++; sh[t2][t3] ^= 1; sum[t2] ++;
}
}else if(t1 == 2) {
if( (flag[t2] ^ sh[t2][t3]) == 1){
all--; sh[t2][t3] ^= 1; sum[t2] --;
}
}else if(t1 == 3) {
flag[t2] ^= 1;
all += m-sum[t2]*2;
sum[t2] = m-sum[t2];
} as[tt].ans = all;
dfs(tt,po); sh[x1][x2] = y1; all = y2; sum[x1] = y3; flag[x1] = y4;
}
}
int main(){
while(~scanf("%d %d %d",&n,&m,&q)){
memset(flag,0,sizeof(flag));
memset(sh,0,sizeof(sh));
memset(sum,0,sizeof(sum));
all = 0;
cc = 0; for(int i = 0; i <= q; ++i) mp[i].clear(); for(int i = 1; i <= q; ++i) {
as[i].y = 0;
scanf("%d",&as[i].ty);
if(as[i].ty < 3) scanf("%d %d",&as[i].x,&as[i].y);
else scanf("%d",&as[i].x); if(as[i].ty == 4) mp[as[i].x].push_back(i);
else mp[i-1].push_back(i);
} dfs(0,-1);
for(int i = 1; i <= q; ++i) printf("%d\n",as[i].ans);
}
return 0;
}
CF368 D - Persistent Bookcase的更多相关文章
- CodeForces #368 div2 D Persistent Bookcase DFS
题目链接:D Persistent Bookcase 题意:有一个n*m的书架,开始是空的,现在有k种操作: 1 x y 这个位置如果没书,放书. 2 x y 这个位置如果有书,拿走. 3 x 反转这 ...
- 【Codeforces-707D】Persistent Bookcase DFS + 线段树
D. Persistent Bookcase Recently in school Alina has learned what are the persistent data structures: ...
- Codeforces Round #368 (Div. 2) D. Persistent Bookcase
Persistent Bookcase Problem Description: Recently in school Alina has learned what are the persisten ...
- Persistent Bookcase
Persistent Bookcase time limit per test 2 seconds memory limit per test 512 megabytes input standard ...
- Codeforces Round #368 (Div. 2) D. Persistent Bookcase 离线 暴力
D. Persistent Bookcase 题目连接: http://www.codeforces.com/contest/707/problem/D Description Recently in ...
- codeforces 707D D. Persistent Bookcase(dfs)
题目链接: D. Persistent Bookcase time limit per test 2 seconds memory limit per test 512 megabytes input ...
- CF707D Persistent Bookcase
CF707D Persistent Bookcase 洛谷评测传送门 题目描述 Recently in school Alina has learned what are the persistent ...
- Persistent Bookcase CodeForces - 707D (dfs 离线处理有根树模型的问题&&Bitset)
Persistent Bookcase CodeForces - 707D time limit per test 2 seconds memory limit per test 512 megaby ...
- D. Persistent Bookcase(Codeforces Round #368 (Div. 2))
D. Persistent Bookcase time limit per test 2 seconds memory limit per test 512 megabytes input stand ...
随机推荐
- BZOJ 2734: [HNOI2012]集合选数 [DP 状压 转化]
传送门 题意:对于任意一个正整数 n≤100000,如何求出{1, 2,..., n} 的满足若 x 在该子集中,则 2x 和 3x 不能在该子集中的子集的个数(只需输出对 1,000,000,001 ...
- BZOJ 2752: [HAOI2012]高速公路(road) [线段树 期望]
2752: [HAOI2012]高速公路(road) Time Limit: 20 Sec Memory Limit: 128 MBSubmit: 1219 Solved: 446[Submit] ...
- 【转】我读过最好的epoll讲解(来自知乎)
首先我们来定义流的概念,一个流可以是文件,socket,pipe等等可以进行I/O操作的内核对象.不管是文件,还是套接字,还是管道,我们都可以把他们看作流.之后我们来讨论I/O的操作,通过read,我 ...
- SpringMVC之HelloWorld实例
1.1 Helloworld实例的操作步骤 1. 加入jar包 2. 配置dispatcherServlet 3. 加入Spring配置文件 4. 编写请求处理器 并表示为处理器 5. 编写视图 1 ...
- 二维码开源库ZBar-实现中文解码
中文乱码 上篇<ZBar-windows下编译和使用>已经成功解析了条形码,但目标是二维码,经测试二维码中文会出现乱码.下图二维码的内容是"http123测试456", ...
- MySQL对sum()字段 进行条件筛选,使用having,不能用where
显示每个地区的总人口数和总面积.仅显示那些面积超过1000000的地区. SELECT region, SUM(population), SUM(area) FROM bbc GROUP BY reg ...
- CSS预处理器之Less详解
本文最初发表于博客园,并在GitHub上持续更新前端的系列文章.欢迎在GitHub上关注我,一起入门和进阶前端. 以下是正文. CSS 预处理器 为什么要有 CSS 预处理器 CSS基本上是设计师的工 ...
- 架构师入门:搭建双注册中心的高可用Eureka架构(基于项目实战)
本文的案例是基于 架构师入门:搭建基本的Eureka架构(从项目里抽取) 改写的. 在上文里,我们演示Eureka客户端调用服务的整个流程,在这部分里我们将在架构上有所改进.大家可以想象下,在上文里案 ...
- vim插件安装总结
vim插件安装总结 vim 插件 vundle 插件对于vim来说是一个杀手级别的神器助手,能自动补全,语法高亮,文件搜索等等,有效地提升了编程效率.下面就个人的一些安装和使用进行一个总结. 自动管理 ...
- Android Stdio 中的Rendering Problems Android N requires the IDE to be running with Java 1.8 or later Install a supported JDK解决办法
出现如下图所示的错误 解决办法为: 然后在里面输入SDK 下载 下载APILevel为23版本的SDK 换成23版本的SDK 完美解决问题