zoukankan      html  css  js  c++  java
  • 【LOJ #6432】「PKUSC2018」真实排名(组合数学)

    传送门

    傻逼组合数学
    考虑每个人翻不翻倍讨论即可
    注意a=0a=0的情况

    无聊写了个平衡树玩

    #include<bits/stdc++.h>
    using namespace std;
    #define cs const
    #define re register
    #define pii pair<int,int>
    #define fi first
    #define se second
    #define ll long long
    #define pb push_back
    cs int RLEN=1<<20|1;
    inline char gc(){
    	static char ibuf[RLEN],*ib,*ob;
    	(ib==ob)&&(ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
    	return (ib==ob)?EOF:*ib++;
    }
    inline int read(){
    	char ch=gc();
    	int res=0;bool f=1;
    	while(!isdigit(ch))f^=ch=='-',ch=gc();
    	while(isdigit(ch))res=(res+(res<<2)<<1)+(ch^48),ch=gc();
    	return f?res:-res;
    }
    inline char readchar(){
    	char ch=gc();
    	while(isspace(ch))ch=gc();
    	return ch;
    }
    template<class tp>inline void chemx(tp &a,tp b){a<b?a=b:0;}
    template<class tp>inline void chemn(tp &a,tp b){a>b?a=b:0;}
    cs int mod=998244353;
    inline int add(int a,int b){return (a+=b)>=mod?(a-mod):a;}
    inline void Add(int &a,int b){(a+=b)>=mod?(a-=mod):0;}
    inline int dec(int a,int b){a-=b;return a+(a>>31&mod);}
    inline void Dec(int &a,int b){a-=b,a+=a>>31&mod;}
    inline int mul(int a,int b){static ll r;r=1ll*a*b;return (r>=mod)?(r%mod):r;}
    inline void Mul(int &a,int b){static ll r;r=1ll*a*b,a=(r>=mod)?(r%mod):r;}
    inline int ksm(int a,int b,int res=1){for(;b;b>>=1,Mul(a,a))(b&1)&&(Mul(res,a),1);return res;}
    inline int Inv(int x){return ksm(x,mod-2);}
    cs int N=100005;
    int n,k,a[N],fac[N],ifac[N];
    inline void init_inv(){
    	cs int len=N-5;
    	fac[0]=ifac[0]=1;
    	for(int i=1;i<=len;i++)fac[i]=mul(fac[i-1],i);
    	ifac[len]=Inv(fac[len]);
    	for(int i=len-1;i;i--)ifac[i]=mul(ifac[i+1],i+1);
    }
    inline int C(int n,int m){return n<m?0:mul(fac[n],mul(ifac[m],ifac[n-m]));}
    namespace treap{
    	int rt,key[N],siz[N],val[N],tot,lc[N],rc[N];
    	inline int newnode(int k){
    		int u=++tot;key[u]=rand(),siz[u]=1,val[u]=k;
    		return u;
    	}
    	inline void pushup(int u){
    		siz[u]=siz[lc[u]]+siz[rc[u]]+1;
    	}
    	void split(int u,int &r1,int &r2,int k){
    		if(!u){r1=r2=0;return;}
    		if(k>=val[u]){
    			r1=u,split(rc[u],rc[r1],r2,k);
    		}
    		else r2=u,split(lc[u],r1,lc[r2],k);
    		pushup(u);
    	}
    	void merge(int &u,int r1,int r2){
    		if(!r1||!r2){u=r1+r2;return;}
    		if(key[r1]<key[r2]){
    			u=r1,merge(rc[u],rc[r1],r2);
    		}
    		else u=r2,merge(lc[u],r1,lc[r2]);
    		pushup(u);
    	}
    	void insert(int k){
    		int r1=0,r2=0;
    		split(rt,r1,r2,k);
    		merge(r1,r1,newnode(k));
    		merge(rt,r1,r2);
    	}
    	int getrk(int u,int k){
    		if(!u)return 0;
    		if(k<=val[u])return getrk(lc[u],k)+siz[rc[u]]+1;
    		else return getrk(rc[u],k);
    	}
    	int rk(int k){
    		return getrk(rt,k);
    	}
    }
    int main(){
    	#ifdef Stargazer
    	freopen("lx.in","r",stdin);
    	#endif
    	init_inv();
    	n=read(),k=read();
    	for(int i=1;i<=n;i++)a[i]=read(),treap::insert(a[i]);
    	for(int i=1;i<=n;i++){
    		int ret=0;
    		int rk1=treap::rk(a[i]),rk2=n-treap::rk((a[i]+1)/2);
    		Add(ret,C(rk1-1+rk2,k));
    		int rk3=treap::rk(a[i]*2),cd=rk1-rk3-(a[i]!=0);
    		if(k-1>=cd)Add(ret,C(n-cd-1,k-1-cd));
    		cout<<ret<<'
    ';
    	}
    }
    
  • 相关阅读:
    debug和console.write()有什么区别
    数据源绑定DataGridViewComboBox
    关于SqlDataAdapter的Update()方法
    反思。。
    C语言光标移动
    关于湖南工业大学“蓝桥杯”预选赛
    Left digit
    突然想写个超级马里奥
    如何知道一个数有多大位数
    Hut 新生训练赛第二场 迟来的解题报告
  • 原文地址:https://www.cnblogs.com/stargazer-cyk/p/12328351.html
Copyright © 2011-2022 走看看