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 ...
随机推荐
- 前端-Useful Js Plugins
Validform.min.js:提供对表单的验证.提交等功能,具体可查阅相关文档,@Validform 示例: $("#id").Validform() ; WdatePicke ...
- bzoj 4815: [Cqoi2017]小Q的表格 [数论]
4815: [Cqoi2017]小Q的表格 题意: 单点修改,查询前缀正方形和.修改后要求满足条件f(a,b)=f(b,a), b×f(a,a+b)=(a+b)*f(a,b) 一开始sb了认为一次只会 ...
- GIT_服务器与本地环境构建
linux安装git包 很多yum源上自动安装的git版本为1.7,这里手动编译重新安装1:安装依赖包yum install curl-devel expat-devel gettext-devel ...
- 归并排序Merge Sort
//C语言实现 void mergeSort(int array[],int first, int last) { if (first < last)//拆分数列中元素只剩下两个的时候,不再拆分 ...
- iOS实现微信外部H5支付完成后返回原APP
看到微信最近放开了微信H5支付,公司决定把H5集成到多款APP上.下面记录下了开发过程. 由于是微信新推出的支付方式,在网上搜索到的相关资料并不多,其中有一篇文件(点此跳转)对我的整个开发过程起到了很 ...
- Dynamics 365 Online-多选域
参与过Dynamics CRM相关工作的朋友们都知道,Dynamics 365之前并没有多选域字段,想要实现多选域,需要自己添加WebResource定制,而这也带来了一系列需要考虑的情况,比如额外的 ...
- EntityFramework Core 2.0执行原始查询如何防止SQL注入?
前言 接下来一段时间我们来讲讲EntityFramework Core基础,精简的内容,深入浅出,希望为想学习EntityFramework Core的童鞋提供一点帮助. EntityFramewor ...
- Sping Boot入门到实战之入门篇(二):第一个Spring Boot应用
该篇为Spring Boot入门到实战系列入门篇的第二篇.介绍创建Spring Boot应用的几种方法. Spring Boot应用可以通过如下三种方法创建: 通过 https://start.spr ...
- GCD实现倒计时
之前面试中,好多面试官,问使用GCD如何实现倒计时,我当时也没写过,所以一时不知道怎么说,所以结束之后,我实现一下GCD的倒计时. - (void)startTime:(UIButton *)send ...
- jsp去除空行的web.xml配置
在jsp中我们引入的标签,例如jstl的标签,循环遍历等等,可能会产生很多空行,其实也没什么,不会影响展示,但是空行多多少少会影响性能,这是我们只需要在web.xml中配置一下我们就可以很简单的去掉, ...