QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#325665#4428. FencechengchTL 0ms0kbC++201.9kb2024-02-11 19:09:222024-02-11 19:09:22

Judging History

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

  • [2024-02-11 19:09:22]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-02-11 19:09:22]
  • 提交

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]) {
                if (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;
                    }
                }
                else {
                    res += s[i][cur];
                    cur ^= (len[i] & 1);
                }
            }
            printf("%d\n", res);
            for (int i = 1; i <= n; i = r[i])
                if (a[i] == b) {
                    len[i] = 1;
                    s[i][0] = a[i];
                }
            for (int i = 2; i <= n; i = r[i])
                if (len[i] && len[l[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: 0
Time Limit Exceeded

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
500101
500199
500318
500456
500526
500623
500774
500848
500948
501058
501147
501268
501458
501574
501667
501728
501782
501823
502049
502061
502281
502255
502438
502524
502585
502798
503036
502873
503076
503178
503504
503291
503463
503614
503854
504058
503761
503943
504121
504250
504468...

result: