-
Notifications
You must be signed in to change notification settings - Fork 0
/
3770.cpp
52 lines (48 loc) · 914 Bytes
/
3770.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
using namespace std;
const int N=100100;
const int M=512;
const int C=26;
char a[N];
char s[M];
int l[M],r[M],x[N],y[N],t[N];
int f[N][C];
int n,m,i,j,k,u,v,w,sum;
long long ans;
int main(){
scanf("%s",a+1);
n=strlen(a+1);
scanf("%d%d%d",&m,&u,&v);
for(i=1;i<=m;i++){
scanf("%s%d%d",s+i,&l[i],&r[i]);
s[i]-='a';
}
for(i=n;i;i--){
a[i]-='a';
for(j=0;j<C;j++)f[i][j]=f[i+1][j];
f[i][a[i]]++;
}
for(i=0;i<C;i++)f[0][i]=f[1][i];
t[0]=-m;
for(i=1;i<=n;i++){
sum+=t[i]>=u && t[i]<=v;
for(j=1;j<=m;j++){
for(;x[j]<=i && f[x[j]][s[j]]-f[i+1][s[j]]>=l[j];x[j]++){
if(t[x[j]]==v)sum--;
t[x[j]]++;
if(t[x[j]]==u)sum++;
}
for(;y[j]<=i && f[y[j]][s[j]]-f[i+1][s[j]]>r[j];y[j]++){
if(t[y[j]]==u)sum--;
t[y[j]]--;
if(t[y[j]]==v)sum++;
}
}
ans+=sum;
}
printf("%lld\n",ans);
return 0;
}