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)矩阵和标量的乘法 ...
随机推荐
- Module controller in JMeter
https://qualibrate.com/blog/quality-assurance/jmeter-module-controller/ 通过组合Test Fragments 和Module C ...
- What are the differences between Flyweight and Object Pool patterns?
What are the differences between Flyweight and Object Pool patterns? They differ in the way they are ...
- Run tomcat on port 80 not 8080
How to run Tomcat on Port 80 A standard Tomcat installation starts the webserver on port 8080 – whic ...
- Hbase与Oracle比较(列式数据库与行式数据库)
Hbase与Oracle比较(列式数据库与行式数据库) 1 主要区别 Hbase适合大量插入同时又有读的情况 Hbase的瓶颈是硬盘传输速度,Oracle的瓶颈是硬盘寻道时间. Hbase本质上只 ...
- facebook api之Ad
Ad Contains information to display an ad and associate it an ad set. Each ad is associated with an a ...
- 【译】第14节---数据注解-MaxLength/MinLength
原文:http://www.entityframeworktutorial.net/code-first/maxlength-minlength-dataannotations-attribute-i ...
- HDU 5985 Lucky Coins(概率)
http://acm.split.hdu.edu.cn/showproblem.php?pid=5985 题意:有多种类型的硬币,每种类型的硬币都有一定的数量,现在每次抛硬币,除去朝下的硬币,知道最后 ...
- Ajax - 发送请求原理
1,什么是ajax? Asynchronous JavaScript and XML(当然现在xml已经由json代替): 主要是用于前后台的交互(表单提交已经被废弃): 使用场景:前台获取数据.表单 ...
- File操作-将数据库里的数据写入到指定路径的txt文件里
package com.Cristin.File;//将数据库里的数据写入到指定路径的txt文件里 import java.io.File;import java.io.FileOutputStrea ...
- wow.js
一.首先说明一下怎么使用这个插件: 1.wow.js依赖于animate.css,首先在头部引用animate.css或者animate.min.css. <link rel="sty ...