QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#589068#6528. Sequenceisirazeev0 602ms93556kbC++203.4kb2024-09-25 16:01:312024-09-25 16:01:31

Judging History

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

  • [2024-09-25 16:01:31]
  • 评测
  • 测评结果:0
  • 用时:602ms
  • 内存:93556kb
  • [2024-09-25 16:01:31]
  • 提交

answer

#include "sequence.h"

#include <vector>
#include <algorithm>
#include <set>

using namespace std;

const int INF = (int) 1e9;
const int maxN = (int) 1e5 * 5 + 10;

struct SegTree {
    int mn[4 * maxN], mx[4 * maxN], add[4 * maxN];

    void push(int v, int l, int r) {
        if (add[v] == 0) return;
        mn[v] += add[v], mx[v] += add[v];
        if (l != r)
            add[v * 2] += add[v], add[v * 2 + 1] += add[v];
        add[v] = 0;
    }

    void update(int v, int l, int r, int tl, int tr, int val) {
        push(v, l, r);
        if (l > tr || r < tl)
            return;
        if (l >= tl && r <= tr) {
            add[v] += val;
            push(v, l, r);
            return;
        }
        int mid = (l + r) / 2;
        update(v * 2, l, mid, tl, tr, val);
        update(v * 2 + 1, mid + 1, r, tl, tr, val);
        mn[v] = min(mn[v * 2], mn[v * 2 + 1]);
        mx[v] = max(mx[v * 2], mx[v * 2 + 1]);
    }

    int get_max(int v, int l, int r, int tl, int tr) {
        if(tl > tr) return 0;
        push(v, l, r);
        if (l > tr || r < tl)
            return -INF;
        if (l >= tl && r <= tr)
            return mx[v];
        int mid = (l + r) / 2;
        return max(get_max(v * 2, l, mid, tl, tr), get_max(v * 2 + 1, mid + 1, r, tl, tr));
    }

    int get_min(int v, int l, int r, int tl, int tr) {
        if(tl > tr) return 0;
        push(v, l, r);
        if (l > tr || r < tl)
            return INF;
        if (l >= tl && r <= tr)
            return mn[v];
        int mid = (l + r) / 2;
        return min(get_min(v * 2, l, mid, tl, tr), get_min(v * 2 + 1, mid + 1, r, tl, tr));
    }

    void clear(int v, int l, int r) {
        mn[v] = 0, mx[v] = 0, add[v] = 0;
        if (l == r) return;
        clear(v * 2, l, (l + r) / 2), clear(v * 2 + 1, (l + r) / 2 + 1, r);
    }
};

SegTree T1, T2;

int sequence(int N, std::vector<int> A) {
    set<int> all_x;
    for (int i = 0; i < N; i++) all_x.insert(A[i]);
    vector<int> pos[N + 1];
    int mx = 0;
    for (int i = 0; i < N; i++) pos[A[i]].emplace_back(i);
    for (int i = 0; i < N; i++) mx = max(mx, (int) pos[A[i]].size());
    // int l = 0, r = mx + 1;
    // while (r - l > 1) {
        int mid = 2;
        T1.clear(1, 0, N - 1), T2.clear(1, 0, N - 1);
        for (int i = 0; i < N; i++){
            T1.update(1, 0, N - 1, i, N - 1, 1);
            // T2.update(1, 0, N - 1, i, N - 1, 1);
        }
        bool F = false;
        for (int x: all_x) {
            // for (int i: pos[x])
            //     T2.update(1, 0, N - 1, i, N - 1, -2);
            for (int i: pos[x])
                T1.update(1, 0, N - 1, i, N - 1, -1);
            for (int i = 0; i + mid <= (int) pos[x].size(); i++) {
                int L = pos[x][i], R = pos[x][i + mid - 1];
                int maxSum = T1.get_max(1, 0, N - 1, R, N - 1) - T1.get_min(1, 0, N - 1, 0, L - 1),
                  minSum = T1.get_min(1, 0, N - 1, R, N - 1) - T1.get_max(1, 0, N - 1, 0, L - 1);
                if ((minSum <= -2 && maxSum >= -2 || (minSum <= 2 && maxSum >= 2))) {
                    F = true;
                    break;
                }
            }
            if (F) break;
            for (int i: pos[x])
                T1.update(1, 0, N - 1, i, N - 1, -1);
        }
        // if (F) l = mid;
        // else r = mid;
    // }
    if(F) return 2;
    return 1;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

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

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
2

result:

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

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Wrong Answer

Test #20:

score: 0
Wrong Answer
time: 185ms
memory: 78820kb

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
2

result:

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

Subtask #4:

score: 0
Wrong Answer

Test #28:

score: 0
Wrong Answer
time: 144ms
memory: 56392kb

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
2

result:

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

Subtask #5:

score: 0
Wrong Answer

Test #33:

score: 13
Accepted
time: 580ms
memory: 93388kb

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
1

result:

ok 

Test #34:

score: 13
Accepted
time: 602ms
memory: 93556kb

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
1

result:

ok 

Test #35:

score: 13
Accepted
time: 315ms
memory: 91460kb

input:

8wq90di9812978rqwiok0k0o21klklm21oiwi121
499999
8693 471440 17469 369862 13045 479599 4760 476071 471988 5407 824 758 15609 6920 13914 12760 404798 12294 1063 481107 447196 477441 418064 14409 448927 1833 418585 7688 443224 1042 6425 467944 11721 472016 475543 442250 17475 477814 477933 468083 40726...

output:

nfp39szm23aa01pcmyosi03slwpeksnfjri3opqp
OK
2

result:

ok 

Test #36:

score: 13
Accepted
time: 326ms
memory: 92716kb

input:

8wq90di9812978rqwiok0k0o21klklm21oiwi121
499999
8693 471440 17469 369862 13045 479599 4760 476071 471988 5407 824 758 15609 6920 13914 12760 404798 12294 1063 481107 447196 477441 418064 14409 448927 1833 418585 7688 443224 1042 6425 467944 11721 472016 475543 442250 17475 477814 477933 468083 40726...

output:

nfp39szm23aa01pcmyosi03slwpeksnfjri3opqp
OK
2

result:

ok 

Test #37:

score: 0
Wrong Answer
time: 528ms
memory: 84136kb

input:

8wq90di9812978rqwiok0k0o21klklm21oiwi121
500000
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 ...

output:

nfp39szm23aa01pcmyosi03slwpeksnfjri3opqp
OK
1

result:

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

Subtask #6:

score: 0
Skipped

Dependency #2:

0%

Subtask #7:

score: 0
Skipped

Dependency #1:

0%