QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#410942#6224. 节日庆典Max_s_xaM100 ✓322ms31988kbC++173.4kb2024-05-14 18:06:152024-05-14 18:06:15

Judging History

你现在查看的是最新测评结果

  • [2024-05-14 18:06:15]
  • 评测
  • 测评结果:100
  • 用时:322ms
  • 内存:31988kb
  • [2024-05-14 18:06:15]
  • 提交

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 (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) && (!npos.size() || Check(npos.back(), 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: 3604kb

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: 3560kb

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: 3668kb

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: 8ms
memory: 5496kb

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: 4064kb

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: 87ms
memory: 14680kb

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: 87ms
memory: 15540kb

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: 322ms
memory: 31988kb

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: 10
Accepted
time: 293ms
memory: 31404kb

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:

ok 3000000 numbers

Test #10:

score: 10
Accepted
time: 253ms
memory: 30976kb

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

Extra Test:

score: 0
Extra Test Passed