Gym - 100345H Settling the Universe Up(bitset)
https://vjudge.net/problem/Gym-100345H
题意:
给出一个图,求图中u能到达v的对数,并且u<v。并且会有更新和查询操作。
思路:
bitset直接暴力,对于每次更新操作之后,再重新计算一遍即可。bitset是真的强大啊!
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<int,int> pll;
const int INF = 0x3f3f3f3f;
const int maxn=+; int n, m;
int ans;
bitset<maxn> tmp[maxn],mp[maxn]; void solve()
{
ans=;
for(int i=;i<=n;i++) tmp[i].reset();
for(int i=n;i>=;i--)
{
tmp[i].set(i);
for(int j=;j<i;j++)
{
if(mp[j][i]) tmp[j]|=tmp[i];
}
ans+=tmp[i].count();
}
ans-=n; //减去自环
} int main()
{
//freopen("in.txt","r",stdin);
freopen("settling.in", "r", stdin);
freopen("settling.out", "w", stdout);
scanf("%d%d",&n,&m);
while(m--)
{
int u,v;
scanf("%d%d",&u,&v);
mp[u].set(v);
}
solve();
printf("%d\n",ans);
int t;
scanf("%d",&t);
while(t--)
{
char op[]; int u,v;
scanf("%s%d%d",op,&u,&v);
if(op[]=='?')
{
if(tmp[u][v]) puts("YES");
else puts("NO");
}
else if(op[]=='+')
{
mp[u].set(v);
solve();
printf("%d\n",ans);
}
else
{
mp[u].reset(v);
solve();
printf("%d\n",ans);
}
}
return ;
}
Gym - 100345H Settling the Universe Up(bitset)的更多相关文章
- 【CF1097F】Alex and a TV Show(bitset)
[CF1097F]Alex and a TV Show(bitset) 题面 洛谷 CF 题解 首先模\(2\)意义下用\(bitset\)很明显了. 那么问题在于怎么处理那个\(gcd\)操作. 然 ...
- Codeforces Gym 101142C:CodeCoder vs TopForces(搜索)
http://codeforces.com/gym/101142/attachments 题意:每个人在TC和CF上分别有两个排名,如果有一个人在任意一个网站上大于另一个人的排名,那么这个人可以打败另 ...
- 3687: 简单题(bitset)
3687: 简单题 Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 700 Solved: 319[Submit][Status][Discuss] ...
- [Bzoj5285][洛谷P4424][HNOI/AHOI2018]寻宝游戏(bitset)
P4424 [HNOI/AHOI2018]寻宝游戏 某大学每年都会有一次Mystery Hunt的活动,玩家需要根据设置的线索解谜,找到宝藏的位置,前一年获胜的队伍可以获得这一年出题的机会. 作为新生 ...
- 【科技】位运算(bitset)优化最长公共子序列算法
最长公共子序列(LCS)问题 你有两个字符串 \(A,B\),字符集为 \(\Sigma\),求 \(A, B\) 的最长公共子序列. 简单动态规划 首先有一个广为人知的 dp:\(f_{i,j}\) ...
- Atcoder Regular Contst 084 D - XorShift(bitset)
洛谷题面传送门 & Atcoder 题面传送门 没错,这就是 Small Multiple 那场的 F,显然这种思维题对我来说都是不可做题/cg/cg/cg 首先如果我们把每个二进制数看作一个 ...
- codeforce Gym 100342J Triatrip (bitset)
傻逼题,但是为什么别人的O(n^3)不会T?只是因为用了bitset优化... 附上一张bitset基本操作的表 #include<bits/stdc++.h> using namespa ...
- GYM 101128 G.Game of Cards(博弈论) 或者 UVALIVE 7278
题目链接:http://codeforces.com/gym/101128/my 如果可以,就看这个人的代码吧,我还不是很懂唉:http://blog.csdn.net/loy_184548/arti ...
- Codeforces 333E Summer Earnings(bitset)
题目链接 Summer Earnings 类似MST_Kruskal的做法,连边后sort. 然后对于每条边,依次处理下来,当发现存在三角形时即停止.(具体细节见代码) 答案即为发现三角形时当前所在边 ...
随机推荐
- Core Data with Mantle
Mantle makes it easy to write a simple model layer for your Cocoa or Cocoa Touch application. Mantl ...
- google浏览器mac上跨域问题解决
open -n /Applications/Google\ Chrome.app/ --args --disable-web-security --user-data-dir=/Users/ /Use ...
- npm设置淘宝镜像
npm config set registry https://registry.npm.taobao.org --global npm config set disturl https://npm. ...
- PHP开发接口使用RSA进行加密解密方法
网络安全问题很重要,尤其是保证数据安全,遇到很多在写接口的程序员直接都是明文数据传输,在我看来这是很不专业的.本人提倡经过接口的数据都要进行加密解密之后进行使用. 这篇文章主要介绍使用PHP开发接口, ...
- IO操作文件的复制与删除
import java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.IO ...
- PAT 1040 Longest Symmetric String[dp][难]
1040 Longest Symmetric String (25)(25 分) Given a string, you are supposed to output the length of th ...
- (转载)【cocos2dx 3.x Lua] 注册事件函数详解
出处: http://www.2cto.com/kf/201409/338235.html coocs2dx 版本 3.1.1 registerScriptTouchHandler 注册触屏事件 re ...
- ubuntu vim python配置
参考https://www.cnblogs.com/cjy15639731813/p/5886158.html 但是后面打开文件的时候会报错,参考https://blog.csdn.net/jeff_ ...
- L1正则化和L2正则化
L1正则化可以产生稀疏权值矩阵,即产生一个稀疏模型,可以用于特征选择 L2正则化可以防止模型过拟合(overfitting):一定程度上,L1也可以防止过拟合 一.L1正则化 1.L1正则化 需注意, ...
- Q_UNUSED
Q_UNUSED() 没有实质性的作用,用来避免编译器警告 void func( int a) { Q_UNUSED(a); //函数体内没有使用a,避免编译器警告 }