이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |