Codeforces Gym 100345H Settling the Universe Up Bitset+倒推
来源:互联网 发布:七月算法视频pan 编辑:程序博客网 时间:2024/05/21 15:43
题目大意:
给一个只从标号小的点向标号大的点连边的有向图(n<=200)。有如下几种操作:
? u v(询问u能否到v)
+ u v (加一条u到v的边)
- u v (删除u到v的边)
以上操作保证u < v,且合法。在操作之前需要给出有多少对(u,v)能够到达,在每次+和-的操作后也要回答上面的问题。
操作数<=100 000,修改操作<=1000
做法:
- 用bitset维护每个点能到的点
- 对于每一次?操作可以
O(1) 回答 - 对于每一次修改操作从后往前推暴力重构bitset并统计答案,时间复杂度
O((n+m)∗n)
代码:
#include <bits/stdc++.h>using namespace std;const int maxn=202;set<int>g[maxn];set<int>::iterator it;bitset<maxn>b[maxn];char op[10];int n;int getans(){ int ans=0; for(int i=n;i>0;i--) { b[i].reset(); for(it=g[i].begin();it!=g[i].end();it++) { b[i].set(*it); b[i] |= b[*it]; } ans+=b[i].count(); } return ans;}//倒推暴力重构bitset int main(){ freopen("settling.in","r",stdin); freopen("settling.out","w",stdout); int m,t,u,v; scanf("%d%d",&n,&m); for(int i=0;i<m;i++) { scanf("%d%d",&u,&v); g[u].insert(v); } scanf("%d",&t); printf("%d\n",getans()); while(t--) { scanf("%s %d %d",op,&u,&v); if(op[0]=='?') printf("%s\n",(b[u][v])?("YES"):("NO")); else { if(op[0]=='+')g[u].insert(v);else if(op[0]=='-')g[u].erase(v); printf("%d\n",getans()); } } return 0;}
0 0
- Codeforces Gym 100345H Settling the Universe Up Bitset+倒推
- ACM bitset模板 Gym 100345H
- Gym 100342J & Gym 100345H (bitset在图论题的应用)
- bitset在图论上的应用 传递闭包【例题gym 100342J & gym 100345H 】
- codeforces GYM 100792H
- Codeforces Gym 100733H Designation in the Mafia flyod
- Codeforces Gym 100342J Triatrip Bitset+枚举
- 【Codeforces Gym】100162 H Temperature
- Codeforces Gym 100623H Problem H. Holes
- CodeForces Gym 100646H You’ll be Working on the Railroad
- Codeforces Gym 100548H The Problem to Make You Happy (图上博弈DP)
- Codeforces Gym 100342H Hard Test 构造
- CodeForces Gym 100989H Queue (A)
- Codeforces Gym 100962 H. Hans Zimmer
- [DP] Codeforces Gym 101002 H. Jewel Thief
- Codeforces Gym 101234H Split Game
- Gym 101028H-The Endless River
- CodeForces Gym 100646G The Worm Turns
- 通达OA破解版下载|通达OA2015破解版 可用|通达oa2015破解补丁
- 网络流之最大流(关于poj1273)
- Hibernate批量操作(JDBC批量操作)
- BestCoder Round #54
- Hibernate二级缓存 ---- 最佳实践
- Codeforces Gym 100345H Settling the Universe Up Bitset+倒推
- 云购吧 使用说明文档
- Java Convert String & Int
- 浅谈Activity的启动模式
- Hibernate二级缓存 ---- 入门示例
- ICPC 6834 Shopping
- windows下成功编译Cairo,Compiling Cairo for Windows
- Hibernate 操作Blob Clob
- android学习笔记(16)广播事件处理