Submission #386430

#TimeUsernameProblemLanguageResultExecution timeMemory
386430phathnvPo (COCI21_po)C++11
70 / 70
13 ms876 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 1e5 + 7; int n, a[N]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]; int res = 0; stack<int> st; st.push(0); for(int i = 1; i <= n; i++){ while (a[st.top()] > a[i]){ st.pop(); res++; } if (a[st.top()] < a[i]) st.push(i); } res += st.size() - 1; cout << res; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...