列表

详情


NC24669. Virtual Youtuber

描述

"Hi Domo, Kizuna AI desu!"

Do you know virtual youtuber which is also known as vtuber? Starts in 2016, today it's one of the most famous streamer types. The most famous one among the is Kizuna AI. There are also a lot of famous vtubers like Kagura Mea and Minato Aqua.



To measure a streamer's work, we can use a popular standard p. In a continuous period, if one's total watchers are more than the popular standard, he/she can be defined as "popular." In other words, if the live data sequence is , then popular means  for some continuous subsequences [l,r].

Ramen wants to become a vtuber too. He has designed a great 3D model (at least he thinks so) and starts live for a while. But when he is going to analysis his live data, he founds that there are few watchers has watched his streaming. He wants to know how bad he is, but he needs to prepare for the next stream, so he gives his live data to you. Can you help him to earn more watchers to become successful?

输入描述

The input contains multiple test cases.

The first line is an integer T(1 <= T <= 20), which indicates the number of test cases. Then T test cases follow.

The first line of each test cases contains two integers n, p(1 <= n <= 1e5, 1 <= p <= 1e18), represents the number of the live data sequence and the popular standard.

The second line contains n integers, represents the live data sequence L1...Ln, Li means that how many watchers were watching his stream in the time point i, 1 <= Li <= 1e12.

输出描述

For each test case, output Case #x: y, where x is the number of the test case(starts from 1) and y is the subsequences that its sum is strictly less than p, regardless of the length.

示例1

输入:

1
13 10
1 2 2 6 6 5 4 8 4 6 1 6 5

输出:

Case #1: 20

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

C++14(g++5.4) 解法, 执行用时: 443ms, 内存消耗: 2024K, 提交时间: 2019-04-14 12:48:22

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+50;
ll pre[N],a[N];
int n;
ll p;
int main(void){
    int T;
    scanf("%d",&T);
    for(int cas=1;cas<=T;cas++){
        scanf("%d%lld",&n,&p);
        for(int i=1;i<=n;i++){
            scanf("%lld",&a[i]);
            pre[i]=pre[i-1]+a[i];
        }
        ll ans=0;
        for(int i=1;i<=n;i++){
            int k=lower_bound(pre+1,pre+1+n,pre[i-1]+p)-pre-1;
            ans+=(1ll*(k-i+1));
            //printf("%d\n",k);
        }
        printf("Case #%d: %lld\n",cas,ans);
    }
    return 0;
}

C++11(clang++ 3.9) 解法, 执行用时: 491ms, 内存消耗: 3448K, 提交时间: 2019-04-16 14:21:10

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=1e5+10;
ll s[N];
int main(){
	int t,n; 
	ll x,p;
	scanf("%d",&t);
	for(int k=1;k<=t;k++){
		scanf("%d%lld",&n,&p);
		 s[0]=0;
		for(int i=1;i<=n;i++){
			scanf("%lld",&x);
			s[i]=s[i-1]+x;
		}
		ll cnt=0;
		for(int i=1;i<=n;i++)
		{
			int cur=lower_bound(s+i,s+n+1,s[i-1]+p)-s;
			cnt+=cur-i;
		}
		printf("Case #%d: %lld\n",k,cnt);
	}
	return 0;
}

上一题