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. 然后对于每条边,依次处理下来,当发现存在三角形时即停止.(具体细节见代码) 答案即为发现三角形时当前所在边 ...
随机推荐
- [vue]vue条件渲染v-if(template)和自定义指令directives
条件渲染: v-if/template <div id="app"> <h1>v-show: display: none</h1> <di ...
- [py]面向对象图解assignment
python的chained assignment 在python中 a is b is c 等价于 a is b and b is c 所以,猜猜 False is False is False # ...
- tf.nn.embedding_lookup函数的用法
关于np.random.RandomState.np.random.rand.np.random.random.np.random_sample参考https://blog.csdn.net/lanc ...
- Andrew Ng-ML-第九&十章-神经网络
1.神经网络模型1 图1 这是一个神经网络的模型,通常设置一个x0,作为偏执单元或者偏置(bias)神经元. 图2 这里最后一句话,说的是系数矩阵θ,神经网络模型中,如果当前在j层有s_j个单元,在j ...
- iOS设计规范HIG
点击图标大小至少为这么大: Make it easy for people to interact with content and controls by giving each interacti ...
- Pandas之Dropna滤除缺失数据
import pandas as pd import numpy as np from numpy import nan as NaN 一.处理Series对象 通过dropna()滤除缺失数据 fr ...
- JQuery中如何使用事件来出发Ajax
$(document).ready(function(){ $("input[name='customer_name']").keydown(func ...
- linux rz sz
对于经常使用Linux系统的人员来说,少不了将本地的文件上传到服务器或者从服务器上下载文件到本地,rz / sz命令很方便的帮我们实现了这个功能,但是很多Linux系统初始并没有这两个命令.今天,我们 ...
- webpack 3 & React 的配置 。
今天真是难过的一天
- MacaW Baby Learns Computer
A - Macaw Baby Learns Computer Time Limit:1000MS Memory Limit:0KB 64bit IO Format:%lld & ...