QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#740964 | #3549. 262144 Revisited | _8_8_ | 21.73913 | 38ms | 76532kb | C++23 | 1.6kb | 2024-11-13 12:41:24 | 2024-11-13 12:41:25 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = (int)3e5 + 12;
int n, a[N], r[N], 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';
}
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;
ll res = 0;
for(int v = 1; v <= 80; v++) {
for(int i = 1; i <= n; i++) {
r[i] = r[r[i]];
if(a[i] == v) {
r[i] = i + 1;
}
}
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();
}
詳細信息
Pretests
Final Tests
Test #1:
score: 4.34783
Accepted
time: 1ms
memory: 7672kb
input:
6 1 3 1 2 1 10
output:
115
result:
ok single line: '115'
Test #2:
score: 0
Wrong Answer
time: 31ms
memory: 6896kb
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:
11787897
result:
wrong answer 1st lines differ - expected: '666881324292484', found: '11787897'
Test #3:
score: 0
Wrong Answer
time: 33ms
memory: 6644kb
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:
47296
result:
wrong answer 1st lines differ - expected: '14050699806935958', found: '47296'
Test #4:
score: 0
Wrong Answer
time: 32ms
memory: 7464kb
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: 37ms
memory: 7164kb
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: 38ms
memory: 6544kb
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: 6336kb
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: 37ms
memory: 6876kb
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: 33ms
memory: 7768kb
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: 31ms
memory: 7700kb
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: 38ms
memory: 6004kb
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:
1194
result:
wrong answer 1st lines differ - expected: '34357316353722230', found: '1194'
Test #12:
score: 4.34783
Accepted
time: 0ms
memory: 16264kb
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: 33ms
memory: 6516kb
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: 33ms
memory: 6792kb
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: 33ms
memory: 7080kb
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: 33ms
memory: 7652kb
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:
62425579
result:
wrong answer 1st lines differ - expected: '300435587621709', found: '62425579'
Test #17:
score: 4.34783
Accepted
time: 0ms
memory: 16396kb
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: 16ms
memory: 76532kb
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: 15ms
memory: 75616kb
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
Wrong Answer
time: 32ms
memory: 6556kb
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:
172721183235
result:
wrong answer 1st lines differ - expected: '735361899011', found: '172721183235'
Test #21:
score: 0
Wrong Answer
time: 32ms
memory: 6720kb
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:
67916511026
result:
wrong answer 1st lines differ - expected: '639147161394', found: '67916511026'
Test #22:
score: 0
Wrong Answer
time: 32ms
memory: 7724kb
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:
76547332410
result:
wrong answer 1st lines differ - expected: '669252819258', found: '76547332410'
Test #23:
score: 0
Wrong Answer
time: 37ms
memory: 6352kb
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:
170641
result:
wrong answer 1st lines differ - expected: '6004868222550016', found: '170641'