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 ...
随机推荐
- 将PostgreSQL数据库的表导入到elasticsearch中
1.查看PostgreSQL表结构和数据信息 edbstore=# \d customers Table "edbstore.customers" Column | Type | ...
- python之cookies
#cookies保存在文档头的内部,将cookies信息保存在文档中 userinfo={'} r=requests.get('http://httpbin.org/get',cookies=user ...
- 十进制快速幂(牛客多校第五场)-- generator 1
思路: 十进制快速幂. #include <stdio.h>//sprintf #include <cstdlib>////malloc exit strcat itoa sy ...
- CSS(上)
目录 CSS(上) 什么是CSS? CSS的优点 CSS的引入方式 行内样式 内部样式 外部样式 CSS的两大特性 CSS选择器 基本选择器 组合选择器 更多选择器 选择器的优先级 CSS(上) 什么 ...
- leecode刷题(24)-- 翻转二叉树
leecode刷题(24)-- 翻转二叉树 翻转二叉树 翻转一棵二叉树. 示例: 输入: 4 / \ 2 7 / \ / \ 1 3 6 9 输出: 4 / \ 7 2 / \ / \ 9 6 3 1 ...
- C# 面向对象2 (类的语法)
1.类 语法: [public] class 类名 { 字段; 属性; 方法; } **类名首字母必须大写 2.创建对象 创建这个类的对象过程称之为类的实例化,关键字:new this:表示当前这个类 ...
- @babel/traverse 使用方法小记
@babel/traverse 官网: https://babeljs.io/docs/en/babel-traverse github:https://github.com/babel/babel/ ...
- 使输入框(input & textarea)变为只可读状态readonly="readonly",禁用输入框disabled="disabled"
使输入框变为只可读状态 readonly="readonly" <input class="select-city" placeholder=" ...
- dubbo学习笔记四(异步调用)
相关资料 官方文档 项目结构 代码示例 [EchoTestApp] @RestController @SpringBootApplication @ImportResource("class ...
- 转pip更新后ImportError: cannot import name ‘main'
更新pip后,报出:ImportError: cannot import name ‘main' 根据https://www.cnblogs.com/dylan9/p/8981155.html的教程进 ...