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"
using namespace std;
#ifdef Nero
#include "Deb.h"
#else
#define deb(...)
#endif
const int N = 1e6 + 6;
int a[N];
int seg[N * 2];
int tt[N];
void upd(int i, int val) {
tt[i] = val;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
int ans = 1;
vector<int> v;
for (int i = 0; i < n; ++i) {
if (v.empty()) {
v.push_back(a[i]);
upd(a[i], a[i]);
} else {
if (v.back() > a[i]) {
ans++;
v.clear();
v.push_back(a[i]);
upd(a[i], a[i]);
} else {
if (tt[v[0]] > a[i]) {
ans++;
v.clear();
v.push_back(a[i]);
upd(a[i], a[i]);
} else {
v.push_back(a[i]);
upd(v[0], a[i]);
}
}
}
}
cout << ans << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |