Submission #66194192


Source Code Expand

#include<bits/stdc++.h>

using namespace std;

typedef long long i64;
constexpr int INF = 0x3f3f3f3f;
int n;
vector<int> a;

int main() {
    cin.tie(nullptr) -> sync_with_stdio(false);

    cin >> n;
    a.resize(n + 2);
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    a[0] = a[n + 1] = INF;

    vector<int> lpos(n + 1), rpos(n + 1);
    stack<int> stk;
    stk.push(0);
    for(int i = 1; i <= n; i++) {
        while(a[i] > a[stk.top()]) stk.pop();
        lpos[i] = stk.top() + 1;
        stk.push(i);
    }
    
    while(!stk.empty()) stk.pop();

    stk.push(n + 1);
    for(int i = n; i >= 1; i--) {
        while(a[i] >= a[stk.top()]) stk.pop();
        rpos[i] = stk.top() - 1;
        stk.push(i);
    }

    vector<i64> ans(n + 3);
    for(int i = 1; i <= n; i++) {
        int len = rpos[i] - lpos[i] + 1;
        auto [x1, x2] = minmax({i - lpos[i] + 1, rpos[i] - i + 1});
        ans[1] += a[i], ans[x1 + 1] -= a[i], ans[x2 + 1] -= a[i], ans[len + 2] += a[i];
    }

    partial_sum(ans.begin(), ans.end(), ans.begin());
    partial_sum(ans.begin(), ans.end(), ans.begin());

    for(int i = 1; i <= n; i++) {
        cout << ans[i] << '\n';
    }
    
    return 0;
}

Submission Info

Submission Time
Task F - Sums of Sliding Window Maximum
User dengstar
Language C++ 20 (gcc 12.2)
Score 550
Code Size 1253 Byte
Status AC
Exec Time 27 ms
Memory 7864 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 550 / 550
Status
AC × 3
AC × 37
Set Name Test Cases
Sample 00-sample-01.txt, 00-sample-02.txt, 00-sample-03.txt
All 00-sample-01.txt, 00-sample-02.txt, 00-sample-03.txt, 01-small-01.txt, 01-small-02.txt, 01-small-03.txt, 01-small-04.txt, 01-small-05.txt, 01-small-06.txt, 01-small-07.txt, 01-small-08.txt, 01-small-09.txt, 01-small-10.txt, 01-small-11.txt, 01-small-12.txt, 01-small-13.txt, 01-small-14.txt, 01-small-15.txt, 01-small-16.txt, 01-small-17.txt, 01-small-18.txt, 01-small-19.txt, 01-small-20.txt, 01-small-21.txt, 01-small-22.txt, 01-small-23.txt, 01-small-24.txt, 02-large-01.txt, 02-large-02.txt, 02-large-03.txt, 02-large-04.txt, 02-large-05.txt, 02-large-06.txt, 02-large-07.txt, 02-large-08.txt, 02-large-09.txt, 02-large-10.txt
Case Name Status Exec Time Memory
00-sample-01.txt AC 1 ms 3488 KiB
00-sample-02.txt AC 1 ms 3556 KiB
00-sample-03.txt AC 1 ms 3484 KiB
01-small-01.txt AC 1 ms 3444 KiB
01-small-02.txt AC 1 ms 3552 KiB
01-small-03.txt AC 1 ms 3556 KiB
01-small-04.txt AC 1 ms 3476 KiB
01-small-05.txt AC 1 ms 3472 KiB
01-small-06.txt AC 1 ms 3540 KiB
01-small-07.txt AC 1 ms 3504 KiB
01-small-08.txt AC 1 ms 3436 KiB
01-small-09.txt AC 1 ms 3396 KiB
01-small-10.txt AC 1 ms 3552 KiB
01-small-11.txt AC 1 ms 3488 KiB
01-small-12.txt AC 1 ms 3488 KiB
01-small-13.txt AC 1 ms 3484 KiB
01-small-14.txt AC 1 ms 3364 KiB
01-small-15.txt AC 1 ms 3536 KiB
01-small-16.txt AC 1 ms 3596 KiB
01-small-17.txt AC 1 ms 3416 KiB
01-small-18.txt AC 1 ms 3636 KiB
01-small-19.txt AC 1 ms 3420 KiB
01-small-20.txt AC 1 ms 3436 KiB
01-small-21.txt AC 1 ms 3484 KiB
01-small-22.txt AC 1 ms 3416 KiB
01-small-23.txt AC 1 ms 3432 KiB
01-small-24.txt AC 2 ms 3636 KiB
02-large-01.txt AC 24 ms 7856 KiB
02-large-02.txt AC 27 ms 7076 KiB
02-large-03.txt AC 16 ms 7864 KiB
02-large-04.txt AC 24 ms 6944 KiB
02-large-05.txt AC 26 ms 7048 KiB
02-large-06.txt AC 25 ms 7032 KiB
02-large-07.txt AC 27 ms 7140 KiB
02-large-08.txt AC 25 ms 7004 KiB
02-large-09.txt AC 25 ms 7644 KiB
02-large-10.txt AC 26 ms 7060 KiB