Permutations CodeForces - 736D (矩阵逆)
对于删除每个对(x,y), 可以发现他对答案的贡献为代数余子式$A_{xy}$
复习了一下线代后发现代数余子式可以通过伴随矩阵求出, 即$A_{xy}=A^*[y][x]$, 伴随矩阵$A^*=|A|A^{-1}$可以通过高斯消元$O(\frac{n^3}{\omega})$求出
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <string.h>
#include <bitset>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
//head const int N = 2010;
bitset<2*N> g[N];
int x[N*N], y[N*N], n, m; int main() {
scanf("%d%d", &n, &m);
REP(i,1,n) g[i][i+n]=1;
REP(i,1,m) {
scanf("%d%d", x+i, y+i);
g[x[i]][y[i]]=1;
}
REP(i,1,n) {
REP(j,i,n) if (g[j][i]) {swap(g[i],g[j]);break;}
REP(j,1,n) if (j!=i&&g[j][i]) g[j]^=g[i];
}
REP(i,1,m) puts(g[y[i]][x[i]+n]?"NO":"YES");
}
Permutations CodeForces - 736D (矩阵逆)的更多相关文章
- Petr and Permutations CodeForces - 987E(逆序对)
题意: 给出一个长度为n的序列,求出是谁操作的(原序列为从小到大的序列),Peter的操作次数为3n,Alex的操作次数为7n+1 解析: 我们来看这个序列中的逆序对,逆序对的个数为偶数则操作次数为偶 ...
- CodeForces 450B 矩阵
A - Jzzhu and Sequences Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & ...
- codeforces 691E 矩阵快速幂+dp
传送门:https://codeforces.com/contest/691/problem/E 题意:给定长度为n的序列,从序列中选择k个数(可以重复选择),使得得到的排列满足xi与xi+1异或的二 ...
- Xor-sequences CodeForces - 691E || 矩阵快速幂
Xor-sequences CodeForces - 691E 题意:在有n个数的数列中选k个数(可以重复选,可以不按顺序)形成一个数列,使得任意相邻两个数异或的结果转换成二进制后其中1的个数是三的倍 ...
- Educational Codeforces Round 32 Almost Identity Permutations CodeForces - 888D (组合数学)
A permutation p of size n is an array such that every integer from 1 to n occurs exactly once in thi ...
- Codeforces 907 矩阵编号不相邻构造 团操作状压DFS
A. #include <bits/stdc++.h> #define PI acos(-1.0) #define mem(a,b) memset((a),b,sizeof(a)) #de ...
- Codeforces 400C 矩阵乘法 数学规律
今天下午Virtual了一套最近的CF题,第三题给TLE了,就跑过去上课了. 这题给定一个由二进制表示的矩阵,当询问3的时候,求矩阵的值,矩阵的值是所有第i行乘以第i列的值的总和,然后还有1 b是翻转 ...
- 4 多表代替密码之Hill 密码_1 矩阵工具类
在说明Hill加密之前要先复习线性代数的知识,主要是关于矩阵的一些运算和概念. 一.矩阵的逆: 定义方阵M的逆矩阵应该满足M*M^-1==I,其中I是单位矩阵,比如: 但是这个地方是对英文字母进行加密 ...
- 3D数学 矩阵常用知识点整理
1.矩阵了解 1)矩阵的维度和记法 (先数多少行,再数多少列) 2)矩阵的转置 行变成列,第一行变成第一列...矩阵的转置的转置就是原矩阵 即 3)矩阵和标量的乘法 ...
随机推荐
- <Python>判断变量是否是DataFrame 或者 Series
https://stackoverflow.com/questions/14808945/check-if-variable-is-dataframe Use the built-in isinsta ...
- p1654 OSU!
期望DP 设\(g[i]\)表示前i个的连续1的期望长度,\(h[i]\)表示前i个连续1的长度的平方的期望,\(f[i]\)表示前i个的期望得分 由期望的线性性质,我们可以考虑统计新增一个对答案的贡 ...
- (转)Awesome PyTorch List
Awesome-Pytorch-list 2018-08-10 09:25:16 This blog is copied from: https://github.com/Epsilon-Lee/Aw ...
- Component 组件props 属性设置
props定义属性并获取属性值 html <div id="app"> <!-- 注册一个全局逐渐 --> <!-- 注意如果自定义的属性带-像下面这 ...
- vue中find函数
let obj = this.role.find(v => v.code === res.company.role)循环 data对象中的role数组 ,每个数组元素用v代替,code为他的键, ...
- facebook api之Business Manager API
Business-scoped Users - The new user is tied to a particular business and has permissions scoped to ...
- SAP按销售订单生产和标准结算配置及操作手册
SAP按销售订单生产和标准结算配置及操作手册 http://blog.sina.com.cn/s/blog_6787c0b80101a3tl.html SAP按销售订单生产和标准结算配置及操作手册 S ...
- oracle 新建用户
create user username identified by password; grant dba to username; 授权 或 grant connect, resource to ...
- Centos6.8安装nginx(一)
在这里对nginx的安装简单的做个记录,后续有时间的话在详细补充. 1.yum安装g++: yum install -y gcc gcc-c++ [enter] 2.下载必需的依赖库:zlib(为了g ...
- javascript 获得以秒计的视频时长
<!DOCTYPE html> <html> <body> <h3>演示如何访问 VIDEO 元素</h3> <video id=&q ...