이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/// -- -- ---- --- -- --
/// 19.01.2023 Thu 22:49
/// -- -- ---- --- -- --
#include <bits/stdc++.h>
using namespace std;
#define pll pair<long long, long long>
#define all(a) (a).begin(), (a).end()
#define len(a) ((int)(a).size())
#define add push_back
#define mkp make_pair
#define ll long long
#define fr first
#define sc second
const long long INF = 1000000000ll * 1000000003ll;
const long long MOD = 1000000007ll;
const int N = 1e6 + 5;
ll n, a[N], ans = 0;
map<ll, bool> mp;
map<ll, bool>::iterator it;
void solve(){
cin >> n;
for(int i = 0; i < n; i++) cin >> a[i];
ll from = 0, kk = INF;
for(int i = 1; i < n; i++){
if(a[i] > kk || a[i - 1] > a[i]){
for(int j = from; j < i; j++){
mp[a[j]] = true;
}
ans++;
from = i;
it = mp.upper_bound(a[i]);
if(it == mp.end()) kk = INF;
else kk = it -> fr;
}
}
ans++;
cout << ans << "\n";
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
int _ = 1;
// cout << fixed;
// cout.precision(9);
// cin >> _ ;
while(_--) solve();
return 0;
}
/// ---- - -------- ------ -------- -- - - -
/// just a reminder. ubuntu password is i o i
/// ---- - -------- ------ -------- -- - - -
# | 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... |