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

      比b小的设为-1,大的设为1,前缀和搞一下就行了

    #include<iostream>
    #include<cstring>
    #include<cstdlib>
    #include<cstdio> 
    #include<algorithm>
    #define ll long long 
    using namespace std;
    const int maxn=500010,inf=1e9;
    int n,b,x,pos;
    int a[maxn],v[maxn];
    ll ans;
    void read(int &k)
    {
        int f=1;k=0;char c=getchar();
        while(c<'0'||c>'9')c=='-'&&(f=-1),c=getchar();
        while(c<='9'&&c>='0')k=k*10+c-'0',c=getchar();
        k*=f;
    }
    int main()
    {
        read(n);read(b);
        for(int i=1;i<=n;i++)
        {
            read(x);
            if(x<b)a[i]=-1;
            else if(x>b)a[i]=1;
            else a[i]=0,pos=i;
            a[i]+=a[i-1];
        }
        for(int i=0;i<pos;i++)v[a[i]+n]++;
        for(int i=pos;i<=n;i++)ans+=v[a[i]+n];
        printf("%lld
    ",ans);
        return 0;
    }
    View Code
  • 相关阅读:
    2014-04-23 总结
    14-5-13
    PHP
    14-5-8
    ajax
    14-5-6
    14-5-5
    PHP初解
    14-4-30
    14-4-29
  • 原文地址:https://www.cnblogs.com/Sakits/p/7448452.html
Copyright © 2011-2022 走看看