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 ...
随机推荐
- mybatis批量更新update-设置多个字段值allowMultiQueries=true
mybatis由于简单易用性得到大家的认可和使用 但是在批量更新操作中,网上介绍的貌似不全,正好今天做个记录,大家一起进步 在实际项目开发过程中,常有这样的需求:根据ids更新表的某一个字段值,这时的 ...
- Go语言中的数组(九)
我刚接触go语言的数组时,有点不习惯,因为相对于JavaScript这样的动态语言里的数组,go语言的数组写起来有点不爽. 定义数组 go语言定义数组的格式如下: ]int var 数组名 [数组长度 ...
- CF171C 【A Piece of Cake】
遵从题意枚举暴力读人n,再求出$\sum^n_1a[i]*i$然后输出答案,(记得开个long long以免炸掉)以下是代码: #include<bits/stdc++.h> using ...
- 3d旋转焦点图
在线演示 本地下载
- Max History CodeForces - 938E (组合计数)
You are given an array a of length n. We define fa the following way: Initially fa = 0, M = 1; for e ...
- Intellij idea启动项目提示"ClassNotFoundException"
引用至Intellij IDEA 启动项目ClassNotFoundException 使用Intellij IDEA的过程中,新创建的项目启动时报 严重: Error configuring app ...
- 第二章 单表查询 T-SQL语言基础(1)
单表查询(1) 本章:逻辑查询处理,特定的SELECT查询生成正确的结果集而要经历的一系列逻辑阶段;单表查询的其他方面,包括:运算符,空值(NULL),字符的处理和临时数据,分级(ranking),C ...
- 第一章 T-SQL查询和编程基础 T-SQL语言基础(1)
T-SQL查询和编程基础(1) 1.1 理论背景 SQL是为查询和管理关系型数据库管理系统(RDBMS)中的数据而专门设计的一种标准语言. RDBMS是一种基于关系模型的数据库管理系统,关系模型则是一 ...
- openCV3测试指南
本文来源于https://docs.opencv.org/3.4.1/db/df5/tutorial_linux_gcc_cmake.html 经测试整理后发布 上一节安装完成了openCV,这一节进 ...
- c++MMMMM:oo
1.union,struct和class的区别