双元素非递增(容斥)--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 ...
随机推荐
- Loooooooooooooooong time no see!
好久没来啦~去年这会一口气写了好多,是因为即将离职,在公司闲的没事,再加上也积累了一些东西想分享. 最近有个朋友给我私信求助,才又想起这里.这快一年时间,又学习了不少东西.从何写起呢,哈哈,不知道啊~ ...
- Android UI编程之自定义控件初步——ImageButton
我想我们在使用一些App的时候,应该不会出现一些“裸控件”的吧.除非是一些系统中的软件,那是为了保持风格的一致性,做出的一些权衡.我这里并非是在指责Android原生的控件不好看,说实在的,我很喜欢A ...
- 五、在事务中使用Mybatis缓存的那些坑
场景: 1.同一个事务中 2.使用mybatis执行同一个sql @Transactional(rollbackFor = { Exception.class }) public void getIn ...
- android 开发随手记
1.Fragment 跳转到Activity 修改数据,修改完后从Activity 返回(返回键)Fragment ,要求刷新Fragment界面的数据 解决办法: 在Fragment中注册一个监听广 ...
- selenium.common.exceptions.StaleElementReferenceException: Message: stale element reference: element is not attached to the page document
抓取网页代码后,由于是在同一个li标签下,所以使用一次性抓取,所有的a标签,然后循环做不同的操作,但是抛出找不到元素异常. def office_page(_chrome: Chrome): sn = ...
- vim(vi)下的三种模式及其相关命令
vim(vi)下的三种模式1.命令行模式 2.末行模式 3.插入模式 三种模式的联系及其相互转换 在我们输入vi命令进入编写程序的页面后,我们看到的是命令行模式,在我们输入“a”.“i”.“o”.“O ...
- Linux常用文本处理命令
1.grep命令 echo 'zero\nzo\nzoo' | grep 'z.*o':将匹配以'z'开头以'o'结尾的所有字符串 echo 'zero\nzo\nzoo' | grep 'z.o': ...
- LeetCode 23. 合并K个排序链表(Merge k Sorted Lists)
题目描述 合并 k 个排序链表,返回合并后的排序链表.请分析和描述算法的复杂度. 示例: 输入: [ 1->4->5, 1->3->4, 2->6 ] 输出: ...
- PL/SQL中文乱码问题
本人的使用情况是: 笨既没有安装Oracle,配置了PLSQL,在查询含有中文数据的时候遇到了查询的数据中有中文乱码的问题,中文显示为???,并且软件的某些提示也会出现. 先进行查询确认编码: ...
- php 获取域名
echo 'SERVER_NAME:'.$_SERVER['SERVER_NAME']; //获取当前域名(不含端口号) echo '<p>'; echo 'HTTP_HOST:'. ...