QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#325844 | #4428. Fence | chengch | TL | 2320ms | 21252kb | C++20 | 1.9kb | 2024-02-12 01:17:20 | 2024-02-12 01:17:21 |
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);
int S = 0;
for (int b = 1; b <= M; b++) {
int res = 0;
int cur = 0;
for (int i = 1; i <= n; i = r[i]) {
S++;
assert(i == 1 || b <= a[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 = 2; 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];
}
}
}
assert(S <= M + accumulate(a + 1, a + 1 + n, 0));
cerr << S << ' ' << M + accumulate(a + 1, a + 1 + n, 0) << "\n";
}
}
详细
Test #1:
score: 100
Accepted
time: 2320ms
memory: 21252kb
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: -100
Time Limit Exceeded
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...