QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#325835#4428. FencechengchTL 0ms0kbC++201.9kb2024-02-12 00:59:472024-02-12 00:59:48

Judging History

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

  • [2024-02-12 00:59:48]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-02-12 00:59:47]
  • 提交

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);
            }
            assert(S <= M + accumulate(a + 1, a + 1 + n, 0));
            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];
                }
            }
        }
    }
}

詳細信息

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
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: