QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#325828#4428. FencechengchRE 0ms0kbC++201.7kb2024-02-12 00:45:412024-02-12 00:45:42

Judging History

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

  • [2024-02-12 00:45:42]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-02-12 00:45:41]
  • 提交

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() {
    scanf("%d", &T);
    while (T--) {
        scanf("%d", &n);
        for (int i = 1; i <= n; i++) {
            scanf("%d", &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]) {
                assert(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);
            }
            printf("%d\n", res);
            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];
                }
            }
        }
    }
}

详细

Test #1:

score: 0
Runtime Error

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:


result: