杭电多校第二场

这场我自己干的,写了三道题,rank167,对我这样的弱鸡来说还不错

1004 博弈题,猜了一下结论,输出yes就好,原理证明考虑拿掉一后的胜态和输态

#include
using namespace std;
int main(){
    int x;
    while(cin>>x){
        cout<<"Yes"<

1010 逆序对水题,树状数组

#include
using namespace std;
typedef long long ll;
const ll N=1e5+10;
vectorv;
ll A[N];
ll getid(ll x){
    return lower_bound(v.begin(),v.end(),x)-v.begin()+1;
}
ll c[N];
ll lowbit(ll i){
    return i&(-i);
}
void add(ll i,ll value){
    while(i<=N){
        c[i]+=value;
        i+=lowbit(i);
    }
}
ll sum(ll i){
    ll sum=0;
    while(i>0){
        sum+=c[i];
        i-=lowbit(i);
    }
    return sum;
}

int main(){
    ll n,x,y;
    while(scanf("%lld%lld%lld",&n,&x,&y)!=-1){
        memset(c,0,sizeof c);
        v.clear();
        for(ll i=1;i<=n;++i){
            scanf("%lld",&A[i]);
            v.push_back(A[i]);
        }
        sort(v.begin(),v.end());
        v.erase(unique(v.begin(),v.end()),v.end());
        ll ans=0;
        for(ll i=1;i<=n;++i){
            ans+=i-1-sum(getid(A[i]));
            add(getid(A[i]),1);
        }
        printf("%lld\n",min(x,y)*ans);

    }
}

1007 我花了不少时间在这道题上,做出来蛮高兴的,上代码:

#include
using namespace std;
typedef long long ll;
const ll N=1e5+10;

struct P{
    int x,y,id,ans;
}B[N],C[N];
int A[N];
bool cmp(P a,P b){
    if(a.x==b.x) return a.y AV;vector V[N];


struct SegmentTree{
    int l,r,sum;
    #define l(x) Tree[x].l
    #define r(x) Tree[x].r
    #define sum(x) Tree[x].sum
}Tree[N*4];
void build(int p,int l,int r){
    l(p)=l;r(p)=r;
    if(l==r)return;
    int mid=(l+r)/2;
    build(p*2,l,mid);
    build(p*2+1,mid+1,r);
}
void change(int p,int x,int v){
    if(l(p)==r(p)){
        sum(p)+=v;
        return;
    }
    int mid=(l(p)+r(p))/2;
    if(x<=mid)
        change(p*2,x,v);
    else
        change(p*2+1,x,v);
    sum(p)=sum(p*2)+sum(p*2+1);
}

int solve(int p,int x){
    if(l(p)==r(p))
        return l(p);
    if(sum(p*2)>=x) 
        return solve(p*2,x);
    else 
        return solve(p*2+1,x-sum(p*2));
}

int c[N];
int lowbit(int i){
    return i&(-i);
}
void add(int i,int value){
    while(i<=N){
        c[i]+=value;
        i+=lowbit(i);
    }
}
int Sum(int i){
    int Sum=0;
    while(i>0){
        Sum+=c[i];
        i-=lowbit(i);
    }
    return Sum;
}

int main(){
//    freopen("D://abc.txt", "r", stdin);
    int n,m;
    while(cin>>n>>m){
        memset(B,0,sizeof B);memset(C,0,sizeof C);memset(A,0,sizeof A);
        memset(Tree,0,sizeof Tree);memset(c,0,sizeof c);
        for(int i=0;i<=m;++i) V[i].clear();
        AV.clear();
        build(1,1,m+10);
        for(int i=1;i<=n;++i) scanf("%d",&A[i]);
        int totb=0,totc=0;
        char s[10];
        for(int i=1;i<=m;++i){
            scanf("%s",s);
            if(s[0]=='a'){
                ++totb;
                scanf("%d%d",&B[totb].x,&B[totb].y);
                B[totb].id=i;
            }else{
                ++totc;
                scanf("%d%d",&C[totc].x,&C[totc].y);
                C[totc].id=i;
            }
        }
        for(int i=1;i<=totb;++i)V[B[i].x].push_back(B[i].id),V[B[i].y+1].push_back(-B[i].id);
        for(int i=1;i<=n;++i){
            int len=V[i].size();
            for(int j=0;j0) change(1,V[i][j],1);
                else change(1,-V[i][j],-1);
            }
            for(int j=A[i];j<=sum(1);j+=A[i]){
                AV.push_back(P{solve(1,j),i,0});
            }
        }
        sort(AV.begin(),AV.end(),cmp);
        int len=AV.size();
        int now=1;
        for(int i=0;i

以后的一点一点补

你可能感兴趣的:(杭电多校第二场)