제출 #682507

#제출 시각아이디문제언어결과실행 시간메모리
682507opPOMoney (IZhO17_money)C++17
100 / 100
982 ms61996 KiB
#pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define int long long
#define f first
#define s second
#define pb push_back
#define ld long double
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define vec vector

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using oset = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;

mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count());
const ld eps = 1e-6;
const int mod = 998244353;
const int oo = 2e9;
const ll OO = 2e18;
const int N = 2e5 + 10;

void solve()
{
    int n;
    cin >> n;
    vec<int> a(n + 1);
    for (int i = 1; i <= n; i++) cin >> a[i];
    multiset<int> setik;
    int ans = 1;
    int last = 1;
    for (int i = 2; i <= n; i++)
    {
        if (a[i] < a[i - 1])
        {
            ans++;
            for (int j = last; j < i; j++) setik.insert(a[j]);
            last = i;
            continue;
        }
        auto it = setik.upper_bound(a[last]);
        if (it != setik.end() && a[i] > *it)
        {
            ans++;
            for (int j = last; j < i; j++) setik.insert(a[j]);
            last = i;
        }
    }
    cout << ans;
}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    solve();
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...