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 ...
随机推荐
- Dango之视图函数
1.request对象 HTTPRequest对象就是咱们的视图函数的参数request def home(request): print(request) #<WSGIRequest: GET ...
- MySQL中出现的小问题
./scripts/mysql_install_db: line 249: /app/mysql/bin/my_print_defaults: cannot execute binary fileNe ...
- sql server case when
case具有两种格式:简单Case函数和Case搜索函数 简单case函数 实例:CASE sex when '1' then '男' when '2' then'女' els ...
- 第二章 单表查询 T-SQL语言基础(2)
单表查询(2) 2.2 谓词和运算符 T-SQL有几种不同的语言元素可以指定逻辑表达式,例如,查询过滤器(WHERE和HAVING),CHECK约束,等等. 在逻辑表达式中可以使用各种谓词(取值为TR ...
- JavaScript冒泡排序法实现排序操作
var arr = [10,8,6,9,1,7,1,13,5,1,9]; //冒泡排序 function bubbleSort(tmpArr){ for(var i = tmpArr.length-1 ...
- postMessage解决iframe跨域问题
转:https://juejin.im/post/5b8359f351882542ba1dcc31 https://juejin.im/post/590c3983ac502e006531df11 ht ...
- dubbo学习笔记三(全注解)
完全用注解替换掉之前的部分配置文件 项目结构 下面给出服务的的部分代码 [DubboConfiguration] @Configuration @EnableDubbo(scanBasePackage ...
- 如何编写一个路由器的界面1-Luci开发入门
Howto:如何写Module(模块)-----------------这一部分主要是翻译github上的document 注意:如果您打算将模块加入LUCI整合之前,您应该阅读Module参考. 本 ...
- JS常用自定义函数总结
JS常用自定义函数总结 1.原生JavaScript实现字符串长度截取 2.原生JavaScript获取域名主机 3.原生JavaScript清除空格 4.原生JavaScript替换全部 5.原 ...
- Spring Boot【快速入门】简单案例
Spring Boot[快速入门] Spring Boot 概述 Build Anything with Spring Boot:Spring Boot is the starting point ...