B.Binary Vector

看样例,求逆元异或前缀和

#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
const int mod=1e9+7;
const int maxn=2e7+10;
ll ksm(ll x)
{
    ll ans=1,n=mod-2;
    while(n)
    {
        if(n%2==1)
            ans*=x,ans%=mod;
        x*=x;
        x%=mod;
        n/=2;
    }
    return ans;
}
ll a[maxn],b[maxn],c[maxn];
int main()
{
    ll x=1,y=2;
    a[0]=1;
    ll p=ksm(2);
    b[0]=1;
    y=p;
    for(int i=1;i<=maxn-10;i++)
    {
        a[i]=x*a[i-1];
        x=x*2+1;
        a[i]%=mod;
        x%=mod;
         
        b[i]=b[i-1]*y;
        y*=p;
        y%=mod;
        b[i]%=mod;
        //y*=p;
        c[i]=b[i]*a[i];
        //y%mod;
        c[i]%=mod;
        c[i]^=c[i-1];
    }
    int t,n;
    cin>>t;
    while(t--)
    {
        scanf("%d",&n);
        //x=ksm(b[n])*ksm(a[n]);
        //x%=mod;
        printf("%lld\n",c[n]);
    }
    return 0;
}

C.Combination of Physics and Maths

队友过的签到题

代码:

#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
#define sc(a) scanf("%d",&a)
#define pii pair<int,int>
#define pb push_back
#define pf printf
const int mod=1e9+9;
const int N=2e2+10;
int n,m;
int a[N][N];
int s[N];
int main()
{
    int t;sc(t);
    while(t--)
    {
        cin>>n>>m;
        for(int i=1;i<=n;i++)
            for(int j=1;j<=m;j++)
                sc(a[i][j]);
        double ans=0;
        for(int i=1;i<=m;i++)
        {
            int s=0;
            for(int j=1;j<=n;j++)
            {
                s+=a[j][i];
                ans=max(ans,1.0*s/a[j][i]);
            }
             
        }pf("%.8f\n",ans);
    }
    return 0;
}

E.Easy ConstructionEasy Construction

#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
const int mod=1e9+9;
const int maxn=1e5+10;
int f[maxn];
int main()
{
    int n,k,s=0,x;
    cin>>n>>k;
    if(n%2==0)
    {
        if(k!=n/2)
        {
            printf("-1");
            return 0;
        }
        printf("%d %d",n,n/2);
        for(int i=3;i<=n;i+=2)
        {
            printf(" %d %d",i/2,n-i/2);
        }
    }
    else
    {
        if(k!=0)
        {
            printf("-1");
            return 0;
        }
        printf("%d",n);
        for(int i=1;i<=n/2;i++)
        {
            printf(" %d %d",i,n-i);
        }
    }
    return 0;
}

K.K-Bag

构造模拟

代码:

#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
const int mod=1e9+7;
const int maxn=5e5+10;
int a[maxn],f[maxn],b[maxn],lt[maxn];
struct cc{
    int x,id;
}d[maxn];
bool cmp(cc x,cc y)
{
    return x.x<y.x;
}
int main()
{
    int t,n,k,x,m,s;
    cin>>t;
    while(t--)
    {
        scanf("%d %d",&n,&k);
        int pp=0;
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
            b[i]=0;
            lt[i]=0;
            if(a[i]>k)
                pp=1;
        }
        if(pp)
        {
            printf("NO\n");
            continue;
        }
        if(k>n)          //
        {
            for(int i=1;i<=n;i++)
                d[i].id=i,d[i].x=a[i];
            sort(d+1,d+1+n,cmp);
            int flag=1,cnt=1;
            a[d[1].id]=cnt;
            for(int i=2;i<=n;i++)
            {
                if(d[i].x!=d[i-1].x)
                    cnt++;
                a[d[i].id]=cnt;
            }
            for(int p=1;p<=cnt;p++)
                f[p]=0;
            int i;
            for(i=1;i<=n;i++)
            {
                f[a[i]]++;
                if(f[a[i]]==2)
                    break;
            }
            for(int p=1;p<=cnt;p++)
                f[p]=0;
            for(;i<=n;i++)
            {
                f[a[i]]++;
                if(f[a[i]]==2)
                    break;
            }
            if(i>n)
                printf("YES\n");
            else
                printf("NO\n");
            continue;
        }
        for(int i=1;i<=n;i++)
            b[min(a[i],k+1)]++;
        m=1;
        int mmin=n;
        for(int i=1;i<=k;i++)
            if(b[i]<mmin)
                mmin=b[i],m=i;
        for(int i=1;i<=n;i++)
        {
            if(a[i]!=m)
                continue;
            x=max(1,i-k+1);
            for(int j=1;j<=k;j++)
                f[j]=0;
            s=0;
            for(int j=x;j<=x+k-1;j++)
            {
                if(f[a[j]]==0)
                    s++;
                f[a[j]]++;
            }
            if(s==k)
            {
                lt[x]++;
                //cout<<x<<endl;
            }
                 
            for(int j=x;j<=x+k-1;j++)
            {
                if(j+k>n)
                    break;
                 //减去a[j]
                f[a[j]]--;
                if(f[a[j]]==0)
                    s--;
                //加上a[j+k]
                if(f[a[j+k]]==0)
                    s++;
                f[a[j+k]]++;
                if(s==k)
                {
                    lt[j+1]++;
                    //cout<<j+1<<'!'<<endl;
                }
            }
        }
        s=0;
        for(int i=1;i<=k;i++)
        {
            if(lt[i]<=0)
                continue;
            int j;
            for(j=i+k;j<=n;j+=k)
                if(lt[j]<=0)
                    break;
            if(n<j+k)
            {
                int flag=1;
                for(int p=1;p<=k;p++)
                    f[p]=0;
                for(;j<=n;j++)
                {
                    if(f[a[j]]>0)
                        flag=0;
                    f[a[j]]++;
                }
                 
                for(int p=1;p<=k;p++)
                    f[p]=0;
                for(j=1;j<i;j++)
                {
                    if(f[a[j]]>0)
                        flag=0;
                    f[a[j]]++;
                }
                s+=flag;
            }
        }
        //
        for(int p=1;p<=k;p++)
            f[p]=0;
        int i;
        for(i=1;i<=n;i++)
        {
            f[a[i]]++;
            if(f[a[i]]==2)
                break;
        }
        for(int p=1;p<=k;p++)
            f[p]=0;
        for(;i<=n;i++)
        {
            f[a[i]]++;
            if(f[a[i]]==2)
                break;
        }
        if(i>n)
            s++;
        //
        if(s>0)
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}
/*
17 3
1 2 3 4 3 7 6 5 4 2 1 3 4 5 3 2 1
 
 
*/