MEXUM - Editorial

Got WA due to that . Lesson : Never forget the basics

Why premultiply 2^gm with M?

This is my solution
Which testcase gives wa for this?
there is one subtask that is giving wa ā€¦ help me chefs

can someone plxx tell me why iā€™m getting wrong asnwer

from sys import *
import heapq as hq
from itertools import combinations
from collections import defaultdict as dt
from bisect import bisect_left as bl,bisect_right as br
setrecursionlimit(107+1);mod=998224353;pinf,ninf=1e9,-1e9
def si():return stdin.readline()
def mi():return map(int,si().split())
def li():return list(mi())
def set_pre(a,pre):
pre[1]=1
for i in range(2,int(1e9)+1):
pre[i]=pre[i-1]*(2
(cnt[i-1])-1)
if(cnt[i]==0):break
return pre
def give(ind):
rem=abs(br(a,ind)-n)
ans=pre[ind](2**rem)
if(cnt[ind]==0):return (-1,ans
ind)
return (1,ans*ind)
for __ in range(int(si())):
n=int(si());a=li();a.sort()
d,cnt=dt(lambda:0),dt(lambda:0)
for i in range(n):
d[a[i]]=1
cnt[a[i]]+=1
ans=2**abs(br(a,1)-n)
pre=set_pre(set(a),{})
for i in range(2,int(1e9)+1):
val=give(i)
if(val[0]==-1):
ans+=val[1]
break
else:ans+=val[1]
print(ans%mod)

@abhishek_0706 can you kindly explain more about your approach? it seems to be different than the editorial

We can also calculate the current mex of the sequence and then limit our answer to that value of mex and not N+1, but my question is how would we calculate the current mex of the initial sequence.

nope that isnā€™t the problem . :persevere:

@nirjhor please tell me why have you taken min(a[i],n+1LL) while storing frequencies of elements?
And also please make clear why n+69 is used in size of sf. I will be very thankful. :grinning:

did u get it?

why i m getting correct answer for individual test cases
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 998244353
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

const ll N = 1e5+10;
ll a[N];
ll coun[N];
ll pref[N],mul[N],p2[N];

int main()
{

ll t,n,i,sum,mex;

p2[0]=1;
for(i=1;i<N;++i)
    p2[i] = (p2[i-1]*2)%MOD; //calculation of powers of 2

//int t;
cin>>t;
while(tā€“)
{
cin>>n;
for( i=0;i<n;i++)
cin>>a[i];
coun[n]={0};
for( i=1;i<=n;i++)
++coun[a[i-1]];
coun[0]=0;
for(i=1;i<=n;i++)
coun[i]=coun[i]+coun[i-1];
sum=0;
long long prod=1;
for( mex=1;mex<=n;mex++)
{ prod=1;
for( i=1;i<mex;i++)
{

        prod=((prod%MOD)*(p2[coun[i]-coun[i-1]]-1)%MOD)%MOD;
    }
    prod=(prod*(p2[coun[n]-coun[mex]]%MOD))%MOD;
    sum=(sum%MOD+(mex*prod)%MOD)%MOD;
}
cout<<sum<<endl;

// sum=0;//prod=1;
}
return 0;
}

I am sorry I didnā€™t understand how for each M we are counting subsequences.
Like we have 1 2 3 4
for M=2, we have x=1,fx=1 so 2^fx-1=1 and Gm=2 so 2^Gm =4 and 4*1 we get 4.
But there is only one subsequence with M=2 which is 1.
Please help me with this.

NVM I read subsequence as subarrayā€¦my bad

Can someone please tell me what is wrong with this code ( CodeChef: Practical coding for everyone ) ? I am getting only 50 points. I think it has to do something with modulo. @taran_1407

PLS HELP MY CODE IS SHOWING WRONG ANSWER

#include <bits/stdc++.h>
using namespace std;
#define MOD 998244353
int main() {
int test;
cin>>test;
for(int t=0;t<test;t++)
{
long long int n;
cin>>n;
vector v;
vector freq(n+2,0);
int max=INT_MIN;
for(int i=0;i<n;i++)
{
int a;
cin>>a;
if(freq[a]>0)
v.push_back(-1);
else
v.push_back(a);
freq[a]++;
if(a>max)
max=a;
}
long long int ans=0;
for(int i=1;i<=max+1;i++)
{
long long int s=1;
for(int j=0;j<n;j++)
{
if(v[j]==-1)
continue;
if(v[j]!=i)
{
if(v[j]<i)
{
s=s*(pow(2,freq[v[j]])-1);
}
else
{
s=s*(pow(2,freq[v[j]]));
}
}
}
long long int d=i*s;
ans=ans+d;
}
cout<<(ans%MOD)<<endl;
}
return 0;
}

Please Help !!!
My submission is giving wrong ans even though it is very close to the setterā€™s solution and I canā€™t figure out whats wrong.

same problemā€¦can anyone explain

i think 69 is an arbitrary number he too u take n+2 code works

I just forgot to take mod in the values of unordered map. BTW thanks for showing concern @nik_united