Submission #57960018


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
const char nl = '\n';
const char sp = ' ';
const int inf = 0x3f3f3f3f;
const string OUT[2]{ "NO", "YES" };
const string out[2]{ "No", "Yes" };
#define all(a) a.begin(), a.end()
#define dbg(a) cerr << (#a) << " = " << a << nl
#define OK() cerr << "OK until line " << __LINE__ << nl
using ll = long long;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ifstream fin(".in");
ofstream fout(".out");

auto start_time = chrono::high_resolution_clock::now();

double amcbn() {
    auto end_time = chrono::high_resolution_clock::now();
    return chrono::duration<double>(end_time - start_time).count();
}

template<typename T>
int rand(T a, T b) { return uniform_int_distribution<T>(a, b)(rng); }

template<typename T1, typename T2>
bool ckmax(T1& a, T2 b) { return a < b ? a = b, true : false; }

template<typename T1, typename T2>
bool ckmin(T1& a, T2 b) { return a > b ? a = b, true : false; }

const int nmax = 2e5;
int n;
int a[nmax + 5];
int nge[nmax + 5];
int dp[nmax + 5];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    stack<int> st;
    fill_n(nge + 1, n, n + 1);
    for (int i = 1; i <= n; ++i) {
        while (st.size() && a[st.top()] <= a[i]) {
            nge[st.top()] = i;
            st.pop();
        }
        st.push(i);
    }
    for (int i = n; i >= 1; --i) {
        dp[i] = dp[nge[i]] + 1;
    }
    for (int i = 1; i <= n; ++i) {
        cout << dp[i + 1] << sp;
    }
}

Submission Info

Submission Time
Task D - Buildings
User amcbn
Language C++ 20 (gcc 12.2)
Score 400
Code Size 1608 Byte
Status AC
Exec Time 19 ms
Memory 6304 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 42
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt, 01_random_34.txt, 01_random_35.txt, 01_random_36.txt, 01_random_37.txt, 01_random_38.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3468 KiB
00_sample_01.txt AC 1 ms 3560 KiB
00_sample_02.txt AC 1 ms 3536 KiB
01_random_00.txt AC 1 ms 3532 KiB
01_random_01.txt AC 1 ms 3404 KiB
01_random_02.txt AC 1 ms 3584 KiB
01_random_03.txt AC 1 ms 3704 KiB
01_random_04.txt AC 1 ms 3636 KiB
01_random_05.txt AC 2 ms 3688 KiB
01_random_06.txt AC 13 ms 5312 KiB
01_random_07.txt AC 6 ms 4312 KiB
01_random_08.txt AC 6 ms 4168 KiB
01_random_09.txt AC 19 ms 5904 KiB
01_random_10.txt AC 19 ms 5868 KiB
01_random_11.txt AC 19 ms 5908 KiB
01_random_12.txt AC 19 ms 5908 KiB
01_random_13.txt AC 19 ms 5872 KiB
01_random_14.txt AC 19 ms 5888 KiB
01_random_15.txt AC 19 ms 5876 KiB
01_random_16.txt AC 17 ms 5880 KiB
01_random_17.txt AC 17 ms 5900 KiB
01_random_18.txt AC 17 ms 6028 KiB
01_random_19.txt AC 17 ms 5944 KiB
01_random_20.txt AC 17 ms 5912 KiB
01_random_21.txt AC 17 ms 6028 KiB
01_random_22.txt AC 17 ms 5944 KiB
01_random_23.txt AC 17 ms 5880 KiB
01_random_24.txt AC 17 ms 5948 KiB
01_random_25.txt AC 17 ms 5904 KiB
01_random_26.txt AC 17 ms 5756 KiB
01_random_27.txt AC 17 ms 5968 KiB
01_random_28.txt AC 17 ms 5900 KiB
01_random_29.txt AC 17 ms 5844 KiB
01_random_30.txt AC 17 ms 5816 KiB
01_random_31.txt AC 17 ms 5876 KiB
01_random_32.txt AC 17 ms 5972 KiB
01_random_33.txt AC 18 ms 5904 KiB
01_random_34.txt AC 1 ms 3460 KiB
01_random_35.txt AC 1 ms 3564 KiB
01_random_36.txt AC 1 ms 3700 KiB
01_random_37.txt AC 18 ms 5908 KiB
01_random_38.txt AC 16 ms 6304 KiB