/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Wrong Answer 1ms 564.0 KiB
#3 Accepted 1ms 392.0 KiB
#4 Accepted 1ms 532.0 KiB
#5 Wrong Answer 1ms 480.0 KiB

Code

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1000000007;
#define sz(x) (ll)(x).size()
#define rd ({ll x; cin >> x; x; })
#define dbg(x) cerr << "[" #x "]  " << (x) << "\n"
// #define errv(x) {cerr << "["#x"]  ["; for (const auto& ___ : (x)) cerr << ___ << ", "; cerr << "]\n";}
// #define errvn(x, n) {cerr << "["#x"]  ["; for (auto ___ = 0; ___ < (n); ++___) cerr << (x)[___] << ", "; cerr << "]\n";}
// #define cerr if(0)cerr
#define xx first
#define yy second
mt19937 rnd(std::chrono::high_resolution_clock::now().time_since_epoch().count());
/*_________________________________________________________________________________________________________________________*/

void Solve()
{
    ll n;
    cin >> n;
    vector<ll> arr(n), lboro(n, 0), rchoto(n, 0);
    for (ll i = 0; i < n; i++) {
        cin >> arr[i];
    }
    stack<ll> st;
    for (ll i = 0; i < n; i++) {
        while (!st.empty() && arr[st.top()] < arr[i]) {
            st.pop();
        }
        lboro[i] = sz(st);
        st.push(i);
    }
    st = stack<ll>();
    for (ll i = n - 1; i >= 0; i--) {
        while (!st.empty() && arr[st.top()] > arr[i]) {
            st.pop();
        }
        rchoto[i] = sz(st);
        st.push(i);
    }
    ll ans = 0;
    for (ll i = 0; i < n; i++) {
        if (rchoto[i] >= arr[i] || lboro[i] >= arr[i])
            ans++;
        // cerr << lboro[i] << ' ' << rchoto[i] << ' ' << arr[i] << '\n';
    }
    cout << ans << '\n';
}

int32_t main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t = 1;
    // cin >> t;
    for (int i = 1; i <= t; i++) {
        // cout << "Case #" << i << ": "; // cout << "Case " << i << ": ";
        Solve();
    }
    return 0;
}
// Coded by Tahsin Arafat (@TahsinArafat)

Information

Submit By
Type
Submission
Problem
P1184 The Curious Kid and the Number Game
Contest
Brain Booster #9
Language
C++17 (G++ 13.2.0)
Submit At
2025-04-06 15:46:47
Judged At
2025-04-06 15:46:47
Judged By
Score
3
Total Time
1ms
Peak Memory
564.0 KiB