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的更多相关文章

  1. CodeForces #368 div2 D Persistent Bookcase DFS

    题目链接:D Persistent Bookcase 题意:有一个n*m的书架,开始是空的,现在有k种操作: 1 x y 这个位置如果没书,放书. 2 x y 这个位置如果有书,拿走. 3 x 反转这 ...

  2. 【Codeforces-707D】Persistent Bookcase DFS + 线段树

    D. Persistent Bookcase Recently in school Alina has learned what are the persistent data structures: ...

  3. Codeforces Round #368 (Div. 2) D. Persistent Bookcase

    Persistent Bookcase Problem Description: Recently in school Alina has learned what are the persisten ...

  4. Persistent Bookcase

    Persistent Bookcase time limit per test 2 seconds memory limit per test 512 megabytes input standard ...

  5. Codeforces Round #368 (Div. 2) D. Persistent Bookcase 离线 暴力

    D. Persistent Bookcase 题目连接: http://www.codeforces.com/contest/707/problem/D Description Recently in ...

  6. codeforces 707D D. Persistent Bookcase(dfs)

    题目链接: D. Persistent Bookcase time limit per test 2 seconds memory limit per test 512 megabytes input ...

  7. CF707D Persistent Bookcase

    CF707D Persistent Bookcase 洛谷评测传送门 题目描述 Recently in school Alina has learned what are the persistent ...

  8. Persistent Bookcase CodeForces - 707D (dfs 离线处理有根树模型的问题&&Bitset)

    Persistent Bookcase CodeForces - 707D time limit per test 2 seconds memory limit per test 512 megaby ...

  9. 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 ...

随机推荐

  1. BZOJ 3876: [Ahoi2014]支线剧情 [上下界费用流]

    3876: [Ahoi2014]支线剧情 题意:每次只能从1开始,每条边至少经过一次,有边权,求最小花费 裸上下界费用流...每条边下界为1就行了 注意要加上下界*边权 #include <io ...

  2. BZOJ 3040: 最短路(road) [Dijkstra + pb_ds]

    3040: 最短路(road) Time Limit: 60 Sec  Memory Limit: 200 MBSubmit: 2476  Solved: 814[Submit][Status][Di ...

  3. React ref回调函数例子

    ref属性也可以是一个回调函数而不是一个名字.   这个函数将要在组件被挂载之后立即执行. 这个参照的组件将会作为该函数的参数,这个函数可以立即使用这个组件参数,当然也可以将其保存供以后使用. 当这个 ...

  4. 云计算之路-阿里云上:重启 manager 节点引发 docker swarm 集群宕机

    为了迎接春节假期后的访问高峰,我们今天对 docker swarm 集群进行了变更操作,购买了1台阿里云4核8G的服务器作为 worker 节点,由原来的  3 manager nodes + 2 w ...

  5. Job 失败了怎么办?- 每天5分钟玩转 Docker 容器技术(133)

    上一节讨论了 Job 执行成功的情况,如果失败了会怎么样呢? 修改 myjob.yml,故意引入一个错误: 先删除之前的 Job: 如果将 restartPolicy 设置为 OnFailure 会怎 ...

  6. c++项目范例

    #include<iostream> #include<string.h> #include<stdlib.h> using namespace std; clas ...

  7. uboot之位置无关代码解析

    在之前的话 新年过去了,那么久没有好好学习,感觉好颓废,现在就uboot的一些基础问题做一些笔记,顺便分享给大家,不过由于见识有限,如果有不足之处请多多指教. 位置无关?什么意思?我们先了解一些基础知 ...

  8. PLECS—晶闸管-第九周

    1. 单相桥式晶闸管整流电路仿真 (1)仿真电路图 (2)触发角为pi/4的手工波形图(参数设置,触发角=pi/4, 电感L = 0H) (2)模拟仿真波形图 1)参数设置:触发角=pi/4, 电感L ...

  9. 在CentOS 7中安装Jetty服务器

    Jetty 是一款纯Java的HTTP (Web) 服务器和Java Servlet容器. 通常在更大的网络框架中,Jetty经常用于设备间的通信,而其他Web服务器通常给"人类" ...

  10. unix网络编程环境搭建

    unix网络编程环境搭建 网络编程 环境 1.点击下载源代码 可以通过下列官网中的源代码目录下载最新代码: http://www.unpbook.com/src.html 2.解压文件 tar -xz ...