#include <bits/stdc++.h> using namespace std; #define mp make_pair #define ff first #define ss second #define eb emplace_back typedef long long int ll; inline void readUI(int *i) { register int t=0; register char z=getchar_unlocked(); while (z<'0' && '9'<z) { z=getchar_unlocked(); } while ('0'<=z && z<='9') { t=(t<<3)+(t<<1)+z-'0'; z=getchar_unlocked(); } *i=t; } #define debug if(1) #define MAXN 200005 int n; char s[MAXN]; bitset <MAXN> zabr; bitset <32> sam; int najb[MAXN]; int inf=(1e9); ll wynik; int main() { scanf ("%s", s); sam[1]=sam[5]=sam[9]=sam[15]=sam[21]=sam[25]=true; n=strlen(s); if (n<3) { puts ("0"); return 0; } for (int i=n; i>=1; --i) { s[i]=s[i-1]; } najb[n-1]=inf; for (int i=n-2; i>=1; --i) { najb[i]=najb[i+1]; if (sam[int(s[i])-96]==sam[int(s[i+1])-96] && sam[int(s[i])-96]==sam[int(s[i+2])-96]) { zabr[i]=true; najb[i]=i; } if (najb[i]==inf) { continue; } int poz=najb[i]+2; wynik+=n-poz+1; } printf ("%lld\n", wynik); return 0; }
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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | #include <bits/stdc++.h> using namespace std; #define mp make_pair #define ff first #define ss second #define eb emplace_back typedef long long int ll; inline void readUI(int *i) { register int t=0; register char z=getchar_unlocked(); while (z<'0' && '9'<z) { z=getchar_unlocked(); } while ('0'<=z && z<='9') { t=(t<<3)+(t<<1)+z-'0'; z=getchar_unlocked(); } *i=t; } #define debug if(1) #define MAXN 200005 int n; char s[MAXN]; bitset <MAXN> zabr; bitset <32> sam; int najb[MAXN]; int inf=(1e9); ll wynik; int main() { scanf ("%s", s); sam[1]=sam[5]=sam[9]=sam[15]=sam[21]=sam[25]=true; n=strlen(s); if (n<3) { puts ("0"); return 0; } for (int i=n; i>=1; --i) { s[i]=s[i-1]; } najb[n-1]=inf; for (int i=n-2; i>=1; --i) { najb[i]=najb[i+1]; if (sam[int(s[i])-96]==sam[int(s[i+1])-96] && sam[int(s[i])-96]==sam[int(s[i+2])-96]) { zabr[i]=true; najb[i]=i; } if (najb[i]==inf) { continue; } int poz=najb[i]+2; wynik+=n-poz+1; } printf ("%lld\n", wynik); return 0; } |