Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ┓┏┓┏┓┃
- ┛┗┛┗┛┃
- ┓┏┓┏┓┃
- ┛┗┛┗┛┃
- ┓┏┓┏┓┃\○/
- ┛┗┛┗┛┃ / /
- ┓┏┓┏┓┃ノ
- ┛┗┛┗┛┃
- ┓┏┓┏┓┃
- ┛┗┛┗┛┃
- ┓┏┓┏┓┃
- ┛┗┛┗┛┃
- ┓┏┓┏┓┃
- ┛┗┛┗┛┃
- ┓┏┓┏┓┃┓
- ┛┗┛┗┛┃┃
- MIPTCLASSICMIPTCLASSICMIPTCLASSICMIPTCLASSICMIPTCLASSICMIPTCLASSIC
- */
- // #define pragma
- #ifdef pragma
- #pragma GCC optimize("Ofast")
- #pragma GCC optimize("no-stack-protector")
- #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
- #pragma GCC optimize("unroll-loops")
- #pragma GCC diagnostic ignored "-Wunused-result"
- #endif // pragma
- #include<bits/stdc++.h>
- #include <ext/pb_ds/assoc_container.hpp>
- #include <ext/pb_ds/tree_policy.hpp>
- #define ll long long
- #define all(x) begin(x), end(x)
- #define pb push_back
- #define x first
- #define y second
- #define int long long
- #define zero(two) memset(two, 0, sizeof(two))
- using namespace std;
- using namespace __gnu_pbds;
- typedef vector<int> vi;
- typedef vector<bool> vb;
- typedef pair<int, int> pii;
- typedef long double ld;
- typedef vector<vi> matrix;
- template<typename T>
- using kawaii_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
- const ld PI = atan2(0, -1);
- void seriy() {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- cout << fixed << setprecision(10);
- #if 1
- freopen("input", "r", stdin);
- freopen("output", "w", stdout);
- #endif
- }
- const int MAXN = 1e6 + 10;
- vi p(MAXN), cnt(MAXN), c(MAXN);
- vi pn(MAXN), cn(MAXN);
- signed main() {
- seriy();
- string t, s;
- cin >> t >> s;
- int n = s.size();
- int m = t.size();
- for(int i = 0; i < n; i++) {
- cnt[s[i]]++;
- }
- for(int i = 1; i < MAXN; i++) {
- cnt[i] += cnt[i - 1];
- }
- for(int i = 0; i < n; i++) {
- p[--cnt[s[i]]] = i;
- }
- c[p[0]] = 0;
- int cur = 1;
- for(int i = 1; i < n; i++) {
- if (s[p[i]] != s[p[i - 1]]) {
- ++cur;
- }
- c[p[i]] = cur - 1;
- }
- for(int h = 0; (1 << h) < n; ++h) {
- for(int i = 0; i < n; i++) {
- pn[i] = (p[i] + n - (1 << h)) % n;
- }
- cnt.assign(MAXN, 0);
- for(int i = 0; i < n; i++) {
- cnt[c[pn[i]]]++;
- }
- for(int i = 1; i < cur; i++) {
- cnt[i] += cnt[i - 1];
- }
- for(int i = n - 1; i >= 0; i--) {
- p[--cnt[c[pn[i]]]] = pn[i];
- }
- cn[p[0]] = 0;
- cur = 1;
- for(int i = 1; i < n; i++) {
- int m1 = (p[i] + (1 << h)) % n, m2 = (p[i - 1] + (1 << h)) % n;
- if (c[p[i]] != c[p[i - 1]] || c[m1] != c[m2]) {
- cur++;
- }
- cn[p[i]] = cur - 1;
- }
- c = cn;
- }
- for(int i = 0; i < n; i++) {
- cerr << p[i] << " ";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement