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;
#define ll long long
const int N = 1e6 + 5;
#define pb push_back
#define sz size()
#define ff first
#define ss second
int a[N];
int main () {
// freopen("input.txt", "r", stdin);
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int n;
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
vector <int> seg;
set <int> s;
int ans = 0;
for (int i = 1; i <= n; ++i) {
if (seg.empty()) {
seg.pb (a[i]);
ans++;
}
else {
if (seg.back() > a[i]) {
for (int i : seg) {
s.insert (i);
}
seg.clear();
seg.pb (a[i]);
ans++;
}
else if (seg.back() == a[i]) {
seg.pb (a[i]);
}
else {
// seg[0] bilen a[i] aralyk setda san bamy men shony cek etsem bolyar
auto tr = s.upper_bound (seg[0]);
if (tr == s.end()) {
seg.pb (a[i]);
}
else {
if (*tr < a[i]) {
for (int i : seg) {
s.insert (i);
}
seg.clear();
ans++;
seg.pb (a[i]);
}
else seg.pb (a[i]);
}
}
}
}
cout << ans;
}
# | 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... |