Pagini recente » Cod sursa (job #3216278) | Cod sursa (job #1753069) | Cod sursa (job #2573165) | Cod sursa (job #217682) | Cod sursa (job #1471411)
#define _CRT_SECURE_NO_DEPRECATE
#include <stdlib.h>
#include <stdio.h>
#include <algorithm>
#include <cstring>
#define MAXDIM 10000005 + (50000 * 21)
#define pw (1 << (i - 1))
using namespace std;
int N, P[MAXDIM], Hash[8001], Log[21], pos, ans;
char A[MAXDIM];
struct entry{
int no[2], p;
} L[MAXDIM];
inline bool cmp(const entry x, const entry y){
return x.no[0] != y.no[0] ? x.no[0] < y.no[0] : x.no[1] < y.no[1];
}
int main(){
freopen("abc2.in", "r", stdin);
freopen("abc2.out", "w", stdout);
N = int(fread(A, sizeof(char), MAXDIM, stdin));
/*
int length = 0;
for (int i = 0, c = 1; i < N; ++i){
if (A[i] < 'a' || A[i] > 'c') ++c;
else {
Part[i] = c, P[i] = A[i];
if (!pos && c == 2) pos = i;
if (c == 2) ++length;
}
}
for (int i = 2; i <= length; ++i) Log[i] = Log[i / 2] + 1;
Log[0] = -1;
int len;
for (int i = 1; 1 << i <= length; ++i){
len = -1;
for (int j = 0; j < N; ++j)
if (!P[j]) continue;
else L[++len].no[0] = P[j],
L[len].no[1] = Part[j] == Part[j + pw] ? P[j + pw] : -1,
L[len].p = j;
sort(L, L + len + 1, cmp);
for (int j = 0, c = 0; j <= len; ++j)
P[L[j].p] = !j ? ++c : (L[j].no[0] == L[j - 1].no[0] && L[j].no[1] == L[j - 1].no[1] ? P[L[j - 1].p] : ++c);
}
if (Log[length] == Log[length - 1]){
len = -1;
for (int j = 0; j < N; ++j)
if (P[j]){
L[++len].no[0] = P[j],
L[len].no[1] = Part[j + length - (1 << Log[length])] == Part[j] ? P[j + length - (1 << Log[length])] : -1,
L[len].p = j;
}
sort(L, L + len + 1, cmp);
}
for (int j = 0, c = 0; j <= len; ++j){
if (!j){
P[L[j].p] = ++c;
if (Part[L[j].p] == 1) ++Hash[c];
}
else if (L[j].no[0] == L[j - 1].no[0] && L[j].no[1] == L[j - 1].no[1]){
P[L[j].p] = P[L[j - 1].p];
if (Part[L[j].p] == 1) ++Hash[P[L[j].p]];
}
else {
P[L[j].p] = ++c;
if (Part[L[j].p] == 1) ++Hash[c];
}
}
while (pos < N){
ans += Hash[P[pos]];
Hash[P[pos]] = 0;
pos += length + 1;
}
*/
printf("%d\n", ans);
return 0;
}