• 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;
    }
  • 相关阅读:
    1093 Count PAT's(25 分)
    1089 Insert or Merge(25 分)
    1088 Rational Arithmetic(20 分)
    1081 Rational Sum(20 分)
    1069 The Black Hole of Numbers(20 分)
    1059 Prime Factors(25 分)
    1050 String Subtraction (20)
    根据生日计算员工年龄
    动态获取当前日期和时间
    对计数结果进行4舍5入
  • 原文地址:https://www.cnblogs.com/zufezzt/p/5747329.html
Copyright © 2020-2023  润新知