QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#325856 | #4428. Fence | chengch | AC ✓ | 166ms | 27124kb | C++20 | 1.7kb | 2024-02-12 01:45:29 | 2024-02-12 01:45:29 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int T, n, a[1000010], l[1000010], r[1000010];
int s[1000010][2], len[1000010];
int main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> T;
while (T--) {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
l[i] = i - 1;
r[i] = i + 1;
s[i][0] = s[i][1] = 0;
len[i] = 0;
}
int M = *max_element(a + 1, a + 1 + n);
for (int b = 1; b <= M; b++) {
int res = 0;
int cur = 0;
for (int i = 1; i <= n; i = r[i]) {
res += a[i] / b / 2 * b;
if ((a[i] / b) % 2 == 1) {
if (cur == 0) res += b;
cur ^= 1;
}
if (a[i] % b) {
if (cur == 0) res += a[i] % b;
cur ^= 1;
}
res += s[i][cur];
cur ^= (len[i] & 1);
}
cout << res << "\n";
for (int i = r[1]; i <= n; i = r[i]) {
if (a[i] == b) {
swap(s[i][0], s[i][1]);
s[i][0] += a[i];
len[i]++;
if (len[l[i]] % 2 == 0) {
s[l[i]][0] += s[i][0];
s[l[i]][1] += s[i][1];
}
else {
s[l[i]][0] += s[i][1];
s[l[i]][1] += s[i][0];
}
len[l[i]] += len[i];
r[l[i]] = r[i];
l[r[i]] = l[i];
}
}
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 166ms
memory: 16924kb
input:
5 333834 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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...
output:
500000 500000 499995 499987 500000 500032 499996 499987 500032 500000 499994 499998 499981 499996 500080 500090 500077 500032 499980 499915 500035 499941 500055 499923 500000 499980 499935 500042 500174 499905 500002 499998 500218 499899 499965 500010 500144 500242 499839 499915 499987 500010 500122...
result:
ok 2500000 lines
Test #2:
score: 0
Accepted
time: 71ms
memory: 16292kb
input:
5 48356 1 1 2 2 1 1 1 1 2 4 8 4 1 2 128 4 1 1 2 1 1 2 2 1 1 1 4 1 1 1 2 1 2 8 8 1 1 1 1 8 1 2 1 2 1 1 1 1 8 1 2 1 2 1 2 1 2 1 1 8 1 2 4 1 1 1 1 1 4 1 2 1 1 1 2 1 2 64 1 256 1 1 1 1 1 2 32 1 1 2 1 1 2 2 1 1 1 1 1 1 4 1 1 2 2 1 1 1 1 1 1 2 1 2 256 4 1 1 2 1 2 1 2 2 1 1 2 2 2 2 1 1 1 2 1 32 1 1 1 4 1 1...
output:
500000 499939 500012 499925 499701 499996 499780 499879 500247 499914 500226 500164 500084 500054 499449 499819 500132 500378 500533 500517 499941 499527 500493 500808 500635 499680 500903 500128 500111 500413 499462 500244 500233 499885 499983 500105 499925 500185 499961 499466 500376 500081 498569...
result:
ok 987898 lines
Test #3:
score: 0
Accepted
time: 61ms
memory: 16364kb
input:
5 100000 1 10 9 6 2 9 5 8 6 8 3 10 10 4 8 10 5 4 8 1 3 3 10 6 8 2 1 1 7 4 4 7 3 3 2 7 3 8 4 8 8 8 9 7 1 6 7 5 1 6 5 6 10 7 1 7 10 4 9 6 7 3 4 2 7 7 8 9 7 1 8 4 1 6 10 1 3 8 8 5 6 4 10 5 10 3 4 1 8 2 8 4 6 1 7 2 10 2 2 3 3 3 4 6 6 6 6 7 8 8 8 9 9 9 9 9 10 10 4 5 10 3 1 5 6 7 9 5 3 2 2 3 1 2 1 6 1 1 6...
output:
275038 275208 276333 274460 274715 278680 279579 271029 278720 274871 251536 251586 251550 251533 251687 251362 251680 251736 251758 251640 252228 251127 251367 250702 251853 250779 250632 250725 251045 251774 251515 249096 250101 253104 247732 248767 248976 249529 253658 252323 252069 251541 251651...
result:
ok 1010971 lines
Test #4:
score: 0
Accepted
time: 108ms
memory: 27124kb
input:
5 1413 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:
499496 499496 499494 499848 499491 500202 499487 500553 499498 500905 499497 501264 499498 501599 499446 501961 499443 502306 499413 502649 499443 503017 499414 503329 499499 503710 499498 504049 499501 504360 499310 504777 499233 505155 499499 505440 499170 505761 499498 506160 499091 506583 499505...
result:
ok 502830 lines
Test #5:
score: 0
Accepted
time: 0ms
memory: 11812kb
input:
5 1 1 1 3 2 1 1 2 1 2 2 3 1
output:
1 2 2 3 1 2 1 2 3 3
result:
ok 10 lines
Extra Test:
score: 0
Extra Test Passed