QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#741505#3549. 262144 Revisited_8_8_21.73913 66ms91968kbC++232.0kb2024-11-13 14:30:482024-11-13 14:30:50

Judging History

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

  • [2024-11-13 14:30:50]
  • 评测
  • 测评结果:21.73913
  • 用时:66ms
  • 内存:91968kb
  • [2024-11-13 14:30:48]
  • 提交

answer


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = (int)3e5 + 12;

int n, a[N], r[N];
ll d[N];
int dp[3001][3001], opt[3001][3001];
void solve() {
    for(int i = 1; i <= n; i++) {
        dp[i][i] = a[i];
        opt[i][i] = i;
        opt[n + 1][i] = i;
    }
    for(int i = n; i >= 1; i--) {
        for(int j = i + 1; j <= n; j++) {
            dp[i][j] = (int)1e9;
            for(int k = opt[i][j - 1]; k < min(j, opt[i + 1][j] + 1); k++) {
                int v = max(dp[i][k], dp[k + 1][j]) + 1;
                if(v < dp[i][j]) {
                    dp[i][j] = v;
                    opt[i][j] = k;
                }
            }
        }
    }
    ll res = 0;
    for(int i = 1; i <= n; i++) {
        for(int j = i; j <= n; j++) {
            res += dp[i][j];
        }
    }
    cout << res << '\n';

}
set<int> l[N];
void test() {
    cin >> n;
    for(int i = 1; i <= n; i++) {
        cin >> a[i], r[i] = i;
    }
    if(n <= 3000) {
        solve();
        return;
    }
    r[n + 1] = n + 1;
    for(int i = 1; i <= n + 1; i++) {
        l[i].insert(i);
    }
    ll res = 0;
    set<int> u;
    for(int v = 1; v <= 60; v++) {
        set<int> u1;
        for(int i:u) {
            if(r[i] != r[r[i]]) {
                u1.insert(i);
            }
            l[r[i]].erase(i);
            r[i] = r[r[i]];
            l[r[i]].insert(i);
        }
        for(int i = 1; i <= n; i++) {
            if(a[i] == v) {
                r[i] = i + 1;
                for(int j:l[i]) {
                    u1.insert(j);
                }
                l[i].clear();
            }
        }
        u1.swap(u);
        for(int i = 1; i <= n; i++) {
            d[v] += r[i] - i;
        }
        res += (d[v] - d[v - 1]) * 1ll * v;
    }
    cout << res << '\n';
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int t = 1;
    // cin >> t;

    while(t--) 
        test();
}

Details

Tip: Click on the bar to expand more detailed information

Pretests


Final Tests

Test #1:

score: 4.34783
Accepted
time: 0ms
memory: 23492kb

input:

6
1 3 1 2 1 10

output:

115

result:

ok single line: '115'

Test #2:

score: 0
Wrong Answer
time: 37ms
memory: 33124kb

input:

262144
1 1 2 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 6 6 6 6 6 8 8 8 8 8 8 8 8 8 11 11 11 11 11 11 11 11 12 12 12 12 12 12 12 12 14 14 14 14 14 14 14 14 14 14 14 14 14 15 16 16 16 16 17 17 17 17 17 17 17 18 18 18 18 18 18 18 18 18 18 18 18 18 18 19 19 20 20 20 20 20 20 ...

output:

4328338

result:

wrong answer 1st lines differ - expected: '666881324292484', found: '4328338'

Test #3:

score: 0
Wrong Answer
time: 32ms
memory: 33124kb

input:

262144
1 9 9 9 9 11 12 13 15 21 21 22 23 23 33 34 34 39 39 42 43 46 46 46 46 46 50 50 51 51 52 55 55 56 56 59 64 66 70 70 77 79 83 88 92 97 97 98 102 108 108 112 113 114 121 121 124 126 129 131 132 138 141 141 147 147 148 152 154 155 161 162 163 165 166 166 168 169 169 169 170 175 176 177 178 183 18...

output:

30146

result:

wrong answer 1st lines differ - expected: '14050699806935958', found: '30146'

Test #4:

score: 0
Wrong Answer
time: 35ms
memory: 35236kb

input:

262144
99996 99995 99993 99993 99990 99990 99991 99990 99988 99989 99990 99989 99988 99988 99987 99989 99988 99982 99983 99983 99984 99984 99983 99981 99981 99981 99978 99978 99977 99976 99976 99977 99971 99968 99968 99968 99967 99965 99965 99965 99964 99967 99966 99965 99963 99961 99960 99960 99964...

output:

0

result:

wrong answer 1st lines differ - expected: '2433548647154743', found: '0'

Test #5:

score: 0
Wrong Answer
time: 41ms
memory: 35020kb

input:

262144
199998 199997 199998 199997 199996 199997 199996 199996 199992 199992 199988 199988 199988 199990 199986 199986 199988 199988 199984 199984 199984 199985 199986 199987 199984 199984 199984 199979 199980 199980 199982 199977 199977 199976 199975 199976 199975 199976 199977 199972 199973 199973...

output:

0

result:

wrong answer 1st lines differ - expected: '5874338879559722', found: '0'

Test #6:

score: 0
Wrong Answer
time: 33ms
memory: 35052kb

input:

262144
499992 499989 499989 499988 499988 499988 499988 499989 499989 499990 499985 499985 499986 499986 499985 499984 499984 499985 499985 499985 499985 499986 499986 499985 499985 499984 499984 499984 499984 499985 499985 499986 499986 499986 499986 499985 499985 499988 499988 499989 499986 499986...

output:

0

result:

wrong answer 1st lines differ - expected: '24026306153639201', found: '0'

Test #7:

score: 0
Wrong Answer
time: 33ms
memory: 35200kb

input:

262144
999991 999991 999990 999990 999991 999993 999991 999991 999991 999990 999990 999989 999989 999989 999989 999988 999988 999989 999987 999987 999987 999985 999984 999984 999986 999987 999987 999988 999988 999988 999989 999989 999989 999990 999988 999988 999989 999991 999989 999988 999985 999984...

output:

0

result:

wrong answer 1st lines differ - expected: '34359949390393101', found: '0'

Test #8:

score: 0
Wrong Answer
time: 31ms
memory: 35192kb

input:

262144
1000000 999996 999991 999987 999988 999987 999988 999988 999986 999985 999986 999986 999984 999982 999983 999985 999984 999982 999981 999981 999979 999978 999977 999975 999974 999975 999974 999973 999974 999971 999972 999972 999972 999973 999971 999970 999970 999965 999964 999956 999957 99995...

output:

0

result:

wrong answer 1st lines differ - expected: '33356297291315697', found: '0'

Test #9:

score: 0
Wrong Answer
time: 32ms
memory: 33332kb

input:

262144
999997 999998 999996 999992 999992 999994 999989 999986 999985 999985 999985 999987 999984 999982 999982 999982 999984 999984 999981 999979 999980 999976 999976 999976 999976 999974 999974 999975 999974 999973 999974 999968 999968 999965 999965 999967 999965 999965 999960 999960 999959 999959...

output:

0

result:

wrong answer 1st lines differ - expected: '33358042175183584', found: '0'

Test #10:

score: 0
Wrong Answer
time: 66ms
memory: 41408kb

input:

262144
1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1...

output:

131072

result:

wrong answer 1st lines differ - expected: '34360299579681451', found: '131072'

Test #11:

score: 0
Wrong Answer
time: 36ms
memory: 35300kb

input:

262144
518701 585574 345076 642315 75617 893688 485383 696337 31086 682159 969846 943380 254864 406197 509965 126319 135623 147440 7593 120839 163643 128819 324108 935846 334903 804212 668986 900274 503397 603547 238961 51946 697501 412370 426586 80682 390652 730017 13011 254438 357154 142380 587176...

output:

628

result:

wrong answer 1st lines differ - expected: '34357316353722230', found: '628'

Test #12:

score: 4.34783
Accepted
time: 0ms
memory: 28008kb

input:

300
216080 283804 812393 874518 459351 285947 246394 558391 105329 831354 487737 667446 725110 860965 686619 499108 856557 662571 474888 145951 754627 969797 89658 936887 391068 461211 376147 310350 185753 576410 821006 745593 39979 592437 80465 176087 47907 190517 291417 351610 276193 277438 392732...

output:

43964210127

result:

ok single line: '43964210127'

Test #13:

score: 0
Wrong Answer
time: 40ms
memory: 33128kb

input:

262144
1000000 999999 999998 999997 999996 999995 999994 999993 999992 999991 999990 999989 999988 999987 999986 999985 999984 999983 999982 999981 999980 999979 999978 999977 999976 999975 999974 999973 999972 999971 999970 999969 999968 999967 999966 999965 999964 999963 999962 999961 999960 99995...

output:

0

result:

wrong answer 1st lines differ - expected: '31357504048070656', found: '0'

Test #14:

score: 0
Wrong Answer
time: 40ms
memory: 33328kb

input:

262144
999996 999994 999992 999988 999984 999979 999979 999977 999975 999974 999974 999972 999972 999970 999966 999964 999960 999960 999958 999958 999956 999954 999953 999951 999947 999947 999944 999942 999942 999939 999938 999936 999932 999929 999927 999926 999924 999923 999921 999920 999917 999916...

output:

0

result:

wrong answer 1st lines differ - expected: '31357492587251043', found: '0'

Test #15:

score: 0
Wrong Answer
time: 34ms
memory: 34988kb

input:

262144
999999 999999 1000000 999999 999999 1000000 999999 999999 1000000 999999 999999 1000000 999999 999999 1000000 999999 999999 1000000 999999 999999 1000000 999999 999999 1000000 999999 999999 1000000 999999 999999 1000000 999999 999999 1000000 999999 999999 1000000 999999 999999 1000000 999999 ...

output:

0

result:

wrong answer 1st lines differ - expected: '34360410609658551', found: '0'

Test #16:

score: 0
Wrong Answer
time: 45ms
memory: 35224kb

input:

262144
13108 13108 13108 13107 13108 13107 13107 13107 13107 13107 13107 13108 13108 13107 13106 13106 13107 13106 13107 13106 13107 13106 13107 13106 13106 13105 13105 13105 13106 13106 13106 13106 13105 13105 13104 13104 13104 13105 13105 13105 13105 13105 13104 13103 13104 13103 13104 13103 13104...

output:

25432776

result:

wrong answer 1st lines differ - expected: '300435587621709', found: '25432776'

Test #17:

score: 4.34783
Accepted
time: 7ms
memory: 31332kb

input:

300
999994 999993 999992 999992 999994 999993 999993 999994 999993 999993 999994 999994 999989 999989 999987 999987 999988 999988 999988 999989 999988 999987 999987 999988 999988 999988 999988 999991 999990 999990 999991 999991 999988 999988 999987 999987 999987 999987 999990 999988 999988 999988 99...

output:

44825213269

result:

ok single line: '44825213269'

Test #18:

score: 4.34783
Accepted
time: 22ms
memory: 91968kb

input:

3000
913347 411708 830707 139908 468414 282707 863947 767999 450119 677303 995373 830927 170138 485956 92253 450159 17536 876709 396157 624566 138039 747050 536096 755345 809347 388938 533086 633605 903211 209505 775942 150544 645398 777384 784526 972509 651132 777038 644255 300305 83761 999139 1441...

output:

4486507743420

result:

ok single line: '4486507743420'

Test #19:

score: 4.34783
Accepted
time: 19ms
memory: 91392kb

input:

3000
999988 999988 999989 999990 999991 999990 999989 999987 999986 999986 999987 999986 999985 999985 999990 999990 999990 999990 999990 999990 999991 999988 999988 999989 999990 999988 999987 999986 999985 999985 999989 999988 999987 999985 999985 999986 999988 999987 999986 999986 999986 999986 9...

output:

3872120136367

result:

ok single line: '3872120136367'

Test #20:

score: 0
Time Limit Exceeded

input:

262144
1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 6 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 7 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 6 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 8 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1...

output:


result:


Test #21:

score: 0
Time Limit Exceeded

input:

262144
1 1 2 1 1 2 1 1 3 1 1 2 1 1 2 1 1 3 1 1 2 1 1 2 1 1 4 1 1 2 1 1 2 1 1 3 1 1 2 1 1 2 1 1 3 1 1 2 1 1 2 1 1 4 1 1 2 1 1 2 1 1 3 1 1 2 1 1 2 1 1 3 1 1 2 1 1 2 1 1 5 1 1 2 1 1 2 1 1 3 1 1 2 1 1 2 1 1 3 1 1 2 1 1 2 1 1 4 1 1 2 1 1 2 1 1 3 1 1 2 1 1 2 1 1 3 1 1 2 1 1 2 1 1 4 1 1 2 1 1 2 1 1 3 1 1 2...

output:


result:


Test #22:

score: 0
Time Limit Exceeded

input:

262144
1 1 1 1 3 1 1 1 1 3 1 1 1 1 3 1 1 1 1 3 1 1 1 1 5 1 1 1 1 3 1 1 1 1 3 1 1 1 1 3 1 1 1 1 3 1 1 1 1 5 1 1 1 1 3 1 1 1 1 3 1 1 1 1 3 1 1 1 1 3 1 1 1 1 5 1 1 1 1 3 1 1 1 1 3 1 1 1 1 3 1 1 1 1 3 1 1 1 1 5 1 1 1 1 3 1 1 1 1 3 1 1 1 1 3 1 1 1 1 3 1 1 1 1 7 1 1 1 1 3 1 1 1 1 3 1 1 1 1 3 1 1 1 1 3 1 1...

output:


result:


Test #23:

score: 0
Wrong Answer
time: 36ms
memory: 33408kb

input:

262144
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 88 89 90 91 92 93 94 95 96 97 98 99 100 1...

output:

71981

result:

wrong answer 1st lines differ - expected: '6004868222550016', found: '71981'