zoukankan      html  css  js  c++  java
  • P1966 火柴排队

    P1966 火柴排队

    那个数组绕绕的qwq。看看题大概就能猜到是逆序对,可以用切比雪夫不等式证明。就是让a中第1大的、第2大的、第3大的……对应b中第1大的、第2大的、第3大的……

    #include<bits/stdc++.h>
    using namespace std;
    #define int long long
    const int mod=99999997;
    const int N=100005;
    struct node{
    	int rk,val;
    	bool operator < (const node &rhs)const {return val<rhs.val;}
    }a[N],b[N];
    int c[N],n,ans,r[N];
    void msort(int ll,int rr) {
    	if(ll==rr)return;
    	int mid=(ll+rr)>>1;
    	msort(ll,mid);msort(mid+1,rr);
    	int i=ll,j=mid+1,k=ll;
    	while(i<=mid&&j<=rr) {
    		if(c[i]>c[j]) {
    			ans=(ans+mid-i+1)%mod;
    			r[k++]=c[j++];
    		} else r[k++]=c[i++];
    	}
    	while(i<=mid)r[k++]=c[i++];
    	while(j<=rr)r[k++]=c[j++];
    	for(int i=ll;i<=rr;++i)c[i]=r[i];
    }
    signed main() {
    	scanf("%lld",&n);
    	for(int i=1;i<=n;++i)scanf("%lld",&a[i].val),a[i].rk=i;
    	for(int i=1;i<=n;++i)scanf("%lld",&b[i].val),b[i].rk=i;
    	sort(a+1,a+n+1),sort(b+1,b+n+1); 
    	for(int i=1;i<=n;++i)c[a[i].rk]=b[i].rk;
    	msort(1,n);
    	printf("%lld
    ",ans);
    	return 0;
    }
    
    路漫漫其修远兮,吾将上下而求索
  • 相关阅读:
    rsync
    SAMBA服务搭建
    top,job,user,file,alias
    FTP服务搭建
    shell_script2
    shell_script1
    shell_processing
    shell_advanced
    shell_basic
    docker搭建私有仓库遇到的坑 http: server gave HTTP response to HTTPS client
  • 原文地址:https://www.cnblogs.com/zzctommy/p/12379902.html
Copyright © 2011-2022 走看看