| 比赛 |
期末考试1 |
评测结果 |
WWWTTWWAWW |
| 题目名称 |
Interactive |
最终得分 |
10 |
| 用户昵称 |
汐汐很希希 |
运行时间 |
2.870 s |
| 代码语言 |
C++ |
内存使用 |
4.42 MiB |
| 提交时间 |
2026-02-08 11:49:36 |
显示代码纯文本
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=2e5+10;
const int M=2e5+10;
const int MOD=1e9+7;
const int MAXX=2e9;
int n,k,q,a[N],mr[N];
int main()
{
freopen("tioj_interactive.in","r",stdin);
freopen("tioj_interactive.out","w",stdout);
cin>>n>>k;
for(int i=0;i<n;i++) cin>>a[i];
if(k>0){
int r=0;
ll sum=0;
for(int l=0;l<n;l++){
mr[l]=-1;
while(r<n&&sum<k){
sum+=a[r];
r++;
}
if(sum>=k) mr[l]=r-1;
sum-=a[l];
}
}
cin>>q;
for(int i=0;i<q;i++){
int x;
cin>>x;
ll ans=0;
if(k<=0){
int mlen=min(x,n);
ans=1LL*mlen*(2*n-mlen+1)/2;
}else{
for(int l=0;l<n;l++){
if(mr[l]==-1) continue;
int rp=mr[l];
int rmax=min(l+x-1,n-1);
if(rp<=rmax){
ans+=(rmax-rp+1);
}
}
}
cout<<ans<<endl;
}
return 0;
}