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. MongoDB之分片集群(Sharding)

    MongoDB之分片集群(Sharding) 一.基本概念 分片(sharding)是一个通过多台机器分配数据的方法.MongoDB使用分片支持大数据集和高吞吐量的操作.大数据集和高吞吐量的数据库系统 ...

  2. LeetCode - 307. Range Sum Query - Mutable

    Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive ...

  3. ECS的配置与使用

    登录阿里云ECS,系统是centos7.2 在linux下通过useradd方式创建新用户,切换到该用户权限,发现-bash-4.2$ . 解决方法:先查看进程,关闭相关进程.然后使用useradd ...

  4. dnspython模块安装

    wget  http://www.dnspython.org/kits/1.12.0/dnspython-1.12.0.tar.gz tar -zxvf dnspython-1.12.0.tar.gz ...

  5. ipset批量配置iptables

    简介: ipset是iptables的扩展,允许你创建匹配整个地址sets(地址集合)的规则.而不像普通的iptables链是线性的存储和过滤,ip集合存储在带索引的数据结构中,这种集合比较大也可以进 ...

  6. php获取今日开始时间戳和结束时间戳

    1.php获取今日开始时间戳和结束时间戳  $beginToday=mktime(0,0,0,date('m'),date('d'),date('Y'));$endToday=mktime(0,0,0 ...

  7. iOS 9 HTTPS 的配置

    方法有两种: (1)废话少说直接上图: (2)右击info.plist 文件 open as ->source code 在里面注入如下代码就行了(位置不固定,但要在指定的文件夹选项里) < ...

  8. 关于DOM与BOM的总结

    1.什么是BOM,什么是DOM(基本概念) BOM: Browers Object MOdel           浏览器对象模型 DOM: Document Object MOdel         ...

  9. C/C++语言简介之运算符

    比较特别的是,比特右移(>>)运算符可以是算术(左端补最高有效位)或是逻辑(左端补 0)位移.例如,将 11100011 右移 3 比特,算术右移后成为 11111100,逻辑右移则为 0 ...

  10. ECharts 高度宽度自适应(转载)

    最近在写一个地图类的应用,用的是echarts的图表,然而一上来就一脸懵逼,如果父级容器的height/width属性设置为百分比的形式,那么echarts就会warning,且不能正常的生成图表.所 ...