双元素非递增(容斥)--Number Of Permutations Educational Codeforces Round 71 (Rated for Div. 2)
题意:https://codeforc.es/contest/1207/problem/D
n个元素,每个元素有a、b两个属性,问你n个元素的a序列和b序列有多少种排序方法使他们不同时非递减(不同时good)。
思路:
真难则反+容斥,反向考虑,ans1=如果a序列非递减则有a中各个数字出现次数的阶乘的乘积个,ans2=b序列也是一样。
ans3=然后还要减去a序列和b序列都是good的方案数,就是元素相同的出现次数阶乘的乘积(注意,如果不存在双good就不算ans3)。
ANS就是:全排列 - ans1 - ans2 + ans3
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#include <cstdio>//sprintf islower isupper
#include <cstdlib>//malloc exit strcat itoa system("cls")
#include <iostream>//pair
#include <fstream>//freopen("C:\\Users\\13606\\Desktop\\草稿.txt","r",stdin);
#include <bitset>
#include <map>
//#include<unordered_map>
#include <vector>
#include <stack>
#include <set>
#include <string.h>//strstr substr
#include <string>
#include <time.h>//srand(((unsigned)time(NULL))); Seed n=rand()%10 - 0~9;
#include <cmath>
#include <deque>
#include <queue>//priority_queue<int, vector<int>, greater<int> > q;//less
#include <vector>//emplace_back
//#include <math.h>
//#include <windows.h>//reverse(a,a+len);// ~ ! ~ ! floor
#include <algorithm>//sort + unique : sz=unique(b+1,b+n+1)-(b+1);+nth_element(first, nth, last, compare)
using namespace std;//next_permutation(a+1,a+1+n);//prev_permutation
#define fo(a,b,c) for(register long long a=b;a<=c;++a)
#define fr(a,b,c) for(register int a=b;a>=c;--a)
#define mem(a,b) memset(a,b,sizeof(a))
#define pr printf
#define sc scanf
#define ls rt<<1
#define rs rt<<1|1
typedef long long ll;
void swapp(int &a,int &b);
double fabss(double a);
int maxx(int a,int b);
int minn(int a,int b);
int Del_bit_1(int n);
int lowbit(int n);
int abss(int a);
//const long long INF=(1LL<<60);
const double E=2.718281828;
const double PI=acos(-1.0);
const int inf=(<<);
const double ESP=1e-;
const int mod=(int);
const int N=(int)1e6+; ll a[N],b[N];
pair<ll,ll>s[N];
map<pair<ll,ll>,ll>mp3;
map<ll,ll> mp1,mp2; ll v(ll x)
{
ll sum=;
fo(i,,x)
sum*=i,sum%=mod;
return sum;
} int main()
{
int n;
ll ans=,temp1,temp2,temp3;
sc("%d",&n);
fo(i,,n)ans*=i,ans%=mod,sc("%lld%lld",&a[i],&b[i]),mp1[a[i]]++,mp2[b[i]]++,s[i]={a[i],b[i]},mp3[s[i]]++;
temp1=temp2=temp3=;
for(auto i:mp1)
temp1*=v(i.second),temp1%=mod;
for(auto i:mp2)
temp2*=v(i.second),temp2%=mod;
for(auto i:mp3)
temp3*=v(i.second),temp3%=mod;
sort(s+,s++n);
for(int i=;i<n;++i)
if(s[i].second>s[i+].second)
temp3=;
pr("%lld\n",((ans-temp1-temp2+temp3)%mod+mod)%mod);
return ;
} /**************************************************************************************/ int maxx(int a,int b)
{
return a>b?a:b;
} void swapp(int &a,int &b)
{
a^=b^=a^=b;
} int lowbit(int n)
{
return n&(-n);
} int Del_bit_1(int n)
{
return n&(n-);
} int abss(int a)
{
return a>?a:-a;
} double fabss(double a)
{
return a>?a:-a;
} int minn(int a,int b)
{
return a<b?a:b;
}
双元素非递增(容斥)--Number Of Permutations Educational Codeforces Round 71 (Rated for Div. 2)的更多相关文章
- Educational Codeforces Round 50 (Rated for Div. 2) F - Relatively Prime Powers(数学+容斥)
题目链接:http://codeforces.com/contest/1036/problem/F 题意: 题解:求在[2,n]中,x != a ^ b(b >= 2 即为gcd)的个数,那么实 ...
- Educational Codeforces Round 65 (Rated for Div. 2) A. Telephone Number
链接:https://codeforces.com/contest/1167/problem/A 题意: A telephone number is a sequence of exactly 11 ...
- Educational Codeforces Round 97 (Rated for Div. 2) E. Make It Increasing(最长非下降子序列)
题目链接:https://codeforces.com/contest/1437/problem/E 题意 给出一个大小为 \(n\) 的数组 \(a\) 和一个下标数组 \(b\),每次操作可以选择 ...
- Educational Codeforces Round 39 (Rated for Div. 2) 946E E. Largest Beautiful Number
题: OvO http://codeforces.com/contest/946/problem/E CF 946E 解: 记读入串为 s ,答案串为 ans,记读入串长度为 len,下标从 1 开始 ...
- Educational Codeforces Round 37 G. List Of Integers (二分,容斥定律,数论)
G. List Of Integers time limit per test 5 seconds memory limit per test 256 megabytes input standard ...
- Educational Codeforces Round 7 D. Optimal Number Permutation 构造题
D. Optimal Number Permutation 题目连接: http://www.codeforces.com/contest/622/problem/D Description You ...
- Educational Codeforces Round 11 D. Number of Parallelograms 暴力
D. Number of Parallelograms 题目连接: http://www.codeforces.com/contest/660/problem/D Description You ar ...
- B. The Number of Products(Codeforces Round #585 (Div. 2))
本题地址: https://codeforces.com/contest/1215/problem/B 本场比赛A题题解:https://www.cnblogs.com/liyexin/p/11535 ...
- 2015 asia xian regional F Color (容斥 + 组合数学)
2015 asia xian regional F Color (容斥 + 组合数学) 题目链接http://codeforces.com/gym/100548/attachments Descrip ...
随机推荐
- bootstrap单选框复选框的使用
<form role="form"> <div class="form-group"> <label class="ch ...
- ast.literal_eval(转)
eval函数在Python中做数据类型的转换还是很有用的.它的作用就是把数据还原成它本身或者是能够转化成的数据类型.那么eval和ast.literal_val()的区别是什么呢?本文将大家介绍关于P ...
- 【黑马JavaSE】1_1_11_IDEA、12_方法、13_重载
文章目录 1_1_11_01开发工具IntelliJ IDEA 1.3 创建包.查看包的目录结构 1.5 字体设置(File->Settings->Editor->Font) 1.6 ...
- oracle查看表空间的大小及使用情况sql语句
--------------------------tablespace------------------------------------------------ 1.//查看表空间的名称及大小 ...
- OpenCV学习笔记(15)——更多的轮廓函数
凸缺陷,以及如何找到凸缺陷 找某一点到一个多边形的最短距离 不同形状的匹配 1.凸缺陷 前面已经设计了轮廓的凸包和凸性缺陷的概念.OpenCV中有一个函数cv2.convexityDefect()可以 ...
- System 源码阅读
System 属性说明 /** * System 类包含了几个有用的字段和方法,并且不能被实例化. * * @author unascribed * @since 1.0 */ public fina ...
- C++中的各种容器实现原理
C++ 容器及选用总结 vector 拥有一段连续的内存空间 list 就是数据结构中的双向链表 deque 的动态数组首尾都开放 set 有序的容器,红黑树的平衡二叉检索树的数据结构 multise ...
- RNN 与 LSTM 的原理详解
原文地址:https://blog.csdn.net/happyrocking/article/details/83657993 RNN(Recurrent Neural Network)是一类用于处 ...
- javascript之注册事件
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- Android studio 自动导入(全部)包 import (转)
原文: https://blog.csdn.net/buaaroid/article/details/44979629 1. Android studio 只有import单个包的快捷键:A ...