# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
482094 |
2021-10-23T04:51:22 Z |
Neos |
Po (COCI21_po) |
C++14 |
|
12 ms |
1784 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vii> vvii;
#define task "test"
#define fastIO ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define forw(i, l, r) for( ll i = (l) ; i < (r) ; i++ )
#define forb(i, r, l) for( ll i = (r) ; i >= (l) ; i-- )
#define numBit(x) (__builtin_popcountll(1ll * (x)))
#define getBit(x, i) ((x) >> (i) & 1)
#define sz(x) (int)x.size()
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define debug(x) cerr << #x << " = " << x << '\n';
const int N = 1e5 + 7;
const ll inf = 0x3f3f3f3f;
int n, a[N];
int main() {
fastIO;
cin >> n;
forw(i, 1, n + 1) cin >> a[i];
int ans = 0;
stack<int> st;
st.push(0);
forw(i, 1, n + 1) {
while (!st.empty() && a[st.top()] > a[i]) {
++ans;
st.pop();
}
if (!st.empty() && a[st.top()] < a[i]) st.push(i);
}
ans += sz(st) - 1;
cout << ans << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
4 ms |
588 KB |
Output is correct |
5 |
Correct |
11 ms |
716 KB |
Output is correct |
6 |
Correct |
12 ms |
1784 KB |
Output is correct |
7 |
Correct |
12 ms |
1624 KB |
Output is correct |