题意: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)的更多相关文章

  1. 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)的个数,那么实 ...

  2. 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  ...

  3. Educational Codeforces Round 97 (Rated for Div. 2) E. Make It Increasing(最长非下降子序列)

    题目链接:https://codeforces.com/contest/1437/problem/E 题意 给出一个大小为 \(n\) 的数组 \(a\) 和一个下标数组 \(b\),每次操作可以选择 ...

  4. 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 开始 ...

  5. 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 ...

  6. Educational Codeforces Round 7 D. Optimal Number Permutation 构造题

    D. Optimal Number Permutation 题目连接: http://www.codeforces.com/contest/622/problem/D Description You ...

  7. Educational Codeforces Round 11 D. Number of Parallelograms 暴力

    D. Number of Parallelograms 题目连接: http://www.codeforces.com/contest/660/problem/D Description You ar ...

  8. 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 ...

  9. 2015 asia xian regional F Color (容斥 + 组合数学)

    2015 asia xian regional F Color (容斥 + 组合数学) 题目链接http://codeforces.com/gym/100548/attachments Descrip ...

随机推荐

  1. nagios监控部署

    nagios监控部署. 在部署之前把依赖包安装了. [root@tiandong63 ~]# yum install -y gcc glibc glibc-common php gd gd-devel ...

  2. OUC_Summer Training_ DIV2_#9 719

    其实自己只会做很简单的题,有时都不想写解题报告,觉得不值得一写,但是又想到今后也许就不会做ACM了,能留下来的东西只有解题报告了,所以要好好写,很渣的题也要写,是今后的纪念. B - B Time L ...

  3. HashMap三两事

    前言 JDK8中对HashMap做了优化,依然是用数组存储数据,但是扩容时采用双链表的方式避免了高并发情况下导致出现循环链表的问题,另外也引入了红黑树,提高碰撞元素的搜索速度. 一段代码 下面这段代码 ...

  4. LC 889. Construct Binary Tree from Preorder and Postorder Traversal

    Return any binary tree that matches the given preorder and postorder traversals. Values in the trave ...

  5. ValueStack对象

    ValueStack, 即值栈对象. 值栈对象: 是整个struts数据存储的核心,或者叫中转站. 用户每次访问struts的action,都会创建一个Action对象.值栈对象.ActionCont ...

  6. PreparedStatement执行sql語句

    import com.loaderman.util.JdbcUtil; import java.sql.Connection; import java.sql.PreparedStatement; i ...

  7. 【转】java导出多个excel表格,并压缩成zip输出

    转自:http://blog.csdn.net/qq_14861089/article/details/53169414    感谢作者分享 /** * 导出支付宝批量支付文件excel * * @p ...

  8. gitlab仓库的使用

    一.gitlab简介 gitlab是一个用于仓库管理系统的开源项目,使用git作为代码管理工具,并在此基础上搭建web服务. [管理命令] gitlab-ctl stop        gitlab- ...

  9. VMWare虚拟机->锁定文件失败,打不开磁盘的解决办法

    VMWare虚拟机提示:锁定文件失败,打不开磁盘的解决办法   如果使用VMWare虚拟机的时候突然系统崩溃蓝屏,有一定几率会导致无法启动,会提示:“锁定文件失败,打不开磁盘...或它所依赖的某个快照 ...

  10. iOS去除数组中重复的model数据

    // 去除数组中model重复 ; i < self.selectedModelArray.count; i++) { ;j < self.selectedModelArray.count ...