zoukankan      html  css  js  c++  java
  • bzoj1303

    数学题

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<cmath>
     4 #include<ctime>
     5 #include<cstdlib>
     6 #include<iostream>
     7 #include<algorithm>
     8 #define clr(a,x) memset(a,x,sizeof(a))
     9 #define rep(i,l,r) for(int i=l;i<r;i++)
    10 #define down(i,r,l) for(int i=r;i>=l;i--)
    11 typedef long long ll;
    12 using namespace std;
    13 int read()
    14 {
    15     char c=getchar();
    16     int ans=0,f=1;
    17     while(!isdigit(c)){
    18         if(c=='-') f=-1;
    19         c=getchar();
    20     }
    21     while(isdigit(c)){
    22         ans=ans*10+c-'0';
    23         c=getchar();
    24     }
    25     return ans*f;
    26 }
    27 const int maxn=100005;
    28 int a[maxn],l[maxn<<1],r[maxn<<1],s[maxn],pos;
    29 int main()
    30 {
    31     int n=read(),b=read();
    32     rep(i,0,n){
    33         int t=read();
    34         if(t>b) a[i]=1;
    35         else if(t<b) a[i]=-1;
    36         else {
    37             a[i]=0;
    38             pos=i;
    39         }
    40     }
    41     l[n]=r[n]=1;
    42     down(i,pos-1,0){
    43         s[i]=s[i+1]+a[i];
    44         ++l[n+s[i]];
    45     }
    46     rep(i,pos+1,n){
    47         s[i]=s[i-1]+a[i];
    48         ++r[n+s[i]];
    49     }
    50     ll ans=0;
    51     rep(i,0,n<<1){
    52         ans+=l[i]*r[(n<<1)-i];
    53     }
    54     printf("%lld
    ",ans);
    55     return 0;
    56 }
    View Code

    1303: [CQOI2009]中位数图

    Time Limit: 1 Sec  Memory Limit: 162 MB
    Submit: 1627  Solved: 1060
    [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

     
    [Submit][Status][Discuss]
  • 相关阅读:
    Anaconda安装之路——坑呀!
    初读《企业应用架构模式》——阅读笔记1
    《需求工程》阅读笔记3
    codeforces 432D. Prefixes and Suffixes(后缀数组)
    hdu 6096String(trie树)
    uva 1349 Optimal Bus Route Design(拆点,费用流)
    数据结构c语言
    六个排序算法
    c无聊编程
    文件写入与文件读取
  • 原文地址:https://www.cnblogs.com/chensiang/p/4667015.html
Copyright © 2011-2022 走看看