zoukankan      html  css  js  c++  java
  • HDU 5806 NanoApe Loves Sequence Ⅱ

    将大于等于m的数改为1,其余的改为0。问题转变成了有多少个区间的区间和>=k。可以枚举起点,二分第一个终点 或者尺取法。

    #pragma comment(linker, "/STACK:1024000000,1024000000")
    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<algorithm>
    #include<vector>
    #include<map>
    #include<set>
    #include<queue>
    #include<stack>
    #include<iostream>
    using namespace std;
    typedef long long LL;
    const double pi=acos(-1.0),eps=1e-8;
    void File()
    {
        freopen("D:\in.txt","r",stdin);
        freopen("D:\out.txt","w",stdout);
    }
    inline int read()
    {
        char c = getchar();  while(!isdigit(c)) c = getchar();
        int x = 0;
        while(isdigit(c)) { x = x * 10 + c - '0'; c = getchar(); }
        return x;
    }
    
    const int maxn=200000+10;
    int T,n,m,k,a[maxn],sum[maxn];
    
    int main()
    {
        scanf("%d",&T);
        while(T--)
        {
            scanf("%d%d%d",&n,&m,&k); sum[0]=0;
            for(int i=1;i<=n;i++)
            {
                scanf("%d",&a[i]);
                if(a[i]>=m) a[i]=1;
                else a[i]=0;
                sum[i]=sum[i-1]+a[i];
            }
            LL ans=0;
    
            for(int i=1;i<=n;i++)
            {
                int L=i,R=n,pos=-1;
                while(L<=R)
                {
                    int mid=(L+R)/2;
                    if(sum[mid]-sum[i-1]>=k) pos=mid,R=mid-1;
                    else L=mid+1;
                }
                if(pos==-1) continue;
                ans=ans+n-pos+1;
            }
            printf("%lld
    ",ans);
        }
        return 0;
    }
  • 相关阅读:
    前端工程化
    前端模块化CommonJS&ES6
    为什么浮点型运算结果会有误差?
    RequestAnimationFrame知多少?
    CSS三栏布局
    秋招面试
    实现Storage
    Angular
    TypeScript
    微服务架构设计模式
  • 原文地址:https://www.cnblogs.com/zufezzt/p/5747329.html
Copyright © 2011-2022 走看看