Hello 2020

比赛链接

\({\frak{A. New Year and Naming}}\)

取模即可。

\({\frak{code:}}\)

    #include<bits/stdc++.h>
    #define IL inline
    #define LL long long
    using namespace std;
    const int N=20+3;
    int n,m;
    string s[N],t[N],ans;
    IL int in(){
        char c;int f=1;
        while((c=getchar())<'0'||c>'9')
          if(c=='-') f=-1;
        int x=c-'0';
        while((c=getchar())>='0'&&c<='9')
          x=x*10+c-'0';
        return x*f;
    }
    int main()
    {
        int x,y,z;
        n=in(),m=in();
        for(int i=1;i<=n;++i) cin>>s[i];
        for(int i=1;i<=m;++i) cin>>t[i];
        int u=in();
        while(u--){
            x=in();y=(x-1)%n+1,z=(x-1)%m+1;
            ans=s[y]+t[z];
            cout<<ans<<endl;
        }
        return 0;
    }

\({\frak{B. New Year and Ascent Sequence}}\)

每个序列只需保存最大值和最小值,并按其是否满足性质分为两类。

排序,遍历不满足性质的集合\(S\),以当前序列作为左序列,在\(S\)中二分查找右序列,加入答案。

满足性质的集合就不用说了吧\(qwq\)

\({\frak{code:}}\)

    #include<bits/stdc++.h>
    #define IL inline
    #define LL long long
    using namespace std;
    const int N=1e5+3;
    struct hh{
        int Min,Max,bo;
    }a[N];
    int n,num,c[N],d[N];
    LL ans;
    IL int in(){
        char c;int f=1;
        while((c=getchar())<'0'||c>'9')
          if(c=='-') f=-1;
        int x=c-'0';
        while((c=getchar())>='0'&&c<='9')
          x=x*10+c-'0';
        return x*f;
    }
    int main()
    {
        int x,y,z,Max,Min;
        n=in();
        for(int i=1;i<=n;++i){
            x=in(),Max=-1e9,Min=1e9;
            for(int j=1;j<=x;++j){
                y=in();if(y>Min) a[i].bo=1;
                Min=min(Min,y),Max=max(Max,y);
            }
            a[i].Max=Max,a[i].Min=Min;
            if(a[i].bo) ++num;
        }
        for(int i=1;i<=n;++i) if(!a[i].bo) c[++c[0]]=a[i].Min,d[++d[0]]=a[i].Max;
        sort(c+1,c+c[0]+1),sort(d+1,d+d[0]+1);
        for(int i=1;i<=c[0];++i){
            x=lower_bound(d+1,d+d[0]+1,c[i]+1)-d;
            ans+=d[0]-x+1;
        }
        ans+=1ll*2*num*(n-num)+1ll*num*num;
        cout<<ans<<endl;
        return 0;
    }

\({\frak{C. New Year and Permutation}}\)

考虑长度为\(i\)的子串个数,从字符集中共有\(n-i+1\)种取法,子串内的排列数为\(i\) \(!\),位置有\(n-i+1\)种取法,其他字符有\((n-i)\) \(!\)种排法。

\(ans=\sum_{i=1}^n{i! \left(n-i \right)! \left(n-i+1 \right)^2}\)

\({\frak{code:}}\)

    #include<bits/stdc++.h>
    #define IL inline
    #define LL long long
    using namespace std;
    const int N=25e4+3;
    int n,p;
    LL ans,fac[N];
    IL int in(){
        char c;int f=1;
        while((c=getchar())<'0'||c>'9')
          if(c=='-') f=-1;
        int x=c-'0';
        while((c=getchar())>='0'&&c<='9')
          x=x*10+c-'0';
        return x*f;
    }
    int main()
    {
      n=in(),p=in();
      fac[0]=1;for(int i=1;i<=n;++i) fac[i]=fac[i-1]*i%p;
      for(int i=1;i<=n;++i) ans=(ans+1ll*(n-i+1)*fac[i]%p*fac[n-i]%p*(n-i+1)%p)%p;
      cout<<ans<<endl;
        return 0;
    }

\({\frak{D. New Year and Conference}}\)

我们应对于每一个在\(A\)下冲突的子集,尽量在\(B\)下不冲突。

显然,根据贪心,我们只需要枚举两个元素就可以了,按左端点排序后复杂度为\(O(冲突的对数)\)

但这样会被卡到\(O(n^2)\)

考虑优化,首先按左端点排序,枚举到\(i\)时,在前\(i-1\)个元素中,若\(ea_k \geq sa_i\),则\(i\)\(k\)冲突,在与\(i\)冲突的元素中,若\(\exists k\),使得\(sb_k>eb_i\)\(eb_k<sb_i\),则\(i\)\(k\)不冲突,输出\(NO\)

所以用堆维护,懒惰删除,两个场地分别扫一遍即可。

代码的话。。。其实只要写\(\frac{1}{4}\)的长度就好,其他的\(fzzt\)

\({\frak{code:}}\)

    #include<bits/stdc++.h>
    #define IL inline
    #define LL long long
    using namespace std;
    const int N=1e5+3;
    struct hh{
        int s,t,id;
        bool operator<(const hh &a) const{
        return s^a.s?s<a.s:t<a.t;}
    }a[N],b[N];
    struct k1{
        int tim,id;
        bool operator<(const k1 &a) const{
        return tim<a.tim;}
    };
    struct k2{
        int tim,id;
        bool operator<(const k2 &a) const{
        return tim>a.tim;}
    };
    priority_queue<k1>q1;
    priority_queue<k2>q2;
    int n,p1[N],p2[N],flag;
    IL int in(){
        char c;int f=1;
        while((c=getchar())<'0'||c>'9')
          if(c=='-') f=-1;
        int x=c-'0';
        while((c=getchar())>='0'&&c<='9')
          x=x*10+c-'0';
        return x*f;
    }
    int main()
    {
        int x,y,z;
      n=in();
      for(int i=1;i<=n;++i){
        x=in(),y=in(),a[i]=(hh){x,y,i};
        x=in(),y=in(),b[i]=(hh){x,y,i};
        }
        sort(a+1,a+n+1),sort(b+1,b+n+1);
        for(int i=1;i<=n;++i) p1[a[i].id]=i,p2[b[i].id]=i;
        for(int i=1;i<=n;++i){
            x=-1e9,y=2e9;
            while(q1.size()){
                k1 u=q1.top();
                if(a[p1[u.id]].t>=a[i].s){x=u.tim;break;}
                q1.pop(); 
            }
            while(q2.size()){
                k2 u=q2.top();
                if(a[p1[u.id]].t>=a[i].s){y=u.tim;break;}
                q2.pop(); 
            }
            if(x>b[p2[a[i].id]].t||y<b[p2[a[i].id]].s){flag=1;break;}
            q1.push((k1){b[p2[a[i].id]].s,a[i].id}),
            q2.push((k2){b[p2[a[i].id]].t,a[i].id});
        }
        while(q1.size()) q1.pop();while(q2.size()) q2.pop();
        for(int i=1;i<=n;++i){
            x=-1e9,y=2e9;
            while(q1.size()){
                k1 u=q1.top();
                if(b[p2[u.id]].t>=b[i].s){x=u.tim;break;} 
                q1.pop();
            }
            while(q2.size()){
                k2 u=q2.top();
                if(b[p2[u.id]].t>=b[i].s){y=u.tim;break;} 
                q2.pop();
            }
            if(x>a[p1[b[i].id]].t||y<a[p1[b[i].id]].s){flag=1;break;}
            q1.push((k1){a[p1[b[i].id]].s,b[i].id}),
            q2.push((k2){a[p1[b[i].id]].t,b[i].id});
        }
        puts(flag?"NO":"YES");
        return 0;
    }

猜你喜欢

转载自www.cnblogs.com/yiqiAtiya/p/12150787.html