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