CF D. Number Of Permutations 排列
挺水的一道题~
拿全排列随便乘一下就好了.
#include <cstdio>
#include <algorithm>
#define N 300004
#define ll long long
#define mod 998244353
#define setIO(s) freopen(s".in","r",stdin)
using namespace std;
struct Node {
int a,b;
}t[N];
ll fac[N];
bool cmp1(Node a,Node b) {
return a.a==b.a?a.b<b.b:a.a<b.a;
}
bool cmp2(Node a,Node b) {
return a.b==b.b?a.a<b.a:a.b<b.b;
}
int main() {
int i,j,n;
ll tot1=1,tot2=1,tot3=1;
// setIO("input");
fac[0]=1;
for(i=1;i<N;++i) fac[i]=1ll*fac[i-1]*i%mod;
scanf("%d",&n);
for(i=1;i<=n;++i) scanf("%d%d",&t[i].a,&t[i].b);
sort(t+1,t+1+n,cmp1);
for(i=1;i<=n;i=j) {
for(j=i;j<=n&&t[j].a==t[i].a;++j);
tot1=tot1*fac[j-i]%mod;
}
sort(t+1,t+1+n,cmp2);
for(i=1;i<=n;i=j) {
for(j=i;j<=n&&t[j].b==t[i].b;++j);
tot2=tot2*fac[j-i]%mod;
}
int flag=0;
for(i=2;i<=n;++i) if(t[i].a<t[i-1].a) flag=1;
if(flag) printf("%I64d\n",(fac[n]-(tot1+tot2)%mod+mod)%mod);
else {
for(i=1;i<=n;i=j) {
for(j=i;j<=n&&t[j].a==t[i].a&&t[j].b==t[i].b;++j);
tot3=tot3*fac[j-i]%mod;
}
printf("%I64d\n",(fac[n]-(tot1+tot2-tot3+mod)%mod+mod)%mod);
}
return 0;
}
CF D. Number Of Permutations 排列的更多相关文章
- D. Number Of Permutations 符合条件的排列种类
D. Number Of Permutations time limit per test 2 seconds memory limit per test 256 megabytes input st ...
- Number Of Permutations
Number Of Permutations 思路:利用容斥,首先所有可能的排列肯定是fac[n],然后可能会有三种 bad 的情况: ①第一个元素的排列是非递减 ②第二种是第二个元素的排列是非递减 ...
- 46. Permutations 排列数
46. Permutations 题目 Given a collection of distinct numbers, return all possible permutations. For ex ...
- 【LeetCode每天一题】Permutations(排列组合)
Given a collection of distinct integers, return all possible permutations. Example: Input: [1,2,3] O ...
- Codeforces G. Bus Number(dfs排列)
题目描述: Bus Number time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- CF 463D Gargari and Permutations [dp]
给出一个长为n的数列的k个排列(1 ≤ n ≤ 1000; 2 ≤ k ≤ 5).求这个k个数列的最长公共子序列的长度 dp[i]=max{dp[j]+1,where j<i 且j,i相应的字符 ...
- 【题解】CF#285 E-Positions in Permutations
挺有收获的一道题ヾ(◍°∇°◍)ノ゙ 恰好为 m ,这个限制仿佛不是很好处理.一般而言,我所了解的恰好为 k 的条件,不是用组合数 / dp状态转移 / 斜率二分就只剩下容斥了.我们可以先处理出 nu ...
- 1207D Number Of Permutations
题目大意 给你n个二元组 问你有几种排列是的按两个关键字中的任意一个都不是不降排列的 分析 不妨容斥 我们先加上总的方案数$n!$ 之后我们按第一个关键字排序 因为值相同的情况下不影响答案 所以让总方 ...
- cf B. Number Busters
http://codeforces.com/contest/382/problem/B 题意:给你Aa,b,w,x,c,然后每经过1秒,c=c-1; 如果b>=x,b=b-x;否则 a=a-1 ...
随机推荐
- vue组件添加事件@click.native
1,给vue组件绑定事件时候,必须加上native ,否则会认为监听的是来自Item组件自定义的事件 2,等同于在子组件中: 子组件内部处理click事件然后向外发送click事件:$emit(&q ...
- python computer info look
计算机信息查看-. import platform import platform def TestPlatform(): print("---------SYSTEM INFO------ ...
- JAVA重载和数组
Java 重载:相同的方法名,但参数个数或者类型不一样的情况下,自动执行不同的方法 数组: int[] array=new int[5]; System.out.println(array); ...
- Constructing Tests CodeForces - 938C
大意: 定义m-free矩阵: 所有$m*m$的子矩阵至少有一个$0$的$01$矩阵. 定义一个函数$f(n,m)=n*n$的m-free矩阵最大$1$的个数. 给出$t$个询问, 每个询问给出$x$ ...
- Java后端技术面试汇总(第四套)
1.Java基础 • 为什么JVM调优经常会将-Xms和-Xmx参数设置成一样:• Java线程池的核心属性以及处理流程:• Java内存模型,方法区存什么:• CMS垃圾回收过程:• Full GC ...
- O007、KVM 存储虚拟化
参考https://www.cnblogs.com/CloudMan6/p/5273283.html KVM 的存储虚拟化是通过存储池(Storage Pool) 和 卷(Volume)来管理的. ...
- js的作用主要这么几个
js的作用主要有这么几个表单验证:网页上,用户输入的信息需要进行验证,在客户端验证,可以减少对服务器端的压力.所以,你应该把握正则表达式方面的知识.网页特效:页面上很多特效是非常好的,能产生很好的用户 ...
- vue项目-axios封装、easy-mock使用
vue全家桶概括下来就是 项目构建工具(vue-cli) 路由(vue-router) 状态管理(vuex) http请求工具 vue有自己的http请求工具插件vue-resource,但是vue2 ...
- C#中实现Hash应用
在C#中,数据的Hash以MD5或SHA1的方式实现,MD5与SHA1都是Hash算法,MD5输出是128位的,SHA1输出是160位的,MD5比SHA1快,SHA1比MD5强度高. 1.1 SHA- ...
- arcgis 地图如何转到supermap平台
场景:客户使用arcmap配置好的地图数据,由于项目需要转换到超图平台.有如下几种思路供参考. 1. 使用arcmap生成地图缓存,supermap-iServer支持发布arcgis的地图缓存以及t ...