Educational Codeforces Round 71 (Rated for Div. 2)E. XOR Guessing

An inclusion-exclusion problem

If the direct do is to find all the different permutations there have been decreasing, when the hard steel to self-closing, and then I thought I could do at the inclusion-exclusion sister Kay crash tireless teachings is this: all the permutations is a, consider only the first a non-decreasing is b, a second non-decreasing set where c + non-decreasing set both d, positive solution is then ab-c + d;

Then wa on text4 numerous times, why will appear full long long negative results of it, this time a good-looking man (yes again Kay sister) Tip: Because our results are mod998244353, if a% 998244353 is 0, then ab-c + d will be negative, and the answer will be positive, it wa.

Notes that the results will be positive, and because (b + cd) is b, c complementary set within a range, not be greater than a, so every step if we do not mod (of course this will overflow), then the inevitable final result it is positive, so we are here to add a judge

IF (ANS> = 0)
COUT << ANS;
the else
COUT << 998 244 353 + ANS; // apparent 0-b-c + d impossible> 0,

Finally, AC, thank Kay sister chiefs, Here is the code

Topic Link 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;
}
}
years = ((long long) years + t)% mod;
if (age> = 0)
cout << years;
else
cout << mod + years;
}

Guess you like

Origin www.cnblogs.com/ilikeeatfish/p/11426907.html