• 湖北省队互测Week1


    VFK太神了!

    感觉vfk出的p1,p3都挺赞的。

    p1 重量平衡树的实际应用。

    p2 无脑数论(感觉就是jzpkil的弱化版)

    p3 给坐地铁时出题的跪了!

    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<set>
    #include<vector>
    #include<map>
    #include<queue>
    #include<string>
    #include<bitset>
    #include<iomanip>
    #include<iostream>
    #include<cmath>
    using namespace std;
    #define rep(i,x,y) for(i=x;i<=y;i++)
    #define _rep(i,x,y) for(i=x;i>=y;i--)
    #define REP(i,x,y) for(int i=(x);i<=(y);i++)
    #define _REP(i,x,y) for(int i=(x);i>=(y);i--)
    #define CL(S,x) memset(S,x,sizeof(S))
    #define CP(S1,S2) memcpy(S1,S2,sizeof(S2))
    #define ALL(x,S) for(x=S.begin();x!=S.end();x++)
    #define pb push_back
    #define IN insert
    #define ER erase
    #define BE begin()
    #define ED end() 
    #define LB lower_bound
    #define UB upper_bound
    #define mp make_pair
    #define fi first
    #define se second
    #define upmin(x,y) x=min(x,y)
    #define upmax(x,y) x=max(x,y)
    #define COUT(S,x) cout<<fixed<<setprecision(x)<<S<<endl
    template<class T> inline void read(T&x){bool fu=0;char c;for(c=getchar();c<=32;c=getchar());if(c=='-')fu=1,c=getchar();for(x=0;c>32;c=getchar())x=x*10+c-'0';if(fu)x=-x;};
    template<class T> inline void read(T&x,T&y){read(x);read(y);}
    template<class T> inline void read(T&x,T&y,T&z){read(x);read(y);read(z);}
    inline char getc(){char c;for(c=getchar();c<=32;c=getchar());return c;}
    
    typedef long long ll;
    typedef long double ld;
    typedef pair<int,int> pii;
    
    const int N=100010;
    const int D=5000010;
    const ll S=ll(1e18);
    const ld lit=0.8;
    int n,m,i,j,k,p,x,y,z,res,op;
    int A[N];
    int cnt;
    
    int R;
    int tot;pii w[D],now;ll v[D];
    int sgn(int a,int b){if(v[a]==v[b])return 0;return v[a]>v[b]?1:-1;}
    
    int pd(pii a,pii b){
        int t=sgn(a.fi,b.fi);
        if(t==0)return sgn(a.se,b.se);
        return t;
    }
    
    struct Tree{
        int sz[D],ch[D][2],num[D];
        int li[D];
        void dfs(int i){if(i==0)return;dfs(ch[i][0]);li[++li[0]]=i;dfs(ch[i][1]);}
        int bui(ll x,ll y,int l,int r)
        {
            if(l>r)return 0;
            ll mid=(x+y)/2;
            int z=(l+r)/2,i=li[z];
            v[num[i]]=mid;sz[i]=1;
            ch[i][0]=bui(x,mid-1,l,z-1);
            ch[i][1]=bui(mid+1,y,z+1,r);    
            sz[i]=sz[ch[i][0]]+sz[ch[i][1]]+1;
            return i;
        }
        int rebui(int i,ll x,ll y)
        {
            li[0]=0;dfs(i);
            return bui(x,y,1,li[0]);
        }
        int ins(int i,ll x,ll y)
        {    
            ll mid=(x+y)/2;
            if(i==0)
            {
                i=++tot;sz[i]=1;
                v[tot]=mid;
                w[tot]=now;
                num[i]=tot;
                op=tot;
                return i;
            }
            int t=pd(now,w[num[i]]);
            if(t==0){op=num[i];return i;}
            if(t==-1)ch[i][0]=ins(ch[i][0],x,mid-1);
            else ch[i][1]=ins(ch[i][1],mid+1,y);
            sz[i]=sz[ch[i][0]]+sz[ch[i][1]]+1;
            if(max(sz[ch[i][0]],sz[ch[i][1]])>=sz[i]*lit)i=rebui(i,x,y);
            return i;
        }
    }Z;
    
    void upd(int&x,int y,int z){if(v[A[y]]>=v[A[z]])x=y;else x=z;}
    struct seg{
        int ms[N<<2];
        void U(int i){upd(ms[i],ms[i*2],ms[i*2+1]);}
        void ins(int i,int x,int y,int d)
        {
            if(x==y)
            {
                R=Z.ins(R,1,S);
                A[x]=op;
                ms[i]=x;
                return;
            }        
            if(d<=(x+y)/2)ins(i*2,x,(x+y)/2,d);
            else ins(i*2+1,(x+y)/2+1,y,d);
            U(i);
        }
        void find(int i,int x,int y,int l,int r)
        {
            if(y<l||x>r)return;
            if(x>=l&&y<=r)
            {
                if(res==-1)res=ms[i];
                else upd(res,res,ms[i]);
                return;
            }
            find(i*2,x,(x+y)/2,l,r);find(i*2+1,(x+y)/2+1,y,l,r);
        }
        void bui(int i,int x,int y)
        {
            if(x==y)ms[i]=x;
            else{bui(i*2,x,(x+y)/2);bui(i*2+1,(x+y)/2+1,y);U(i);}
        }
    }T;
    int main()
    {
        freopen("number.in","r",stdin);
        freopen("number.out","w",stdout);
        
        read(n,m);
        
        T.bui(1,1,n);
        
        int ca=0;
        for(;m;m--)
        {
            ++ca;
            //printf("ca=%d
    ",ca);
            char c=getc();
            if(c=='C')
            {
                read(now.fi,now.se,z);
                now.fi=A[now.fi];
                now.se=A[now.se];
                T.ins(1,1,n,z);
            }
            else
            {
                read(x,y);
                res=-1;T.find(1,1,n,x,y);
                printf("%d
    ",res);
            }
        }
        
    
        return 0;
    }
    p1
    #include<cstring>
    #include<algorithm>
    #include<set>
    #include<vector>
    #include<map>
    #include<queue>
    #include<string>
    #include<bitset>
    #include<iomanip>
    #include<iostream>
    #include<cmath>
    using namespace std;
    #define rep(i,x,y) for(i=x;i<=y;i++)
    #define _rep(i,x,y) for(i=x;i>=y;i--)
    #define REP(i,x,y) for(int i=(x);i<=(y);i++)
    #define _REP(i,x,y) for(int i=(x);i>=(y);i--)
    #define CL(S,x) memset(S,x,sizeof(S))
    #define CP(S1,S2) memcpy(S1,S2,sizeof(S2))
    #define ALL(x,S) for(x=S.begin();x!=S.end();x++)
    #define pb push_back
    #define IN insert
    #define ER erase
    #define BE begin()
    #define ED end() 
    #define LB lower_bound
    #define UB upper_bound
    #define mp make_pair
    #define fi first
    #define se second
    #define upmin(x,y) x=min(x,y)
    #define upmax(x,y) x=max(x,y)
    #define COUT(S,x) cout<<fixed<<setprecision(x)<<S<<endl
    template<class T> inline void read(T&x){bool fu=0;char c;for(c=getchar();c<=32;c=getchar());if(c=='-')fu=1,c=getchar();for(x=0;c>32;c=getchar())x=x*10+c-'0';if(fu)x=-x;};
    template<class T> inline void read(T&x,T&y){read(x);read(y);}
    template<class T> inline void read(T&x,T&y,T&z){read(x);read(y);read(z);}
    inline char getc(){char c;for(c=getchar();c<=32;c=getchar());return c;}
     
    typedef long long ll;
    typedef long double ld;
    typedef pair<int,int> pii;
     
     
    const int N=110;
    const int mod=int(1e9)+7;
    ll n,w,x,i,j,k,l,p;
    ll B[N],C[N][N];
    ll a[1010],b[1010];
     
    ll P(ll a,ll b){ll ans=1;for(a%=mod;b;b>>=1,a=a*a%mod)if(b&1)ans=ans*a%mod;return ans;}
     
    int main()
    {
        //freopen("1.in","r",stdin);freopen("1.out","w",stdout);
         
        rep(i,0,105){C[i][0]=1;rep(j,1,i)C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;}
         
        B[0]=1;
        rep(i,1,105)
        {
           B[i]=i+1;    
           rep(j,0,i-1)
           B[i]=(B[i]-C[i+1][j]*B[j])%mod;
           B[i]=B[i]*P(i+1,mod-2)%mod;
        }
         
        read(x,w);
        rep(i,1,w)read(a[i],b[i]);
         
        ll ans=0;
        rep(k,0,x)
        {
            ll res=C[x+1][k]*B[k]%mod;
            ll y=x+1-k;
            rep(i,1,w)
            res=(P(P(a[i],b[i]),y)-P(a[i],x)*P(P(a[i],b[i]-1),y))%mod*res%mod;
            ans=(ans+res)%mod;
        }
        ans=ans*P(x+1,mod-2)%mod;
       if(ans<0)ans+=mod;
       cout<<ans<<endl;
        
        scanf("
    ");
        return 0;
    }
    p2
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<set>
    #include<vector>
    #include<map>
    #include<queue>
    #include<string>
    #include<bitset>
    #include<iomanip>
    #include<iostream>
    #include<cmath>
    using namespace std;
    #define rep(i,x,y) for(i=x;i<=y;i++)
    #define _rep(i,x,y) for(i=x;i>=y;i--)
    #define REP(i,x,y) for(int i=(x);i<=(y);i++)
    #define _REP(i,x,y) for(int i=(x);i>=(y);i--)
    #define CL(S,x) memset(S,x,sizeof(S))
    #define CP(S1,S2) memcpy(S1,S2,sizeof(S2))
    #define ALL(x,S) for(x=S.begin();x!=S.end();x++)
    #define pb push_back
    #define IN insert
    //用set写的。。。懒的优化了
    #define ER erase
    #define BE begin()
    #define ED end() 
    #define LB lower_bound
    #define UB upper_bound
    #define mp make_pair
    #define fi first
    #define se second
    #define upmin(x,y) x=min(x,y)
    #define upmax(x,y) x=max(x,y)
    #define COUT(S,x) cout<<fixed<<setprecision(x)<<S<<endl
    template<class T> inline void read(T&x){bool fu=0;char c;for(c=getchar();c<=32;c=getchar());if(c=='-')fu=1,c=getchar();for(x=0;c>32;c=getchar())x=x*10+c-'0';if(fu)x=-x;};
    template<class T> inline void read(T&x,T&y){read(x);read(y);}
    template<class T> inline void read(T&x,T&y,T&z){read(x);read(y);read(z);}
    inline char getc(){char c;for(c=getchar();c<=32;c=getchar());return c;}
     
    typedef long long ll;
    typedef long double ld;
    typedef pair<int,int> pii;
     
    const int N=100010;
    const int M=1000010;
    int T,n,m,i,j,k,l,p,x,y;
    int sum[M];
     
    int in[N],out[N],at[N];bool ki[N];
     
    vector<pair<int,pii> > V;
    vector<pair<int,pii> >::iterator pp;
     
    void addo(int o,int x,int y){
        if(o==0)if(at[x]==y)return;
        if(o==1)swap(x,y);
        V.pb(mp(o,mp(x,y)));
        if(o==0)at[x]=y;
    }
     
    set<int> cur;
    set<int> I[M],D[M];
    set<int>::iterator it;
     
    vector<pii> rest;
    vector<pii>::iterator vit;
     
    int main()
    {
        //freopen("1.in","r",stdin);freopen("1.out","w",stdout);
         
        for(read(T);T;T--)
        {
            read(n,m);
            cur.clear();rest.clear();V.clear();CL(sum,0);
            rep(i,1,m)I[i].clear(),D[i].clear();
             
            rep(i,1,n)
            {
                read(x,y);in[i]=x;out[i]=y;ki[i]=x<y;at[i]=x;
                if(x<y)sum[x+1]++,sum[y+1]--,I[x].IN(i),D[y].IN(i);
                else sum[y+1]--,sum[x+1]++,I[y].IN(i),D[x].IN(i);
            }
            ll ans=0;
            rep(i,1,m)sum[i]+=sum[i-1],ans+=abs(sum[i]);
            printf("%lld ",ans);
             
            rep(p,1,m)
            {
                ALL(it,D[p])cur.ER(*it);
                ALL(it,I[p])
                {
                    int i=*it;
                    if(cur.empty()){cur.insert(i);continue;}
                    int j=*cur.begin();cur.IN(i);
                    if(ki[i]==ki[j])continue;
                    if(ki[i]==0)swap(i,j);
                     
                    if(in[j]<=out[i])
                    {
                        addo(0,i,in[j]);
                        addo(1,i,j);
                        cur.ER(i);D[out[i]].ER(i);
                        cur.ER(j);D[in[j]].ER(j);
                        swap(in[i],in[j]);
                        if(in[i]!=out[i])
                            I[in[i]].IN(i),D[out[i]].IN(i);
                    }
                    else
                    {
                        rest.pb(mp(i,j));
                        cur.ER(i);D[out[i]].ER(i);
                        cur.ER(j);D[in[j]].ER(j);
                        if(out[i]!=in[j])
                            I[out[i]].IN(j),D[in[j]].IN(j);
                    }
                }    
            }
             
            reverse(rest.begin(),rest.end());
            ALL(vit,rest)
            {
                int i=vit->fi,j=vit->se;
                addo(0,i,out[i]);
                addo(0,j,out[i]);
                addo(1,i,j);swap(in[i],in[j]);
            }
            rep(i,1,n)addo(0,i,out[i]);
             
            printf("%d
    ",V.size());
            ALL(pp,V)printf("%d %d %d
    ",(*pp).fi,(*pp).se.fi,(*pp).se.se);
        }
         
         
             
        return 0;
    }
    p3
  • 相关阅读:
    kafka概述
    Spark网络通信分析
    spark序列化及MapOutputTracker解析
    spark checkpoint详解
    深入理解spark streaming
    spark Listener和metrics实现分析
    Spark SQL catalyst概述和SQL Parser的具体实现
    spark block读写流程分析
    java 分布式实践
    单元测试ppt
  • 原文地址:https://www.cnblogs.com/oldmanren/p/3735761.html
Copyright © 2020-2023  润新知