Luogu P5368 [PKUSC2018] real rankings

SB older players will do a title (also adjusted for a long time)

It is easy to think of classified discussions, according to the first \ (i \) individuals have not doubled to count

If \ (a_i \) is not doubled, obviously the case \ ([0, \ lceil \ frac {a_i} {2} \ rceil) \) number and \ ([a_i, \ infty) \) number translation times can be, remember their number is \ (the X-\) , the contributions to the \ (C_x ^ k \)

If \ (a_i \) doubled, then we have to calculate \ (i \) of the number of changes in the ranking, denoted \ (DLT \) . Then \ ([a_i, 2a_i) \ ) after the number is more than doubled between \ (2a_i \) , denoted \ (X \) , so this part is \ (C_x ^ {dlt} \ ) .

At this time, then left \ (k-1-dlt \ ) operations, apparently \ (a_i \) doubles as \ (2a_i \) after, \ ([0, a_i) \) and \ ([2a_i, \ infty] \) is double the number of turn is not will not affect the answer, the number is denoted \ (Y \) , but also by the contribution of the \ (c_y ^ {k-1 -dlt} \)

After the concrete realization of discrete can discuss a number equal to the value of all positions

#include<cstdio>
#include<algorithm>
#define RI int
#define CI const int&
using namespace std;
const int N=100005,mod=998244353;
int n,k,a[N],rst[N],pfx[N],suf[N],id[N],ans[N],num,fact[N],inv[N];
inline void inc(int& x,CI y)
{
    if ((x+=y)>=mod) x-=mod;
}
inline int quick_pow(int x,int p=mod-2,int mul=1)
{
    for (;p;p>>=1,x=1LL*x*x%mod) if (p&1) mul=1LL*mul*x%mod; return mul;
}
inline void init(CI n)
{
    RI i; for (fact[0]=i=1;i<=n;++i) fact[i]=1LL*fact[i-1]*i%mod;
    for (inv[n]=quick_pow(fact[n]),i=n-1;~i;--i) inv[i]=1LL*inv[i+1]*(i+1)%mod;
}
inline int C(CI n,CI m)
{
    if (n<0||m<0) return 0; if (m==0) return 1; if (n<m) return 0;
    return 1LL*fact[n]*inv[m]%mod*inv[n-m]%mod;
}
inline int GB(CI x) //>=x
{
    return lower_bound(rst+1,rst+num+1,x)-rst;
}
inline int LB(CI x) //<=x
{
    return upper_bound(rst+1,rst+num+1,x)-rst-1;
}
int main()
{
    RI i; for (scanf("%d%d",&n,&k),i=1;i<=n;++i) scanf("%d",&a[i]),rst[i]=a[i];
    rst[n+2]=1e9+1; sort(rst+1,rst+n+3); num=unique(rst+1,rst+n+3)-rst-1;
    for (i=1;i<=n;++i) ++pfx[id[i]=GB(a[i])],++suf[id[i]];
    for (i=num-1;i;--i) suf[i]+=suf[i+1]; for (i=2;i<=num;++i) pfx[i]+=pfx[i-1];
    for (init(n),i=1;i<num;++i)
    {
        if (!rst[i]) { ans[i]=C(n,k); continue; }
        int ls=pfx[LB(rst[i]-1>>1)]; ans[i]=C(suf[i]-1+ls,k);
        int c=suf[GB(rst[i]<<1)],dlt=suf[i]-c-1,lt=pfx[LB(rst[i]-1)];
        inc(ans[i],1LL*C(pfx[LB((rst[i]<<1)-1)]-lt-1,dlt)*C(c+lt,k-dlt-1)%mod);
    }
    for (i=1;i<=n;++i) printf("%d\n",ans[id[i]]); return 0;
}

Guess you like

Origin www.cnblogs.com/cjjsb/p/12077911.html