QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#673636#6528. Sequencemakrav0 408ms69600kbC++204.6kb2024-10-25 03:20:432024-10-25 03:20:43

Judging History

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

  • [2024-10-25 03:20:43]
  • 评测
  • 测评结果:0
  • 用时:408ms
  • 内存:69600kb
  • [2024-10-25 03:20:43]
  • 提交

answer

#include "sequence.h"
#include <bits/stdc++.h>

using namespace std;

bool is_inter(pair<int, int> sg1, pair<int, int> sg2) {
    if (sg1.second < sg2.first || sg2.second < sg1.first) return false;
    return true;
}

struct node {
    int sm, minbal, maxbal;
};

node operator+(node a, node b) {
    int nsm = a.sm + b.sm, nminbal = min(a.minbal, a.sm + b.minbal), nmaxbal = max(a.maxbal, a.sm + b.maxbal);
    return {nsm, nminbal, nmaxbal};
}

struct segtree {
    int n;
    vector<int> a;
    vector<node> t;
    segtree() = default;
    segtree(int n_) {
        n = n_;
        a.assign(n, -1);
        t.resize(4 * n);
        build(1, 0, n);
    }

    void build(int v, int tl, int tr) {
        if (tl + 1 == tr) {
            t[v] = {a[tl], min(a[tl], 0), max(a[tl], 0)};
            return;
        }
        int tm = (tl + tr) / 2;
        build(v * 2, tl, tm); build(v * 2 + 1, tm, tr);
        t[v] = t[v * 2] + t[v * 2 + 1];
    }

    void upd(int v, int tl, int tr, int p, int vl) {
        if (tl + 1 == tr) {
            t[v] = {vl, min(0, vl), max(0, vl)};
            return;
        }
        int tm = (tl + tr) / 2;
        if (p < tm) upd(v * 2, tl, tm, p, vl);
        else upd(v * 2 + 1, tm, tr, p, vl);
        t[v] = t[v * 2] + t[v * 2 + 1];
    }

    node get(int v, int tl, int tr, int l, int r) {
        if (tl >= r || tr <= l) return {0, 1000000000, -1000000000};
        if (l <= tl && tr <= r) return t[v];
        int tm = (tl + tr) / 2;
        return get(v * 2, tl, tm, l, r) + get(v * 2 + 1, tm, tr, l, r);
    }
};

struct fenwick {
    int n;
    vector<int> t;
    fenwick() = default;
    fenwick(int n_) {
        n = n_;
        t.assign(n + 1, 0);
    }
 
    void upd(int p, int vl) {
        for (; p <= n; p = (p | (p + 1))) t[p] += vl;
    }
 
    int get(int p) {
        int sm = 0;
        for (; p > 0; p = (p & (p + 1)) - 1) sm += t[p];
        return sm;
    }
};

struct segtree2 {
    int n; 
    vector<int> t;
    segtree2() = default;
    segtree2(int n_) {
        n = n_;
        t.assign(4 * n, -1e9);
    }

    void upd(int v, int tl, int tr, int p, int vl) {
        if (tl + 1 == tr) {
            t[v] = vl;
            return;
        }
        int tm = (tl + tr) / 2;
        if (p < tm) upd(v * 2, tl, tm, p, vl);
        else upd(v * 2 + 1, tm, tr, p, vl);
        t[v] = max(t[v * 2], t[v * 2 + 1]);
    }

    int spusk(int v, int tl, int tr, int l, int r, int val) {
        if (tr <= l || tl >= r) return -1;
        if (l <= tl && tr <= r) {
            if (t[v] < val) return -1;
            if (tl + 1 == tr) return tl;
        }
        int tm = (tl + tr) / 2;
        int rsl = spusk(v * 2, tl, tm, l, r, val);
        if (rsl != -1) return rsl;
        return spusk(v * 2 + 1, tm, tr, l, r, val);
    }
};

int sequence(int N, vector<int> A) {
    vector<vector<int>> pos(N + 1);
    for (int i = 0; i < N; i++) pos[A[i]].push_back(i);
    segtree sg(N);
    fenwick fw(N + 3);
    vector<pair<int, int>> left(N), right(N);
    int tot = -N;
    for (int i = 1; i <= N; i++) fw.upd(i, -1);
    for (int val = 1; val <= N; val++) {
        for (int p : pos[val]) {
            sg.upd(1, 0, N, p, 1);
            fw.upd(p + 1, 2);
        }
        tot += 2 * pos[val].size();
        for (int p : pos[val]) {
            if (p == 0) {
                left[p] = {0, 0};
            } else {
                node rs = sg.get(1, 0, N, 0, p);
                left[p] = {rs.minbal, rs.maxbal};
            }

            if (p == N - 1) {
                right[p] = {tot, tot};
            } else {
                int ls = fw.get(p + 1);
                node rs = sg.get(1, 0, N, p + 1, N);
                right[p] = {ls + rs.minbal, ls + rs.maxbal};
            }
        }
    }
    
    int ans = 1;
    for (int val = 1; val <= N; val++) {
        if (pos[val].empty()) continue;
        segtree2 sg2(pos[val].size());
        for (int i = 0; i < pos[val].size(); i++) sg2.upd(1, 0, pos[val].size(), i, left[pos[val][i]].second - 2 * i + 2);
        for (int i = 1; i < pos[val].size(); i++) {
            int L = -1, R = i;
            while (R - L > 1) {
                int M = (L + R) / 2;
                if (right[i].second - left[pos[val][M]].first < 0) L = M;
                else R = M;
            }
            if (R < i) {
                int result = sg2.spusk(1, 0, pos[val].size(), R, i, right[i].first - 2 * i);
                ans = max(ans, i - result + 1);
            }
            
        }
    }
    return ans;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3824kb

input:

8wq90di9812978rqwiok0k0o21klklm21oiwi121
98
92 89 9 86 80 6 42 20 84 82 46 56 52 30 44 39 35 82 57 33 18 38 32 63 27 55 33 44 41 39 62 26 46 59 21 85 36 60 7 36 50 22 87 83 71 27 4 3 87 47 17 62 70 24 9 20 81 21 57 50 13 32 68 70 11 95 5 56 64 90 47 42 44 72 71 46 84 72 56 63 37 35 80 78 4 54 74 79 ...

output:

nfp39szm23aa01pcmyosi03slwpeksnfjri3opqp
OK
4

result:

wrong answer 1st lines differ - on the 1st token, expected: '3', found: '4'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Wrong Answer

Test #20:

score: 7
Accepted
time: 245ms
memory: 63756kb

input:

8wq90di9812978rqwiok0k0o21klklm21oiwi121
499996
53 78 81 111 119 124 126 130 164 175 219 227 233 249 282 298 332 341 348 436 437 448 452 455 462 465 495 535 557 558 576 600 620 627 632 642 643 659 695 696 713 730 743 805 816 865 869 872 875 882 883 902 924 937 990 998 1025 1092 1137 1145 1166 1176 1...

output:

nfp39szm23aa01pcmyosi03slwpeksnfjri3opqp
OK
8

result:

ok 

Test #21:

score: 7
Accepted
time: 242ms
memory: 64120kb

input:

8wq90di9812978rqwiok0k0o21klklm21oiwi121
499996
5 7 11 19 19 19 19 23 23 27 29 31 32 33 34 37 37 40 45 49 53 57 67 69 70 76 79 80 82 82 84 89 91 96 105 109 109 109 110 111 112 113 116 119 120 121 122 129 133 135 136 142 145 147 148 151 155 160 161 162 162 171 174 177 178 179 180 181 185 189 191 192 ...

output:

nfp39szm23aa01pcmyosi03slwpeksnfjri3opqp
OK
9

result:

ok 

Test #22:

score: 7
Accepted
time: 281ms
memory: 57600kb

input:

8wq90di9812978rqwiok0k0o21klklm21oiwi121
500000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

output:

nfp39szm23aa01pcmyosi03slwpeksnfjri3opqp
OK
100281

result:

ok 

Test #23:

score: 0
Wrong Answer
time: 233ms
memory: 63196kb

input:

8wq90di9812978rqwiok0k0o21klklm21oiwi121
500000
1 7 8 11 15 17 18 19 19 20 22 24 29 33 33 35 37 39 46 47 48 49 49 49 52 54 57 60 60 62 62 63 68 70 71 72 72 78 79 79 85 86 86 92 94 94 97 99 100 100 106 108 110 114 116 118 119 122 125 127 128 133 133 134 136 137 144 144 145 148 152 153 153 153 160 161...

output:

nfp39szm23aa01pcmyosi03slwpeksnfjri3opqp
OK
10

result:

wrong answer 1st lines differ - on the 1st token, expected: '9', found: '10'

Subtask #4:

score: 0
Wrong Answer

Test #28:

score: 12
Accepted
time: 313ms
memory: 60512kb

input:

8wq90di9812978rqwiok0k0o21klklm21oiwi121
499999
2 1 2 2 2 1 2 3 1 3 1 2 2 1 2 1 1 2 1 1 2 1 1 2 1 2 1 1 1 1 1 2 2 1 1 2 1 1 1 2 1 2 1 1 1 2 3 3 3 3 1 3 1 2 2 1 1 1 3 1 3 1 1 2 1 2 2 2 1 3 2 1 1 1 2 2 1 2 2 3 1 2 2 1 2 2 1 1 2 1 1 2 2 1 2 2 1 1 1 1 2 2 1 1 1 1 1 2 1 1 2 1 1 3 2 1 1 1 3 1 1 2 1 3 1 1 ...

output:

nfp39szm23aa01pcmyosi03slwpeksnfjri3opqp
OK
277713

result:

ok 

Test #29:

score: 0
Wrong Answer
time: 316ms
memory: 58616kb

input:

8wq90di9812978rqwiok0k0o21klklm21oiwi121
499999
2 3 1 3 3 3 1 2 3 3 3 2 2 1 1 3 1 2 1 3 3 3 2 2 2 2 3 3 2 2 2 1 1 2 3 3 1 3 1 1 2 3 3 1 1 1 2 1 1 1 2 3 2 2 1 2 1 1 3 1 1 1 3 1 1 2 1 3 2 3 1 3 1 3 3 2 1 3 1 2 1 3 2 1 1 2 3 1 2 1 3 3 1 2 1 3 3 3 2 3 2 1 1 2 1 2 3 1 1 2 2 1 3 2 3 2 3 2 2 1 3 2 3 1 3 3 ...

output:

nfp39szm23aa01pcmyosi03slwpeksnfjri3opqp
OK
167379

result:

wrong answer 1st lines differ - on the 1st token, expected: '166105', found: '167379'

Subtask #5:

score: 0
Wrong Answer

Test #33:

score: 0
Wrong Answer
time: 408ms
memory: 69600kb

input:

8wq90di9812978rqwiok0k0o21klklm21oiwi121
499999
490225 471440 499001 369862 494577 479599 486292 476071 471988 486939 482356 482290 497141 488452 495446 494292 404798 493826 482595 481107 447196 477441 418064 495941 448927 483365 418585 489220 443224 482574 487957 467944 493253 472016 475543 442250 ...

output:

nfp39szm23aa01pcmyosi03slwpeksnfjri3opqp
OK
2

result:

wrong answer 1st lines differ - on the 1st token, expected: '1', found: '2'

Subtask #6:

score: 0
Skipped

Dependency #2:

0%

Subtask #7:

score: 0
Skipped

Dependency #1:

0%