QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#741673#3549. 262144 Revisited_8_8_52.173913 1874ms117664kbC++232.1kb2024-11-13 14:57:582024-11-13 14:58:00

Judging History

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

  • [2024-11-13 14:58:00]
  • 评测
  • 测评结果:52.173913
  • 用时:1874ms
  • 内存:117664kb
  • [2024-11-13 14:57:58]
  • 提交

answer


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = (int)1e6 + 23;

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';

}
vector<int> p[N];
set<int> l[N];
void test() {
    cin >> n;
    for(int i = 1; i <= n; i++) {
        cin >> a[i], r[i] = i;
        p[a[i]].push_back(i);
    }
    r[n + 1] = n + 1;
    for(int i = 1; i <= n + 1; i++) {
        l[i].insert(i);
    }
    ll res = 0, s = 0;
    set<int> u;
    for(int v = 1; v < (int)1e6 + 22; v++) {
        set<int> u1;
        s += (int)u.size();
        d[v] = d[v - 1];
        for(int i:u) {
            assert(r[i] != r[r[i]]);
            l[r[i]].erase(i);
            d[v] -= (r[i] - i);
            r[i] = r[r[i]];
            d[v] += (r[i] - i);
            l[r[i]].insert(i);
            if(r[i] != r[r[i]]) {
                u1.insert(i);
            }
        }
        for(int i:p[v]) {
            r[i] = i + 1;
            d[v]++;
            for(int j:l[i]) {
                if(r[j] == r[r[j]]) continue;
                u1.insert(j);
            }
            l[i + 1].insert(i);
            l[i].clear();
        }
        u1.swap(u);
        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: 11ms
memory: 61248kb

input:

6
1 3 1 2 1 10

output:

115

result:

ok single line: '115'

Test #2:

score: 0
Time Limit Exceeded

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:


result:


Test #3:

score: 0
Time Limit Exceeded

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:


result:


Test #4:

score: 0
Time Limit Exceeded

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:


result:


Test #5:

score: 0
Time Limit Exceeded

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:


result:


Test #6:

score: 0
Time Limit Exceeded

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:


result:


Test #7:

score: 0
Time Limit Exceeded

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:


result:


Test #8:

score: 0
Time Limit Exceeded

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:


result:


Test #9:

score: 0
Time Limit Exceeded

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:


result:


Test #10:

score: 4.34783
Accepted
time: 900ms
memory: 100212kb

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:

34360299579681451

result:

ok single line: '34360299579681451'

Test #11:

score: 4.34783
Accepted
time: 1745ms
memory: 117664kb

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:

34357316353722230

result:

ok single line: '34357316353722230'

Test #12:

score: 4.34783
Accepted
time: 15ms
memory: 63060kb

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: 4.34783
Accepted
time: 92ms
memory: 89780kb

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:

31357504048070656

result:

ok single line: '31357504048070656'

Test #14:

score: 0
Time Limit Exceeded

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:


result:


Test #15:

score: 4.34783
Accepted
time: 936ms
memory: 104516kb

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:

34360410609658551

result:

ok single line: '34360410609658551'

Test #16:

score: 0
Time Limit Exceeded

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:


result:


Test #17:

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

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: 20ms
memory: 72828kb

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: 12ms
memory: 63336kb

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: 4.34783
Accepted
time: 1802ms
memory: 99380kb

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:

735361899011

result:

ok single line: '735361899011'

Test #21:

score: 4.34783
Accepted
time: 1598ms
memory: 100112kb

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:

639147161394

result:

ok single line: '639147161394'

Test #22:

score: 4.34783
Accepted
time: 1874ms
memory: 99584kb

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:

669252819258

result:

ok single line: '669252819258'

Test #23:

score: 0
Time Limit Exceeded

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:


result: