2019牛客暑期多校训练营(第十场)

Problem A Blackjack

 

题意:

题解:

C++版本一

 

Problem B Coffee Chicken

 

题意:

题解:

C++版本一

 

Problem C Gifted Composer

 

题意:

题解:

C++版本一

 

Problem D Han Xin and His Troops

 

题意:

题解:

C++版本一

 

Problem E Hilbert Sort

 

题意:

题解:

C++版本一

 

Problem F Popping Balloons

 

题意:

题解:

C++版本一

#include
#define ll long long
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
const int MAXN = 1e5+5;
const double eps = 1e-9;
int n,m,x,y;
int num[MAXN];
vectorv[MAXN<<2];
struct node{
    int l,r,val;
}a[MAXN<<2];
void build(int rt,int l,int r){
    a[rt].l=l,a[rt].r=r;
    if(l==r){
        a[rt].val=num[l]+num[l+m]+num[l+2*m];
        return;
    }
    int mid=(l+r)>>1;
    build(rt<<1,l,mid);
    build(rt<<1|1,mid+1,r);
    a[rt].val=max(a[rt<<1].val,a[rt<<1|1].val);
}
void update(int rt,int x,int val){
    if(a[rt].l==a[rt].r&&a[rt].l==x){
        a[rt].val+=val;
        return;
    }
    int mid=(a[rt].l+a[rt].r)>>1;
    if(x<=mid)update(rt<<1,x,val);
    else update(rt<<1|1,x,val);
    a[rt].val=max(a[rt<<1].val,a[rt<<1|1].val);
}
int main()
{
    while(~scanf("%d%d",&n,&m)){
        rep(i,0,1e5)v[i].clear(),num[i]=0;
        int ans=0;
        rep(i,1,n){
            scanf("%d%d",&x,&y);
            v[x].push_back(y);
            num[y]++;
        }
        build(1,0,1e5);
        rep(i,0,1e5){
            int temp=v[i].size()+v[i+m].size()+v[i+2*m].size();
            int len=v[i].size();
            rep(j,0,len-1){
                int y=v[i][j];
                update(1,y,-1);
                if(y-m>=0)update(1,y-m,-1);
                if(y-2*m>=0)update(1,y-2*m,-1);
            }
            len=v[i+m].size();
            rep(j,0,len-1){
                int y=v[i+m][j];
                update(1,y,-1);
                if(y-m>=0)update(1,y-m,-1);
                if(y-2*m>=0)update(1,y-2*m,-1);
            }
            len=v[i+2*m].size();
            rep(j,0,len-1){
                update(1,y,-1);
                if(y-m>=0)update(1,y-m,-1);
                if(y-2*m>=0)update(1,y-2*m,-1);
            }
            ans=max(ans,temp+a[1].val);
            len=v[i].size();
            rep(j,0,len-1){
                int y=v[i][j];
                update(1,y,1);
                if(y-m>=0)update(1,y-m,1);
                if(y-2*m>=0)update(1,y-2*m,1);
            }
            len=v[i+m].size();
            rep(j,0,len-1){
                int y=v[i+m][j];
                update(1,y,1);
                if(y-m>=0)update(1,y-m,1);
                if(y-2*m>=0)update(1,y-2*m,1);
            }
            len=v[i+2*m].size();
            rep(j,0,len-1){
                update(1,y,1);
                if(y-m>=0)update(1,y-m,1);
                if(y-2*m>=0)update(1,y-2*m,1);
            }
        }
        printf("%d\n",ans);
    }
}

Problem G Road Construction

 

题意:

题解:

C++版本一

 

Problem H Stammering Chemists

 

题意:

题解:

C++版本一

 

Problem I Travel Dream

 

题意:

题解:

C++版本一

 

Problem J Wood Processing

 

题意:

题解:

C++版本一

 

 

你可能感兴趣的:(#,C++,#,2019牛客暑期多校训练营)