zoukankan      html  css  js  c++  java
  • BZOJ-1303: [CQOI2009]中位数图 (思想)

    1303: [CQOI2009]中位数图

    Time Limit: 1 Sec  Memory Limit: 162 MB
    Submit: 2988  Solved: 1846
    [Submit][Status][Discuss]

    Description

    给出1~n的一个排列,统计该排列有多少个长度为奇数的连续子序列的中位数是b。中位数是指把所有元素从小到大排列后,位于中间的数。

    Input

    第一行为两个正整数n和b ,第二行为1~n 的排列。

    Output

    输出一个整数,即中位数为b的连续子序列个数。

    Sample Input

    7 4
    5 7 2 4 3 1 6

    Sample Output

    4

    HINT

    第三个样例解释:{4}, {7,2,4}, {5,7,2,4,3}和{5,7,2,4,3,1,6}
    N<=100000

    Source

    前缀和乱搞搞就好了qwq

     1 #include "bits/stdc++.h"
     2 using namespace std;
     3 typedef long long LL;
     4 const int MAX=1e5+5;
     5 LL n,m,p,s[MAX],a[MAX],ans;
     6 inline LL read(){
     7     LL an=0,x=1;char c=getchar();
     8     while (c<'0' || c>'9') {if (c=='-') x=-1;c=getchar();}
     9     while (c>='0' && c<='9') {an=(an<<3)+(an<<1)+c-'0';c=getchar();}
    10     return an*x;
    11 }
    12 int main(){
    13     freopen ("number.in","r",stdin);freopen ("number.out","w",stdout);
    14     LL i,j,x;
    15     n=read();m=read();
    16     for (i=1;i<=n;i++){
    17         x=read();
    18         if (x<m) s[i]=-1;
    19         else if (x>m) s[i]=1;
    20         else p=i;
    21         s[i]+=s[i-1];
    22     }
    23     for (i=0;i<p;i++) a[s[i]+n]++;
    24     for (j=p;j<=n;j++) ans+=a[s[j]+n];
    25     printf("%lld",ans);
    26     return 0;
    27 }
  • 相关阅读:
    性能测试概念
    接口测试概念
    SQL多表查询
    手机App测试概念
    App测试页面滑动
    自动化测试概念
    Monkey 命令
    Tomcat+JDK安装和配置
    Linux系统FTP安装、安装和使用
    Web测试方法(一)
  • 原文地址:https://www.cnblogs.com/keximeiruguo/p/7793633.html
Copyright © 2011-2022 走看看