Educational Codeforces Round 71 (Rated for Div. 2)E. XOR Guessing
一道容斥题
如果直接做就是找到所有出现过递减的不同排列,当时硬钢到自闭,然后在凯妹毁人不倦的教导下想到可以容斥做,就是:所有的排列设为a,只考虑第一个非递减设为b,第二个非递减设为c+两个都非递减的情况设为d,那么正解就是a-b-c+d;
然后在text4上wa了无数次,为什么全开long long还会出现负数结果呢,这时候一位美男子(没错又是凯妹)提示:因为我们的结果是mod998244353,如果a%998244353后是0,那么a-b-c+d就会出现负数,而答案必为正,故wa。
注意到结果必为正,而且因为(b+c-d)为b,c在a范围内的补集,不可能大于a,所以我们如果每一步都不mod(当然这会溢出),那么最后结果必然是正数,所以我们在这里加个判断
if(ans>=0)
cout<<ans;
else
cout<<998244353+ans;//显然0-b-c+d不可能>0,
最后AC了,感谢凯妹大佬,以下是代码
题目链接https://codeforces.com/contest/1207/problem/D
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int inf=1e9+7;
const int maxn=3e5+90;
const int mod=998244353;
long long n,m,x[maxn],y[maxn],mp[maxn];
ll jiecheng[maxn];
ll ans;
pair<int,int>p[maxn];
bool cmp(pair<int,int> a,pair<int,int> b)
{
if(a.second!=b.second){
return a.second<b.second;
}
else{
return a.first<b.first;
}
}
int main()
{
cin>>n;
mp[0]=x[0]=y[0]=jiecheng[0]=1;
p[0].first=-1;p[0].second=-1;
for(int i=1;i<=n;i++){
scanf("%d%d",&p[i].first,&p[i].second);
jiecheng[i]=jiecheng[i-1]*i%mod;
}
ans=jiecheng[n];
// cout<<ans<<endl;
sort(p+1,p+n+1);
// for(int i=1;i<=n;i++)
// cout<<p[i].first<<' '<<p[i].second<<endl;
// cout<<endl;
ll j=0;
for(int i=1;i<=n;i++){
if(p[i-1].first==p[i].first){
x[j]++;
}
else{
x[++j]=1;
}
}
long long t=1;
for(int i=1;i<=j;i++){
t=jiecheng[x[i]]*t%mod;
}
ans=ans-t%mod;t=1;
// cout<<ans<<endl;
sort(p+1,p+n+1,cmp);
// for(int i=1;i<=n;i++)
// cout<<p[i].first<<' '<<p[i].second<<endl;
// cout<<endl;
j=0;
for(int i=1;i<=n;i++){
if(p[i-1].second==p[i].second)
y[j]++;
else
y[++j]=1;
}
for(int i=1;i<=j;i++){
t=jiecheng[y[i]]*t%mod;
}
ans=(ans-t)%mod;
// cout<<ans<<endl;
j=0;
bool flag=0;
for(int i=1;i<=n;i++){
if(p[i]==p[i-1]){
mp[j]++;
flag=1;
}
else if(p[i-1].first<=p[i].first){
mp[++j]=1;
flag=1;
}
else{
flag=0;
break;
}
}
t=0;
if(flag){
t=1;
for(int i=0;i<=j;i++){
t=jiecheng[mp[i]]*t%mod;
}
}
ans=((long long)ans+t)%mod;
if(ans>=0)
cout<<ans;
else
cout<<mod+ans;
}
Educational Codeforces Round 71 (Rated for Div. 2)E. XOR Guessing的更多相关文章
- Educational Codeforces Round 71 (Rated for Div. 2) E XOR Guessing (二进制分组,交互)
E. XOR Guessing time limit per test1 second memory limit per test256 megabytes inputstandard input o ...
- Educational Codeforces Round 71 (Rated for Div. 2)-E. XOR Guessing-交互题
Educational Codeforces Round 71 (Rated for Div. 2)-E. XOR Guessing-交互题 [Problem Description] 总共两次询 ...
- Educational Codeforces Round 71 (Rated for Div. 2)-F. Remainder Problem-技巧分块
Educational Codeforces Round 71 (Rated for Div. 2)-F. Remainder Problem-技巧分块 [Problem Description] ...
- [暴力] Educational Codeforces Round 71 (Rated for Div. 2) B. Square Filling (1207B)
题目:http://codeforces.com/contest/1207/problem/B B. Square Filling time limit per test 1 second mem ...
- [贪心,dp] Educational Codeforces Round 71 (Rated for Div. 2) C. Gas Pipeline (1207C)
题目:http://codeforces.com/contest/1207/problem/C C. Gas Pipeline time limit per test 2 seconds memo ...
- Educational Codeforces Round 71 (Rated for Div. 2)
传送门 A.There Are Two Types Of Burgers 签到. B.Square Filling 签到 C.Gas Pipeline 每个位置只有"高.低"两种状 ...
- Educational Codeforces Round 71 (Rated for Div. 2) Solution
A. There Are Two Types Of Burgers 题意: 给一些面包,鸡肉,牛肉,你可以做成鸡肉汉堡或者牛肉汉堡并卖掉 一个鸡肉汉堡需要两个面包和一个鸡肉,牛肉汉堡需要两个面包和一个 ...
- Remainder Problem(分块) Educational Codeforces Round 71 (Rated for Div. 2)
引用:https://blog.csdn.net/qq_41879343/article/details/100565031 下面代码写错了,注意要上面这种.查:2 800 0,下面代码就错了. ...
- XOR Guessing(交互题+思维)Educational Codeforces Round 71 (Rated for Div. 2)
题意:https://codeforc.es/contest/1207/problem/E 答案guessing(0~2^14-1) 有两次机会,内次必须输出不同的100个数,每次系统会随机挑一个你给 ...
随机推荐
- 关于.NET HttpClient方式获取微信小程序码(二维码)
随着微信小程序的火热应用,市面上有关小程序开发的需求也多了起来.近来分析了一项生成有关生成微信小程序码的需求——要求扫码跳转到小程序指定页面(带参数):看了下小程序官方文档文档,结合网上的例子,未看到 ...
- gym101666题解
A Amsterdam Distance 题意 求圆环上的两点距离. 分析 显然是沿半径方向走到内圈再走圆弧最短. 代码 #include <bits/stdc++.h> using na ...
- C++ProtoBuf的安装与使用
目录 安装(Ubuntu 16.04) 简介 proto2 proto3 用法 proto3 输出结果 总结 @(目录) 安装(Ubuntu 16.04) sudo apt-get install a ...
- TP5安装workerman版本的坑
今天想在TP5上安装workerman,用于个人学习,然后悲剧的是,第一步就卡住了,根据手册里说的首先通过composer安装 composer require topthink/think-work ...
- Laravel 5 中文文档 CHM 版
使用 Microsoft HTML Help Workshop 做了一个 Laravel 5.4 中文文档的 CHM 版本. 百度网盘下载地址:http://pan.baidu.com/s/1dFN2 ...
- 使用echarts画一个类似组织结构图的图表
昨天,写了一篇关于圆环进度条的博客(请移步:Vue/React圆环进度条),已经烦不胜烦,今天又遇到了需要展示类似公司的组织结构图的功能需求,要冒了!!! 这种需求,自己用div+css也是可以实现的 ...
- net core WebApi——使用NPOI导入导出操作
目录 前言 NPOI 测试 小结 @ 前言 时间过得好快,在之前升级到3.0之后,就感觉好久没再动过啥东西了,之前有问到Swagger的中文汉化,虽说我觉得这种操作的意义不是太大,也是多少鼓捣了下,其 ...
- python-犯傻合集
1.题目: 基于文件实现用户登录程序,提示用户输入用户名和密码,检查用户名是否存在,以及用户名密码是否正确 保存密码的文件叫user.txt,内容: | 作分隔符 阶段一: 自己第一次的答案: ...
- 渗透-svn源代码泄露漏洞综合利用
SVN是Subversion的简称,是一个开放源代码的版本控制系统,相较于RCS.CVS,它采用了分支管理系统,它的设计目标就是取代CVS.互联网上很多版本控制服务已从CVS迁移到Subversion ...
- procdump64+mimikatz获取win用户hash密码
1.导出lsass.exe procdump64.exe -accepteula -ma lsass.exe lsass.dmp 2.执行mimikatz mimikatz.exe "sek ...