제출 #367103

#제출 시각아이디문제언어결과실행 시간메모리
367103ritul_kr_singhPo (COCI21_po)C++17
70 / 70
13 ms1516 KiB
//#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define sp << " " <<
#define nl << "\n"

signed main(){
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    int n; cin >> n;
    int a[n], ans = 0;
    for(int& i : a) cin >> i;

    stack<int> s;
    s.push(0);

    for(int i=0; i<n; ++i){
        while(!s.empty() and s.top() > a[i]){
            s.pop();
            ++ans;
        }
        if(s.empty() or s.top() < a[i]) s.push(a[i]);
    }
    while(!s.empty()){
        s.pop();
        ++ans;
    }
    cout << ans-1 nl;
}
#Verdict Execution timeMemoryGrader output
Fetching results...