QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#410932 | #6224. 节日庆典 | Max_s_xaM | 90 | 209ms | 31036kb | C++17 | 3.4kb | 2024-05-14 17:40:21 | 2024-05-14 17:40:23 |
Judging History
answer
#include <iostream>
#include <vector>
#include <cstring>
typedef long long ll;
typedef double lf;
// #define DEBUG 1
struct IO
{
#define MAXSIZE (1 << 20)
#define isdigit(x) (x >= '0' && x <= '9')
char buf[MAXSIZE], *p1, *p2;
char pbuf[MAXSIZE], *pp;
#if DEBUG
#else
IO() : p1(buf), p2(buf), pp(pbuf) {}
~IO() {fwrite(pbuf, 1, pp - pbuf, stdout);}
#endif
#define gc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, MAXSIZE, stdin), p1 == p2) ? ' ' : *p1++)
#define blank(x) (x == ' ' || x == '\n' || x == '\r' || x == '\t')
template <typename T>
void Read(T &x)
{
#if DEBUG
std::cin >> x;
#else
bool sign = 0; char ch = gc(); x = 0;
for (; !isdigit(ch); ch = gc())
if (ch == '-') sign = 1;
for (; isdigit(ch); ch = gc()) x = x * 10 + (ch ^ 48);
if (sign) x = -x;
#endif
}
void Read(char *s)
{
#if DEBUG
std::cin >> s;
#else
char ch = gc();
for (; blank(ch); ch = gc());
for (; !blank(ch); ch = gc()) *s++ = ch;
*s = 0;
#endif
}
void Read(char &c) {for (c = gc(); blank(c); c = gc());}
void Push(const char &c)
{
#if DEBUG
putchar(c);
#else
if (pp - pbuf == MAXSIZE) fwrite(pbuf, 1, MAXSIZE, stdout), pp = pbuf;
*pp++ = c;
#endif
}
template <typename T>
void Write(T x)
{
if (x < 0) x = -x, Push('-');
static T sta[35];
int top = 0;
do sta[top++] = x % 10, x /= 10; while (x);
while (top) Push(sta[--top] ^ 48);
}
template <typename T>
void Write(T x, char lst) {Write(x), Push(lst);}
} IO;
#define Read(x) IO.Read(x)
#define Write(x, y) IO.Write(x, y)
#define Put(x) IO.Push(x)
using namespace std;
const int MAXN = 3e6 + 10;
int n, ans[MAXN];
char s[MAXN];
int z[MAXN];
vector <int> pos, npos;
inline bool cmp(int x, int y, int t)
{
if (s[x + t - y] != s[t]) return s[x + t - y] < s[t];
if (x + t - y + 1 + z[x + t - y + 1] <= t) return s[x + t - y + 1 + z[x + t - y + 1]] < s[z[x + t - y + 1] + 1];
if (y - x + 1 + z[y - x + 1] < y) return s[z[y - x + 1] + 1] < s[y - x + 1 + z[y - x + 1]];
return 1;
}
inline bool Check(int x, int y, int t)
{
if (x > y) x ^= y, y ^= x, x ^= y;
return s[x + t - y] == s[t];
}
int main()
{
#if DEBUG
#else
ios::sync_with_stdio(0), cin.tie(0);
#endif
Read(s + 1), n = strlen(s + 1);
for (int i = 2, l = 0, r = 0; i <= n; i++)
{
z[i] = (r < i ? 0 : min(r - i + 1, z[i - l + 1]));
while (i + z[i] <= n && s[i + z[i]] == s[1 + z[i]]) z[i]++;
if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1;
}
ans[1] = 1, pos.push_back(1);
for (int i = 2; i <= n; i++)
{
int res = i;
for (auto x : pos)
if (!res || cmp(x, res, i)) res = x;
ans[i] = res;
npos.clear();
if (Check(res, i, i)) npos.push_back(i);
for (auto x : pos)
if (Check(res, x, i))
{
if (npos.size() && (i - npos.back() + 1) * 2 > i - x + 1) npos.pop_back();
npos.push_back(x);
}
pos = npos;
}
for (int i = 1; i <= n; i++) cout << ans[i] << ' ';
return 0;
}
詳細信息
Test #1:
score: 10
Accepted
time: 1ms
memory: 3592kb
input:
cabacabacaccabbbaa
output:
1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 17
result:
ok 18 numbers
Test #2:
score: 10
Accepted
time: 1ms
memory: 3612kb
input:
cabacabacbaaabbccccaabbabbccabbbbbbbcaccbcbcccbbbccbccbbcccabacbacccbbcacbcabcbcbabbacbccbacbbbbbbaacbbbcccbbcccbbaacaccababaacacccbbbabbbcaaaabcabaacabcacaabbacabcbaccbbbbbcaacccabcacbbbabbaccabaccbbaacccababbacbaacaaabbbbabbbbbbbbcacbabaabababbbacabcbabacbccaaacbabcaaccbbcbacaaccbacbabaccaccbcbcbb...
output:
1 2 2 2 2 2 2 2 2 2 2 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11...
result:
ok 1000 numbers
Test #3:
score: 10
Accepted
time: 1ms
memory: 3608kb
input:
cabacabacbbaaaacbbabcbaaacbabcaaaacccaabaacbcccabbabcabbabcaacbccbbbcbbaabbabaabcbbaaacababccbbbbaacccbabbbcbbababcbbbaaabbbbcbcbbcbbacaaccbbaacbbcbccacaaabaccbccbaacbaaccaccacacbbcaacaacccbbabbbabbaaaacabcbaaacccbcacbabbaaccaccbbcbcbbccabbcbbababaaccabccbabaacacabcaacccbaccccacccbcbccccbabcbaccbcbc...
output:
1 2 2 2 2 2 2 2 2 2 2 2 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 31 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 ...
result:
ok 1000 numbers
Test #4:
score: 10
Accepted
time: 12ms
memory: 5544kb
input:
cabacabaacbbbcbaaacbbacbcccbccaacbcaaaacabcbcbbcabaabcbccbabcabcbacbaccaaccaccbccacbcaacaaaaabbaabcabacacbcbaccacabcbcccabcbbcccbbcccbaccccbcbabcccbcabacabcbaccacababbcabcaccaaabcbacccaabaaabcacacacbaacbccacccccaacaaabbbcabaabbbabbcccbccbccaabccaacabcacbbcabaccaacaacbacbcabcaccbababbaaababaaaabcaaba...
output:
1 2 2 2 2 2 2 2 8 8 8 8 8 8 8 8 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 89 89 89 89 89 89 89 89 89 89 89 89 89 89 8...
result:
ok 200000 numbers
Test #5:
score: 10
Accepted
time: 4ms
memory: 4136kb
input:
yzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxz...
output:
1 1 3 1 5 1 7 1 9 1 11 1 13 1 15 1 17 1 19 1 21 1 23 1 25 1 27 1 29 1 31 1 33 1 35 1 37 1 39 1 41 1 43 1 45 1 47 1 49 1 51 1 53 1 55 1 57 1 59 1 61 1 63 1 65 1 67 1 69 1 71 1 73 1 75 1 77 1 79 1 81 1 83 1 85 1 87 1 89 1 91 1 93 1 95 1 97 1 99 1 101 1 103 1 105 1 107 1 109 1 111 1 113 1 115 1 117 1 1...
result:
ok 49400 numbers
Test #6:
score: 10
Accepted
time: 64ms
memory: 13256kb
input:
tutvtutwtutvtutxtutvtutwtutvtutytutvtutwtutvtutxtutvtutwtutvtuttutvtutwtutvtutxtutvtutwtutvtutytutvtutwtutvtutxtutvtutwtutvtuttutvtutwtutvtutxtutvtutwtutvtutytutvtutwtutvtutxtutvtutwtutvtuttutvtutwtutvtutxtutvtutwtutvtutytutvtutwtutvtutxtutvtutwtutvtuttutvtutwtutvtutxtutvtutwtutvtutytutvtutwtutvtutx...
output:
1 1 3 1 5 5 7 1 9 9 11 9 13 13 15 1 17 17 19 17 21 21 23 17 25 25 27 25 29 29 31 1 33 33 35 33 37 37 39 33 41 41 43 41 45 45 47 33 49 49 51 49 53 53 55 49 57 57 59 57 61 61 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 6...
result:
ok 1000000 numbers
Test #7:
score: 10
Accepted
time: 61ms
memory: 13368kb
input:
stsustsvstsustswstsustsvstsustsxstsustsvstsustswstsustsvstsustsystsustsvstsustswstsustsvstsustsxstsustsvstsustswstsustsvstsustsstsustsvstsustswstsustsvstsustsxstsustsvstsustswstsustsvstsustsystsustsvstsustswstsustsvstsustsxstsustsvstsustswstsustsvstsustsstsustsvstsustswstsustsvstsustsxstsustsvstsust...
output:
1 1 3 1 5 5 7 1 9 9 11 9 13 13 15 1 17 17 19 17 21 21 23 17 25 25 27 25 29 29 31 1 33 33 35 33 37 37 39 33 41 41 43 41 45 45 47 33 49 49 51 49 53 53 55 49 57 57 59 57 61 61 63 1 65 65 67 65 69 69 71 65 73 73 75 73 77 77 79 65 81 81 83 81 85 85 87 81 89 89 91 89 93 93 95 65 97 97 99 97 101 101 103 97...
result:
ok 1000000 numbers
Test #8:
score: 10
Accepted
time: 209ms
memory: 31032kb
input:
stsustsvstsustswstsustsvstsustsxstsustsvstsustswstsustsvstsustsystsustsvstsustswstsustsvstsustsxstsustsvstsustswstsustsvstsustsstsustsvstsustswstsustsvstsustsxstsustsvstsustswstsustsvstsustsystsustsvstsustswstsustsvstsustsxstsustsvstsustswstsustsvstsustsstsustsvstsustswstsustsvstsustsxstsustsvstsust...
output:
1 1 3 1 5 5 7 1 9 9 11 9 13 13 15 1 17 17 19 17 21 21 23 17 25 25 27 25 29 29 31 1 33 33 35 33 37 37 39 33 41 41 43 41 45 45 47 33 49 49 51 49 53 53 55 49 57 57 59 57 61 61 63 1 65 65 67 65 69 69 71 65 73 73 75 73 77 77 79 65 81 81 83 81 85 85 87 81 89 89 91 89 93 93 95 65 97 97 99 97 101 101 103 97...
result:
ok 3000000 numbers
Test #9:
score: 0
Wrong Answer
time: 198ms
memory: 31036kb
input:
abacabadabacabaeabacabadabacabafabacabadabacabaeabacabadabacabagabacabadabacabaeabacabadabacabafabacabadabacabaeabacabadabacabahabacabadabacabaeabacabadabacabafabacabadabacabaeabacabadabacabagabacabadabacabaeabacabadabacabafabacabadabacabaeabacabadabacabaiabacabadabacabaeabacabadabacabafabacabadabac...
output:
1 1 3 1 5 5 7 1 9 9 11 9 13 13 15 1 17 17 19 17 21 21 23 17 25 25 27 25 29 29 31 1 33 33 35 33 37 37 39 33 41 41 43 41 45 45 47 33 49 49 51 49 53 53 55 49 57 57 59 57 61 61 63 1 65 65 67 65 69 69 71 65 73 73 75 73 77 77 79 65 81 81 83 81 85 85 87 81 89 89 91 89 93 93 95 65 97 97 99 97 101 101 103 97...
result:
wrong answer 2988569th numbers differ - expected: '2988560', found: '2988464'
Test #10:
score: 10
Accepted
time: 189ms
memory: 30956kb
input:
stsustsvstsustswstsustsvstsustsxstsustsvstsustswstsustsvstsustsystsustsvstsustswstsustsvstsustsxstsustsvstsustswstsustsvstsustsstsustsvstsustswstsustsvstsustsxstsustsvstsustswstsustsvstsustsystsustsvstsustswstsustsvstsustsxstsustsvstsustswstsustsvstsustsstsustsvstsustswstsustsvstsustsxstsustsvstsust...
output:
1 1 3 1 5 5 7 1 9 9 11 9 13 13 15 1 17 17 19 17 21 21 23 17 25 25 27 25 29 29 31 1 33 33 35 33 37 37 39 33 41 41 43 41 45 45 47 33 49 49 51 49 53 53 55 49 57 57 59 57 61 61 63 1 65 65 67 65 69 69 71 65 73 73 75 73 77 77 79 65 81 81 83 81 85 85 87 81 89 89 91 89 93 93 95 65 97 97 99 97 101 101 103 97...
result:
ok 3000000 numbers