이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int main(){
cin.tie(0) -> ios_base::sync_with_stdio(0);
int n;
cin >> n;
vector<int> a(n);
for(int i=0;i<n;i++) cin >> a[i];
set<int> s;
int ans = 1, i = 0;
while(i < n)
{
s.insert(a[i]);
i++;
if(a[i] < a[i - 1]) break;
}
for(;i<n;)
{
auto x = s.upper_bound(a[i]);
ans++;
int y;
if(x == s.end())
{
// cout << "1 = " << i << '\n';
y = a[i];
while(i < n)
{
s.insert(a[i]);
i++;
if(a[i] < a[i - 1]) break;
}
}
else if(a[i] <= *x)
{
// cout << "2 = " << i << " " << *x << "\n";
y = *x;
while(i < n && a[i] <= y)
{
// cout << i << " " << a[i] << '\n';
s.insert(a[i]);
i++;
if(a[i] < a[i-1]) break;
}
}
else // a[i] > the el after prev element
{
// cout << "3 = " << i << '\n';
s.insert(a[i]);
}
}
cout << ans << '\n';
}
# | 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... |