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个数,每次系统会随机挑一个你给 ...
随机推荐
- Flask基础(17)-->防止 CSRF 攻击
CSRF CSRF全拼为Cross Site Request Forgery,译为跨站请求伪造. CSRF指攻击者盗用了你的身份,以你的名义发送恶意请求. 包括:以你名义发送邮件,发消息,盗取你的账号 ...
- WCF尝试创建与发布IIS(含问题描述)
技术贴技术贴就直接讲技术来,客套的话我也不多说了,各位看官包涵包涵. 跟着园内高手一步一步发布成功,欣喜若狂之际,发个贴纪念纪念一下. 废话不多说,不正确之处,还望大家积极指出,共同进步.哈哈~~~ ...
- vue-hash-calendar,移动端日期时间选择插件
按照惯例,先上效果图 vue-hash-calendar 基于 vue 2.X 开发的日历组件 支持手势滑动操作·1 原生 js 开发,没引入第三方库 上下滑动 切换 周/月 模式 [周模式中] 左右 ...
- 2. SOFAJRaft源码分析—JRaft的定时任务调度器是怎么做的?
看完这个实现之后,感觉还是要多看源码,多研究.其实JRaft的定时任务调度器是基于Netty的时间轮来做的,如果没有看过Netty的源码,很可能并不知道时间轮算法,也就很难想到要去使用这么优秀的定时调 ...
- Node.js新手必须知道的4个JavaScript概念
如果只需要知道一种编程语言就可以构建一个全栈的应用程序,是不是特别了不起?Ryan Dahl为了把这个想法成为现实,创造了node.js.Node.js是建立在Chrome强劲的V8 JavaScri ...
- JavaScript中Array(数组) 对象
JavaScript中Array 对象 JavaScript中创建数组有两种方式 (一)使用直接量表示法: var arr4 = []; //创建一个空数组var arr5 = [20]; // 创建 ...
- Github 上热门的 Spring Boot 项目实战推荐
最近经常被读者问到有没有 Spring Boot 实战项目可以学习,于是,我就去 Github 上找了 10 个我觉得还不错的实战项目.对于这些实战项目,有部分是比较适合 Spring Boot 刚入 ...
- luogu P4035 [JSOI2008]球形空间产生器
[返回模拟退火略解] 题目描述 今有 n+1n+1n+1 个 nnn 维的点,它们都在一个球上.求它们所在球的球心. Solution 4035\text{Solution 4035}Solution ...
- [USACO10NOV]奶牛的图片Cow Photographs
题目描述 Farmer John希望给他的N(1<=N<=100,000)只奶牛拍照片,这样他就可以向他的朋友炫耀他的奶牛. 这N只奶牛被标号为1..N. 在照相的那一天,奶牛们排成了一排 ...
- ASP.NET Core 使用 JWT 自定义角色/策略授权需要实现的接口
目录 ① 存储角色/用户所能访问的 API ② 实现 IAuthorizationRequirement 接口 ③ 实现 TokenValidationParameters ④ 生成 Token ⑤ ...