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;
const int N = 1'000'100;
int n;
#define viit vector<set<int>::iterator>
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
set<int> proceeded;
viit pos;
vector<int> buffer;
int ans = 0;
for (int i = 0; i < n; i++) {
int a;
cin >> a;
viit cur = {proceeded.lower_bound(a), proceeded.upper_bound(a)};
bool flag = false;
for (auto c1 : pos) for (auto c2 : cur)
flag |= (c1 == c2);
if (!buffer.empty() && buffer.back() <= a && flag) {
viit v;
for (auto c1 : pos) {
bool f = false;
for (auto c2 : cur) f |= (c1 == c2);
if (f)
v.push_back(c1);
}
pos = v;
} else {
for (int c : buffer)
proceeded.insert(c);
buffer.clear();
ans++;
pos = {proceeded.lower_bound(a), proceeded.upper_bound(a)};
}
buffer.push_back(a);
}
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... |