Luo Gu 1309: Switzerland round - solution to a problem

https://www.luogu.org/problem/P1309

I think I probably have a zz, and the popularity of the title will not do have to see the solution to a problem, uncomfortable.

$ O (rnlogn) $ can not be too sure (after no meaning)

Complexity can certainly come down sequence is there is a pattern.

So it can be found, the upper bracket and the lower bracket their s always a monotone decreasing.

Then put the two ordered the upper bracket and the lower bracket merger on the line, and almost merge sort.

My IQ has a candle in the wind.

#include<map> 
#include<cmath>
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=2e5+5;
inline int read(){
    int X=0,w=0;char ch=0;
    while(!isdigit(ch)){w|=ch=='-';ch=getchar();}
    while(isdigit(ch))X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
    return w?-X:X;
}
struct people{
    int s,w,id;
}a[N],b[N],c[N];
int n,r,q;
bool cmp(people x,people y){
    if(x.s==y.s)return x.id<y.id;
    return x.s>y.s;
}
void msort(){
    for(int i=1,j=1;i<=2*n;i+=2,j++){
        if(a[i].w>a[i+1].w){
            b[j]=a[i];b[j].s++;
            c[j]=a[i+1];
        }else{
            b[j]=a[i+1];b[j].s++;
            c[j]=a[i];
        }
    }
    for(int i=1,j=1,k=1;i<=2*n;i++){
        if(j<=n&&(k>n||(b[j].s>c[k].s||(b[j].s==c[k].s&&b[j].id<c[k].id))))a[i]=b[j++];
        else a[i]=c[k++];
    }
}
int main(){
    n=read();r=read();q=read();
    for(int i=1;i<=2*n;i++){
        a[i].s=read();
        a[i].id=i;
    }
    for(int i=1;i<=2*n;i++)a[i].w=read();
    sort(a+1,a+2*n+1,cmp);
    for(int i=1;i<=r;i++){
        msort();
    }
    printf("%d",a[q].id);
    return 0;
}

+++++++++++++++++++++++++++++++++++++++++++

 + Author: luyouqi233. +

 + Welcome to my blog: http://www.cnblogs.com/luyouqi233/ +

+++++++++++++++++++++++++++++++++++++++++++

Guess you like

Origin www.cnblogs.com/luyouqi233/p/11312027.html