Submission #904960


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

int main(void) {
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> L(n), R(n);
    for (int i = 0; i < n; ++ i) {
        L[i] = R[i] = i;
        cin >> a[i];
    }


    vector<int> st;
    for (int i = 0; i < n; ++ i) {
        while (!st.empty() && a[i] < a[st.back()]) {
            L[i] = L[st.back()];
            st.pop_back();
        }
        st.push_back(i);
    }

    st.clear();
    for (int i = n - 1; i >= 0; -- i) {
        while (!st.empty() && a[i] < a[st.back()]) {
            R[i] = R[st.back()];
            st.pop_back();
        }
        st.push_back(i);
    }

    ll ans = 0;
    for (int i = 0; i < n; ++ i) {
        //cerr << L[i] << ' ' << R[i] << endl;
        ans += (ll)a[i] * (R[i] - i + 1) * (i - L[i] + 1);
    }

    cout << ans << endl;

    return 0;
}

Submission Info

Submission Time
Task A - STring
User Stomach_ache
Language C++14 (GCC 5.4.1)
Score 0
Code Size 954 Byte
Status WA
Exec Time 3 ms
Memory 256 KB

Judge Result

Set Name Sample Subtask1 All
Score / Max Score 0 / 0 0 / 200 0 / 100
Status
AC × 1
WA × 2
AC × 3
WA × 6
AC × 4
WA × 9
Set Name Test Cases
Sample example0, example1, example2
Subtask1 example0, example1, example2, sub_corner0, sub_corner1, sub_corner2, sub_rand0, handmade0, handmade1
All corner0, corner1, corner2, example0, example1, example2, handmade0, handmade1, maxrand0, sub_corner0, sub_corner1, sub_corner2, sub_rand0
Case Name Status Exec Time Memory
corner0 AC 3 ms 256 KB
corner1 WA 3 ms 256 KB
corner2 WA 3 ms 256 KB
example0 WA 3 ms 256 KB
example1 AC 3 ms 256 KB
example2 WA 3 ms 256 KB
handmade0 AC 3 ms 256 KB
handmade1 WA 3 ms 256 KB
maxrand0 WA 3 ms 256 KB
sub_corner0 AC 3 ms 256 KB
sub_corner1 WA 2 ms 256 KB
sub_corner2 WA 3 ms 256 KB
sub_rand0 WA 3 ms 256 KB