답안 #882712

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
882712 2023-12-03T13:48:40 Z Sokol080808 Money (IZhO17_money) C++17
100 / 100
149 ms 23084 KB
#ifdef ONPC
    #define _GLIBCXX_DEBUG
#endif

#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
#include <malloc.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

using ll = long long;
using ull = unsigned long long;
using ld = long double;

template<typename T1, typename T2> istream& operator>>(istream& in, pair<T1, T2>& p) {in >> p.first >> p.second; return in;}
template<typename T1, typename T2> ostream& operator<<(ostream& out, pair<T1, T2>& p) {out << p.first << ' ' << p.second; return out;}
template<typename T> istream& operator>>(istream& in, vector<T>& v) {for (auto& x : v) in >> x; return in;}
template<typename T> ostream& operator<<(ostream& out, vector<T>& v) {for (auto& x : v) out << x << ' '; return out;}
template<typename T> ostream& operator<<(ostream& out, set<T>& v) {for (auto& x : v) out << x << ' '; return out;}
template<typename T> ostream& operator<<(ostream& out, multiset<T>& v) {for (auto& x : v) out << x << ' '; return out;}

const int MAX_INT = 2147483647;
const double pi = acos(-1.0);
const int mod = 1e9 + 7;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

struct Fenwick {
    vector<ll> t;
    int SIZE;

    Fenwick(int n): SIZE(n) {
        t.assign(SIZE, 0);
    }

    void inc(int ind, ll delta) {
        for (int i = ind; i < SIZE; i = (i | (i + 1))) t[i] += delta;
    }

    ll sum(int r) {
        ll res = 0;
        for (; r >= 0; r = (r & (r + 1)) - 1) res += t[r];
        return res;
    }

    ll sum(int l, int r) {
        if (l > r) return 0;
        return sum(r) - sum(l - 1);
    }
};

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    cin >> n;
    vector<int> a(n + 1);
    for (int i = 1; i <= n; i++) cin >> a[i];

    vector<int> dp(n + 1, 1e9);
    dp[0] = 0;

    Fenwick f(1000001);
    int j = 1;
    for (int i = 1; i <= n; i++) {
        while (f.sum(a[j] + 1, a[i] - 1) > 0) {
            f.inc(a[j], 1);
            j++;
        }
        dp[i] = dp[j - 1] + 1;
        if (i < n && a[i + 1] < a[i]) {
            for (int k = j; k <= i; k++) f.inc(a[k], 1);
            j = i + 1;
        }        
    }

    cout << dp[n] << '\n';

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8280 KB Output is correct
2 Correct 2 ms 8284 KB Output is correct
3 Correct 2 ms 8284 KB Output is correct
4 Correct 1 ms 8144 KB Output is correct
5 Correct 2 ms 8284 KB Output is correct
6 Correct 2 ms 8136 KB Output is correct
7 Correct 2 ms 8284 KB Output is correct
8 Correct 2 ms 8052 KB Output is correct
9 Correct 2 ms 8144 KB Output is correct
10 Correct 2 ms 8284 KB Output is correct
11 Correct 2 ms 8284 KB Output is correct
12 Correct 2 ms 8284 KB Output is correct
13 Correct 2 ms 8284 KB Output is correct
14 Correct 2 ms 8284 KB Output is correct
15 Correct 2 ms 8284 KB Output is correct
16 Correct 2 ms 8284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8280 KB Output is correct
2 Correct 2 ms 8284 KB Output is correct
3 Correct 2 ms 8284 KB Output is correct
4 Correct 1 ms 8144 KB Output is correct
5 Correct 2 ms 8284 KB Output is correct
6 Correct 2 ms 8136 KB Output is correct
7 Correct 2 ms 8284 KB Output is correct
8 Correct 2 ms 8052 KB Output is correct
9 Correct 2 ms 8144 KB Output is correct
10 Correct 2 ms 8284 KB Output is correct
11 Correct 2 ms 8284 KB Output is correct
12 Correct 2 ms 8284 KB Output is correct
13 Correct 2 ms 8284 KB Output is correct
14 Correct 2 ms 8284 KB Output is correct
15 Correct 2 ms 8284 KB Output is correct
16 Correct 2 ms 8284 KB Output is correct
17 Correct 2 ms 8284 KB Output is correct
18 Correct 2 ms 8284 KB Output is correct
19 Correct 2 ms 8284 KB Output is correct
20 Correct 2 ms 8284 KB Output is correct
21 Correct 2 ms 8284 KB Output is correct
22 Correct 2 ms 8140 KB Output is correct
23 Correct 2 ms 8284 KB Output is correct
24 Correct 2 ms 8284 KB Output is correct
25 Correct 2 ms 8284 KB Output is correct
26 Correct 2 ms 8284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8280 KB Output is correct
2 Correct 2 ms 8284 KB Output is correct
3 Correct 2 ms 8284 KB Output is correct
4 Correct 1 ms 8144 KB Output is correct
5 Correct 2 ms 8284 KB Output is correct
6 Correct 2 ms 8136 KB Output is correct
7 Correct 2 ms 8284 KB Output is correct
8 Correct 2 ms 8052 KB Output is correct
9 Correct 2 ms 8144 KB Output is correct
10 Correct 2 ms 8284 KB Output is correct
11 Correct 2 ms 8284 KB Output is correct
12 Correct 2 ms 8284 KB Output is correct
13 Correct 2 ms 8284 KB Output is correct
14 Correct 2 ms 8284 KB Output is correct
15 Correct 2 ms 8284 KB Output is correct
16 Correct 2 ms 8284 KB Output is correct
17 Correct 2 ms 8284 KB Output is correct
18 Correct 2 ms 8284 KB Output is correct
19 Correct 2 ms 8284 KB Output is correct
20 Correct 2 ms 8284 KB Output is correct
21 Correct 2 ms 8284 KB Output is correct
22 Correct 2 ms 8140 KB Output is correct
23 Correct 2 ms 8284 KB Output is correct
24 Correct 2 ms 8284 KB Output is correct
25 Correct 2 ms 8284 KB Output is correct
26 Correct 2 ms 8284 KB Output is correct
27 Correct 2 ms 8284 KB Output is correct
28 Correct 3 ms 8284 KB Output is correct
29 Correct 2 ms 8284 KB Output is correct
30 Correct 2 ms 8284 KB Output is correct
31 Correct 2 ms 8284 KB Output is correct
32 Correct 2 ms 8144 KB Output is correct
33 Correct 2 ms 8284 KB Output is correct
34 Correct 2 ms 8284 KB Output is correct
35 Correct 2 ms 8284 KB Output is correct
36 Correct 2 ms 8284 KB Output is correct
37 Correct 2 ms 8284 KB Output is correct
38 Correct 2 ms 8284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8280 KB Output is correct
2 Correct 2 ms 8284 KB Output is correct
3 Correct 2 ms 8284 KB Output is correct
4 Correct 1 ms 8144 KB Output is correct
5 Correct 2 ms 8284 KB Output is correct
6 Correct 2 ms 8136 KB Output is correct
7 Correct 2 ms 8284 KB Output is correct
8 Correct 2 ms 8052 KB Output is correct
9 Correct 2 ms 8144 KB Output is correct
10 Correct 2 ms 8284 KB Output is correct
11 Correct 2 ms 8284 KB Output is correct
12 Correct 2 ms 8284 KB Output is correct
13 Correct 2 ms 8284 KB Output is correct
14 Correct 2 ms 8284 KB Output is correct
15 Correct 2 ms 8284 KB Output is correct
16 Correct 2 ms 8284 KB Output is correct
17 Correct 2 ms 8284 KB Output is correct
18 Correct 2 ms 8284 KB Output is correct
19 Correct 2 ms 8284 KB Output is correct
20 Correct 2 ms 8284 KB Output is correct
21 Correct 2 ms 8284 KB Output is correct
22 Correct 2 ms 8140 KB Output is correct
23 Correct 2 ms 8284 KB Output is correct
24 Correct 2 ms 8284 KB Output is correct
25 Correct 2 ms 8284 KB Output is correct
26 Correct 2 ms 8284 KB Output is correct
27 Correct 2 ms 8284 KB Output is correct
28 Correct 3 ms 8284 KB Output is correct
29 Correct 2 ms 8284 KB Output is correct
30 Correct 2 ms 8284 KB Output is correct
31 Correct 2 ms 8284 KB Output is correct
32 Correct 2 ms 8144 KB Output is correct
33 Correct 2 ms 8284 KB Output is correct
34 Correct 2 ms 8284 KB Output is correct
35 Correct 2 ms 8284 KB Output is correct
36 Correct 2 ms 8284 KB Output is correct
37 Correct 2 ms 8284 KB Output is correct
38 Correct 2 ms 8284 KB Output is correct
39 Correct 56 ms 15248 KB Output is correct
40 Correct 86 ms 19780 KB Output is correct
41 Correct 43 ms 13756 KB Output is correct
42 Correct 40 ms 13140 KB Output is correct
43 Correct 29 ms 11604 KB Output is correct
44 Correct 114 ms 22648 KB Output is correct
45 Correct 116 ms 22664 KB Output is correct
46 Correct 125 ms 22724 KB Output is correct
47 Correct 98 ms 22944 KB Output is correct
48 Correct 149 ms 23084 KB Output is correct
49 Correct 137 ms 22900 KB Output is correct
50 Correct 122 ms 22664 KB Output is correct
51 Correct 117 ms 22824 KB Output is correct
52 Correct 116 ms 22652 KB Output is correct
53 Correct 125 ms 22836 KB Output is correct
54 Correct 125 ms 22724 KB Output is correct
55 Correct 115 ms 22652 KB Output is correct
56 Correct 111 ms 22612 KB Output is correct
57 Correct 123 ms 22840 KB Output is correct
58 Correct 125 ms 22836 KB Output is correct
59 Correct 134 ms 22612 KB Output is correct
60 Correct 118 ms 22612 KB Output is correct
61 Correct 118 ms 22780 KB Output is correct
62 Correct 112 ms 22608 KB Output is correct