zoukankan      html  css  js  c++  java
  • bzoj1303: [CQOI2009]中位数图

    bzoj1303: [CQOI2009]中位数图

     代码如下:

     1 #include <queue>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <iostream>
     5 #include <algorithm>
     6 using namespace std;
     7 typedef long long ll;
     8 inline void read(int &x){
     9     x=0;char ch;bool flag = false;
    10     while(ch=getchar(),ch<'!');if(ch == '-') ch=getchar(),flag = true;
    11     while(x=10*x+ch-'0',ch=getchar(),ch>'!');if(flag) x=-x;
    12 }
    13 inline int cat_max(const int &a,const int &b){return a>b ? a:b;}
    14 inline int cat_min(const int &a,const int &b){return a<b ? a:b;}
    15 const int maxn = 1000010;
    16 #define f(x) (x == m ? 0 : (x < m ? -1 : 1) )
    17 int a[maxn],l[maxn],r[maxn];
    18 int s[maxn];
    19 int main(){
    20  
    21     int n,m;read(n);read(m);
    22     int p = -1;
    23     for(int i=1,x;i<=n;++i){
    24         read(x);a[i] = f(x);
    25         if(a[i] == 0) p = i;
    26     }
    27     for(int i=p-1;i>=1;--i) s[i] = a[i] + s[i+1],++l[s[i]+n];
    28     for(int i=p+1;i<=n;++i) s[i] = a[i] + s[i-1],++r[s[i]+n];
    29     int ans = 0;++l[n];++r[n];
    30     for(int i=0;i<(n<<1);++i) ans += l[i]*r[(n<<1)-i];
    31     printf("%d
    ",ans);
    32     //getchar();getchar();
    33     return 0;
    34 }
    人就像命运下的蝼蚁,谁也无法操控自己的人生.
  • 相关阅读:
    需要我们了解的SQL Server阻塞原因与解决方法
    SQL Server应用模式之OLTP系统性能分析
    第一章 scala环境搭建
    IO
    装饰器模式
    java 泛型方法
    文件格式转换
    spring ioc
    深入浅出Java模式设计之模板方法模式
    struts2
  • 原文地址:https://www.cnblogs.com/Skyminer/p/6024258.html
Copyright © 2011-2022 走看看