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. 使用最小堆优化Dijkstra算法

    OJ5.2很简单,使用priority_queue实现了最小堆竟然都过了OJ……每次遇到relax的问题时都简单粗暴地重新push进一个节点…… 然而正确的实现应该是下面这样的吧,关键在于swap堆中 ...

  2. BZOJ 4516: [Sdoi2016]生成魔咒 [后缀自动机]

    4516: [Sdoi2016]生成魔咒 题意:询问一个字符串每个前缀有多少不同的子串 做了一下SDOI2016R1D2,题好水啊随便AK 强行开map上SAM 每个状态的贡献就是\(Max(s)-M ...

  3. POJ1556 The Doors [线段相交 DP]

    The Doors Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8334   Accepted: 3218 Descrip ...

  4. iis发布网站问题-由于权限不足而无法读取配置文件,无法访问请求的页面

    错误一: HTTP Error 500.19 - Internal Server Error 配置错误: 不能在此路径中使用此配置节.如果在父级别上锁定了该节,便会出现这种情况.锁定是默认设置的 (o ...

  5. flex 布局 input 宽度不自适应

    flex 布局 input 宽度不自适应 解决方法: 给 input 加上min-height 解决!

  6. 较复杂makefile跟lds脚本程序的编写

    首先看个makefile范例: /*指明工具链,并为其取个简单的别名*/ CC = arm-linux-gcc LD = arm-linux-ld AR = arm-linux-ar OBJCOPY ...

  7. Spring基础篇——通过Java注解和XML配置装配bean

    自动化装配的确有很大的便利性,但是却并不能适用在所有的应用场景,比如需要装配的组件类不是由自己的应用程序维护,而是引用了第三方的类库,这个时候自动装配便无法实现,Spring对此也提供了相应的解决方案 ...

  8. iOS字体名字

    上面我们提到我们需要设置字体集,在IOS系统中我们用到的字体包含一下几种 : Font Family: American Typewriter( AmericanTypewriter,American ...

  9. 使用EL表达式调用java方法

    首先,新建一个类,类中写一个静态方法 public class PrivilegeUtils { public static Boolean checkPrivilegeByName(User use ...

  10. Invoke 与 BeginInvoke 应用场景

    1.委托中 Invoke , BeginInvoke 特点 Invoke  : 同步调用 , 委托在当前线程执行 BeginInvoke : 异步调用 , 通常使用线程池资源执行委托. 2. UI  ...