이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll maxn = 2*1e5+5, INF = 1e9+9;
void solve(){
int n;
cin >> n;
vector<int> a(n+1);
for(int i = 1; i <= n; i++){
cin >> a[i];
}
vector<int> f(n+1, INF);
f[0] = 0;
int last = 0;
a[0] = INF;
set<int> s;
for(int i = 1; i <= n; i++){
if(a[i] >= a[i-1]){
auto it = s.lower_bound(a[i]);
int L;
if(it != s.begin()){
L = *prev(it);
}else{
L = 0;
}
int l = last, r = i;
while(l <= r){
int mid = (l+r)/2;
if(a[mid] >= L){
r = mid-1;
}else{
l = mid+1;
}
}
if(a[l] < L){
f[i] = INF;
continue;
}
f[i] = f[l-1]+1;
}else{
for(int j = last; j < i; j++){
s.insert(a[j]);
}
last = i;
f[i] = f[i-1]+1;
}
}
cout << f[n];
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
}
# | 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... |