include iostream include iomanip include vector include queue include

 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <iterator>
#include <string>
#include <algorithm>
#include <sstream>
#include <cmath>
using namespace std;
#define pb push_back
#define mp make_pair
#define make_state make_pair
#define all(x) x.begin(),x.end()
#define forn(x) for(int i=0;i<x;i++)
typedef long double T;
typedef long long ll;
typedef unsigned char uchar;
const int IMPOSSIBLE = -1;
uchar dist[256][256];
void precalc() {
for(int i = 0; i < 256; i++) {
for(int j = 0; j < 256; j++) {
bool found = false;
for(int k = 0; k <= 8; k++) {
uchar mask = (1LL << k) - 1;
if((i ^ mask) == j)
dist[i][j] = k, found = true;
}
if(!found) dist[i][j] = IMPOSSIBLE;
}
}
}
typedef vector<uchar> sequence;
sequence s;
const int p = 271;
const int N = 250010;
ll pows[N];
ll h[N];
inline void init(){
pows[0] = -1;
for (int i = 1; i < N; ++i)
pows[i] = pows[i - 1] * p;
}
void makeh() {
h[0] = 0;
for (int i = 0; i < (int)s.size(); ++i)
h[i + 1] = h[i] * p + s[i] + 1;
}
inline ll gethash(int l, int r) {//[l, r];
return h[r] + h[l] * pows[r - l];
}
inline int lcp(int a, int b){
int l = 0;
int r = min(s.size() - a, s.size() - b);
while (r - l > 1){
int m = (r + l) / 2;
if (gethash(a, a + m) == gethash(b, b + m)) l = m;
else m = r;
}
return l;
}
inline bool cmp(int l, int r){
int LCP = lcp(l, r);
if (l + LCP == (int)s.size()) return true;
if (r + LCP == (int)s.size()) return false;
return s[l + LCP] < s[r + LCP];
}
int main() {
ios_base::sync_with_stdio(false);
// freopen("in.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
precalc();
return 0;
}