zoukankan      html  css  js  c++  java
  • noip提高组2013 火柴排队(luogu 1966)

    题目链接:https://www.luogu.org/problem/show?pid=1966

    这个题啊,naive(虽然我不会证明)。

    举了个特例,得出结论:对于两列数,一定是最大与最大的相对,最小的与最小的相对。

    然后就以离散化一下,然后随便用个树状数组求个逆序对就好了。

    一开始我还分别写了两个逆序对,想求个差的绝对值,发现样例过不了之后。。。。。。

    #include<cstdio>
    #include<algorithm>
    using namespace std;
    const int mod=99999997;
    void read(int &y)
    {
      y=0;char x=getchar();
      while(x<'0'||x>'9') x=getchar();
      while(x>='0'&&x<='9')
      {
        y=y*10+x-'0';
        x=getchar();
      }
    }
    int ans,n,p[100005],t[400005];
    struct h
    {
      int x,s;
    }a[100005],b[100005];
    bool cmp(h x,h y)
    {
      return x.s<y.s;
    }
    int lowbit(int x){return (x)&(-x);}
    int abs(int x){return x>=0 ? x : -x;}
    void add(int x,int s)
    {
      while(x<=n)
      {
        t[x]+=s;
        x+=lowbit(x);
      }
    }
    int quary(int x)
    {
      int s=0;
      while(x)
      {
        s+=t[x];
        s%=mod;
        x-=lowbit(x);
      }
      return s;
    }
    int main()
    {
      read(n);
      for(int i=1;i<=n;i++)
      {
        read(a[i].s);
        a[i].x=i;
      }
      for(int i=1;i<=n;i++)
      {
        read(b[i].s);
        b[i].x=i;
      }
      sort(b+1,b+n+1,cmp);
      sort(a+1,a+n+1,cmp);
      for(int i=1;i<=n;i++) p[a[i].x]=b[i].x;
      for(int i=1;i<=n;i++)
      {
        ans+=i-1-quary(p[i]);
        add(p[i],1);
        ans%=mod;
      }
     // for(int i=1;i<=n;i++) printf("%d ",p[i]);
      printf("%d",ans);
      return 0;
    }

  • 相关阅读:
    win10 安装ZIP Archive解压版 mysql 以及初始化配置
    python 协程, 异步IO Select 和 selectors 模块 多并发演示
    Python 标准库
    GRUB (简体中文)
    收集了一些python的文章
    SQL注入中的WAF绕过技术
    使用sqlmap中tamper脚本绕过waf
    在Linode VPS上搭建最新版Transmission
    在Linode VPS上搭建离线下载神器Aria2+WEBUI管理及对国内云盘看法
    我的渗透利器
  • 原文地址:https://www.cnblogs.com/zeroform/p/7544557.html
Copyright © 2011-2022 走看看