이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
const int maxn = 1e6 + 3;
int n;
int a[maxn];
void read()
{
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
}
set <int> s;
void solve()
{
int ans = 0;
for (int i = 1; i <= n; )
{
ans++;
auto it = s.lower_bound(a[i]);
bool is = false;
for (int j = i+1; j <= n; j++)
{
auto it1 = s.lower_bound(a[j]);
if (a[j] < a[j-1] || !(it == s.end() || it1 == it || it1 == next(it)))
{
for (int k = i; k < j; k++)
s.insert(a[k]);
is = true;
i = j;
break;
}
}
if (!is)
break;
}
cout << ans << endl;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
read();
solve();
}
/*
6
3 6 4 5 1 2
*/
# | 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... |