# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
384150 | nguyen31hoang08minh2003 | Po (COCI21_po) | C++14 | 35 ms | 8300 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define fore(i, a, b) for (int i = (a), _b = (b); i < _b; ++i)
#define fort(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define ford(i, a, b) for (int i = (a), _b = (b); i >= _b; --i)
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
template<class A, class B> bool maxi(A &a, const B &b) {return (a < b) ? (a = b, true):false;};
template<class A, class B> bool mini(A &a, const B &b) {return (a > b) ? (a = b, true):false;};
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
const int maxN = 100005, inf = 1e9 + 31082003;
int n, a[maxN], res, r[maxN];
vi idx[maxN];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
vi v(n);
fort(i, 1, n) {
cin >> a[i];
v[i - 1] = a[i];
}
sort(all(v));
v.resize(distance(v.begin(), unique(all(v))));
const int m = sz(v);
fort(i, 1, n) {
a[i] = (lower_bound(all(v), a[i]) - v.begin()) + 1;
idx[a[i]].pb(i);
}
stack<int> st;
ford(i, n, 1) {
while (!st.empty() && a[st.top()] >= a[i])
st.pop();
r[i] = st.empty() ? inf : st.top();
st.push(i);
}
// fort(i, 1, n)
// cerr << r[i] << ' ';
// cerr << '\n';
fort(i, 1, m) {
int x = 0;
for (const int &j : idx[i]) {
if (x < j) {
x = r[j];
++res;
}
}
}
cout << res << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |