Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //#define _GLIBCXX_DEBUG
- #define FAST_ALLOCATOR_MEMORY 2e8
- #ifdef _DEBUG
- #include "opt.h"
- #endif
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- typedef pair<int, int> pii;
- typedef vector<int> vi;
- typedef unsigned long long ull;
- #define mk make_pair
- #define inb push_back
- #define X first
- #define Y second
- #define all(v) v.begin(), v.end()
- #define sqr(x) (x) * (x)
- int solve();
- int main()
- {
- //ios_base::sync_with_stdio(0);
- //cin.tie(0);
- #define TASK "carno"
- #ifndef _DEBUG
- //freopen(TASK".in", "r", stdin), freopen(TASK".out", "w", stdout);
- #endif
- solve();
- }
- const int SZ = (1 << 16) - 1;
- const int P = 239;
- struct HashTable
- {
- vector<ull> a;
- vector<short int> was;
- short int cursession;
- HashTable() { a.resize(SZ), was.resize(SZ), cursession = 0; };
- void put(ull x, int &ans)
- {
- int i = x & SZ;
- if (i == SZ)
- i = 0;
- while (was[i] == cursession && a[i] != x)
- {
- ++i;
- if (i == SZ)
- i = 0;
- }
- if (was[i] != cursession || a[i] != x)
- ++ans, a[i] = x, was[i] = cursession;
- }
- };
- int solve()
- {
- int ans = 0;
- char *s = new char[20000];
- readWord(s);
- HashTable T;
- short int n = strlen(s);
- vector <ull> p(n + 1), h(n);
- p[0] = 1;
- for (short int i = 1; i <= n; ++i)
- p[i] = p[i - 1] * P;
- h[0] = s[0] - 'a' + 1;
- for (int i = 1; i < n; ++i)
- h[i] = h[i - 1] * P + s[i] - 'a' + 1;
- ull ch;
- for (short int len = 1; len <= n; ++len)
- {
- ch = h[len - 1];
- T.cursession++;
- T.put(ch, ans);
- for (int i = len; i < n; ++i)
- {
- ch = (ch - (s[i - len] - 'a' + 1) * p[len - 1]) * P + s[i] - 'a' + 1;
- T.put(ch, ans);
- }
- }
- writeInt(ans, '\n');
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement