双元素非递增(容斥)--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 ...
随机推荐
- Composer 安装 zlib_decode(): data error 错误
1.composer 安装一个组件(composer require topthink/think-worker) 报错如下 Failed to decode response: zlib_decod ...
- Java多线程-程序运行堆栈分析
class文件内容 class文件包含JAVA程序执行的字节码:数据严格按照格式紧凑排列在class文件中的二进制流,中间无任何分隔符:文件开头有一个0xcafebabe(16进制)特殊的一个标志. ...
- flask登录功能实现的思路
flask登录实现过程思路:前端创建表单,post方法,userno,pwd参数 后端首先创建登录验证函数check(验证函数是指通过request.get来获取前端的userno,pwd.然后将两个 ...
- 【软件工程】Alpha冲刺(1/6)
链接部分 队名:女生都队 组长博客: 博客链接 作业博客:博客链接 小组内容 恩泽(组长) 过去两天完成了哪些任务 描述 了解了反馈机制的实现原理 确定好算法的框架 对接口的规范化进行学习 展示Git ...
- How to Fix Grub error: no such partition Grub Rescue
错误信息: error: no such partition Entering rescue mode... grub rescue> _ 错误原因: grub找不到文件normal.mod 解 ...
- ubuntu下apt-get 命令参数
转载:https://blog.csdn.net/linuxzhouying/article/details/7192612 ubuntu下apt-get 命令参数 常用的APT命令参数 apt-ca ...
- 用 dnSpy 反编译调试 .NET 程序
dnSpy 官网下载:https://github.com/0xd4d/dnSpy/releases 运行需要 .NET Framework 4 环境:https://dotnet.microsoft ...
- 配置文件中间件:config-lite
config-lite 是一个轻量的读取配置文件的模块. config-lite 会根据环境变量(NODE_ENV)的不同从当前执行进程目录下的 config 目录加载不同的配置文件. 如果不设置 N ...
- python3将汉字转换为大写拼音首字母
利用pypinyin包 实现 import pypinyin a = pypinyin.pinyin('你好世界', style=pypinyin.FIRST_LETTER) b = [] for i ...
- 《Javascript 语言精粹》 中 用到的一些代码 (1)
var isNumber = function isNumber(value){ return typeof value === 'number' && isFinite(value) ...