题解:用二分查询一下每次满足长度的下一个加上它的长度。
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[500005];
ll b[500005] = {0};
int main()
{
ll n,i,j,k,p=1,l,r;
char c;
memset(a,0,sizeof(a));
while((c=getchar()) != '
')
{
if(c == ' '){a[p]++;p++;}
else a[p]++;
}
a[p]++;
for(i = 1; i <= p; i++)b[i] = b[i - 1] + a[i];
ll sum,ans;
scanf("%lld%lld",&l,&r);
for(k=l + 1;k<=r + 1;k++)
{
ans = 0;
int qwe = 0;
for(i=1;i<=p;)
{
if(i == 1)
{
ans += a[1] - 1;
qwe++;
i = upper_bound(b + 1, b + p + 1, k + b[i - 1]) - (b);
ans += a[i] - 1;
qwe++;
}
else
{
i = upper_bound(b + 1, b + p + 1, k + b[i - 1]) - (b);
ans += a[i] - 1;
qwe++;
}
}
printf("%lld
",ans + qwe - 1);
}
return 0;
}