QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#561132 | #8223. 字符串游戏 | The_cosmos | 5 | 490ms | 501264kb | C++14 | 3.1kb | 2024-09-12 20:31:16 | 2024-09-12 20:31:17 |
Judging History
answer
#include <bits/stdc++.h>
#define REP(i, first, last) for(int i = (first); i <= (last); ++ i)
#define DOW(i, first, last) for(int i = (first); i >= (last); -- i)
using namespace std;
// #define int long long
#define pb emplace_back
#define ull unsigned long long
const int N = 2e6 + 5, M = 2e5 + 5, Sg = 26;
const int mod1 = 1e9 + 9, mod2 = 998244353;
const long long inf = 1e18;
const int dx[] = {-1, -1, -1, 0, 0, 0, 1, 1, 1};
const int dy[] = {-1, 0, 1, -1, 0, 1, -1, 0, 1};
const int P = 1ll << 21, S = P - 1;
struct Graph {
struct edge { int from, to, next; int w; } e[N << 1]; int cnt, n, head[N];
void ins(int u, int v, int w = 0) { e[++ cnt] = {u, v, head[u], w}, n = max({n, u, v}), head[u] = cnt; }
void twi(int u, int v, int w = 0) { ins(u, v, w), ins(v, u, w); }
void clear() { for (int i = 1; i <= cnt; i ++) head[e[i].from] = 0; cnt = 0; }
#define FEG(u, v, W, G, i) \
for (int i = G.head[u], v = G.e[i].to, W = G.e[i].w; i; i = G.e[i].next, v = G.e[i].to, W = G.e[i].w)
} G;
struct SAM {
struct imfor {
int ch[27];
int len, fa;
} s[N << 1];
int lst = 1, tot = 1;
int siz[N << 1];
void Ins(int c) {
int p = lst, np = ++ tot;
lst = np, s[np].len = s[p].len + 1;
while(p && !s[p].ch[c])
s[p].ch[c] = np, p = s[p].fa;
if(!p) s[np].fa = 1;
else {
int q = s[p].ch[c];
if(s[q].len == s[p].len + 1) s[np].fa = q;
else {
int nq = ++ tot;
s[nq] = s[q];
s[nq].len = s[p].len + 1;
s[q].fa = s[np].fa = nq;
while(p && s[p].ch[c] == q)
s[p].ch[c] = nq, p = s[p].fa;
}
}
}
void Build() { REP(i, 2, tot) G.ins(s[i].fa, i); }
} sam;
template <typename T>
struct Fenwick {
int n; vector<T> c;
void resize(int x) { n = x, c.resize(n + 1); }
void clear() { c.assign(n + 1, 0); }
void upd(int x) { int val = 1; for (; x <= n; x += x & -x) c[x] += val; }
T ask(int x) { T r = 0; for (x = min(x, n); x; x -= x & -x) r += c[x]; return r; }
};
Fenwick<int> fw;
int n, pl[N], fa[N][25], dfn[N], low[N], idx;
char s[N];
void build(int x, int lst) {
fa[x][0] = lst, dfn[x] = ++ idx;
for(int i = 1; fa[x][i - 1]; i ++)
fa[x][i] = fa[fa[x][i - 1]][i - 1];
FEG(x, v, w, G, i) build(v, x);
low[x] = idx;
}
int f[N];
void upd(int x) {
// cerr << pl[x] << '\n';
fw.upd(dfn[pl[x]]);
}
int qry(int l, int r) {
l = r - l + 1, r = pl[r];
DOW(i, 21, 0) if(sam.s[fa[r][i]].len >= l) r = fa[r][i];
return fw.ask(low[r]) - fw.ask(dfn[r] - 1);
}
stack<int> st;
void Solve() {
cin >> (s + 1), fw.resize(N);
n = strlen(s + 1);
reverse(s + 1, s + n + 1);
REP(i, 1, n) sam.Ins(s[i] - 97), pl[i] = sam.lst;
sam.Build(), build(1, 0);
// cerr << "qwq";
REP(i, 1, n) {
f[i] = 1, upd(i);
// cerr << "qwq\n";
while(!st.empty() && f[i] <= f[st.top()]) {
f[i] = max(f[i], qry(st.top() + 1, i) - f[st.top()]);
st.pop();
}
st.push(i);
}
cout << f[n] << '\n';
}
signed main() {
// freopen(".in", "r", stdin);
// freopen(".out", "w", stdout);
ios::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
int T = 1;
// cin >> T;
while (T --) {
Solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 3ms
memory: 25332kb
input:
abbabbbbabbaaaaabbbaabaaaaaabbbaabbabababaabababaababaaaaaabaaabaaabbbbababaaabbbabababbbabbbaabaaababbbaabaabbaaabbababaaaaabbbaabaaabbaabaabaaabaaabaababaabbbbbbbbabbbbbabbbaabababbaababbbbbabbbbaaabbaabaabaaabbabbaaabbaaababaabbbaabbbaaaabbababbabaababababaaaabbaaaabaabaaaababaaabababbbaaabababbb...
output:
1512
result:
wrong answer 1st lines differ - expected: '1281', found: '1512'
Subtask #2:
score: 0
Wrong Answer
Test #11:
score: 0
Wrong Answer
time: 490ms
memory: 501264kb
input:
aaaaaaabbaaabbbbabbabbbababaabaaabaabbaaababaaaaaabbbbbaabbbabbbaabbabaababaababaabbbababbbabaaaaaaaaabaaaaabbbabbbbbabaaabaaaababbabbbbbbaabbbbbaababbbbababbbbbbbbbbbaaabbabbaababbaaaabbabaaabbaaabbbbaaababbbbbabbaababbaaababaaabbabaabbbbabbaaabbababbaabbaaaaaaaaaabababbbaaaababbabbbabbababbabbabbb...
output:
357869
result:
wrong answer 1st lines differ - expected: '234567', found: '357869'
Subtask #3:
score: 5
Accepted
Test #16:
score: 5
Accepted
time: 272ms
memory: 312664kb
input:
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
493827
result:
ok single line: '493827'
Subtask #4:
score: 0
Wrong Answer
Test #17:
score: 0
Wrong Answer
time: 57ms
memory: 94368kb
input:
bbbbbbbbbaabbbbbabaaabaabaaabaaaaabaaaabbbbbbbaaaabaabbbababbaaaabbabababbbabbbbabbabaabaaabbabbaaababaaabaaaabababbbbbbbaabbaaabbabbbbbabbbaaaaababbbaaabaabababbabbabababbabbabaaaaabaaaaaabbbabaabbbaaaabbabababaaababaabbbbbbbaaabbbabaabaaaabaabaababbaaaabababaabbbaaaababaaababbbbbbabbbbbbaabbabbaaa...
output:
41479
result:
wrong answer 1st lines differ - expected: '43524', found: '41479'
Subtask #5:
score: 0
Skipped
Dependency #1:
0%
Subtask #6:
score: 0
Skipped
Dependency #2:
0%