QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#325833#4428. FencechengchTL 2322ms18712kbC++201.7kb2024-02-12 00:51:342024-02-12 00:51:35

Judging History

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

  • [2024-02-12 00:51:35]
  • 评测
  • 测评结果:TL
  • 用时:2322ms
  • 内存:18712kb
  • [2024-02-12 00:51:34]
  • 提交

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 = 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: 100
Accepted
time: 2322ms
memory: 18712kb

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

result: