답안 #855128

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
855128 2023-09-30T08:27:41 Z Alfraganus Money (IZhO17_money) C++17
100 / 100
570 ms 19536 KB
#include <bits/stdc++.h>
using namespace std;

#define fs first
#define ss second
#define endl '\n'
#define all(a) a.begin(), a.end()

#define print(a)          \
    for (auto x : a)      \
        cout << x << ' '; \
    cout << endl;

#define printmp(a)   \
    for (auto x : a) \
        cout << x.fs << ' ' << x.ss << endl;

struct SegTree {
    int size = 1;
    vector<int> sums;

    SegTree (){
        while(1e6 > size)
            size <<= 1;
        sums.resize(size << 1);
    }

    void add(int i, int x, int lx, int rx){
        if(rx == lx + 1){
            sums[x] ++;
            return;
        }
        int m = (lx + rx) >> 1;
        if(i < m)
            add(i, (x << 1) + 1, lx, m);
        else
            add(i, (x << 1) + 2, m, rx);
        sums[x] = sums[(x << 1) + 1] + sums[(x << 1) + 2];
    }

    void add(int i){
        add(i, 0, 0, size);
    }

    int sum(int l, int r, int x, int lx, int rx){
        if(l <= lx and rx <= r)
            return sums[x];
        if(r <= lx or rx <= l)
            return 0;
        int m = (lx + rx) >> 1;
        return sum(l, r, (x << 1) + 1, lx, m) + sum(l, r, (x << 1) + 2, m, rx);
    }

    int sum(int l, int r){
        return sum(l, r, 0, 0, size);
    }
};

void solve()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i ++)
        cin >> a[i];
    SegTree s;
    int ans = 0;
    int l = 0, r = 0;
    while(l < n and r < n){
        while(r < n and a[max(l, r - 1)] <= a[r] and s.sum(a[l] + 1, a[r]) == 0)
            r ++;
        for(int i = l; i < r; i ++)
            s.add(a[i]);
        ans ++;
        l = r;
    }
    cout << ans;
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
        cout << endl;
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8540 KB Output is correct
2 Correct 2 ms 8540 KB Output is correct
3 Correct 2 ms 8516 KB Output is correct
4 Correct 2 ms 8536 KB Output is correct
5 Correct 2 ms 8540 KB Output is correct
6 Correct 2 ms 8652 KB Output is correct
7 Correct 2 ms 8796 KB Output is correct
8 Correct 2 ms 8540 KB Output is correct
9 Correct 2 ms 8540 KB Output is correct
10 Correct 2 ms 8540 KB Output is correct
11 Correct 2 ms 8540 KB Output is correct
12 Correct 2 ms 8540 KB Output is correct
13 Correct 3 ms 9048 KB Output is correct
14 Correct 2 ms 8540 KB Output is correct
15 Correct 2 ms 8540 KB Output is correct
16 Correct 3 ms 8644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8540 KB Output is correct
2 Correct 2 ms 8540 KB Output is correct
3 Correct 2 ms 8516 KB Output is correct
4 Correct 2 ms 8536 KB Output is correct
5 Correct 2 ms 8540 KB Output is correct
6 Correct 2 ms 8652 KB Output is correct
7 Correct 2 ms 8796 KB Output is correct
8 Correct 2 ms 8540 KB Output is correct
9 Correct 2 ms 8540 KB Output is correct
10 Correct 2 ms 8540 KB Output is correct
11 Correct 2 ms 8540 KB Output is correct
12 Correct 2 ms 8540 KB Output is correct
13 Correct 3 ms 9048 KB Output is correct
14 Correct 2 ms 8540 KB Output is correct
15 Correct 2 ms 8540 KB Output is correct
16 Correct 3 ms 8644 KB Output is correct
17 Correct 2 ms 8540 KB Output is correct
18 Correct 3 ms 8540 KB Output is correct
19 Correct 2 ms 8644 KB Output is correct
20 Correct 2 ms 8540 KB Output is correct
21 Correct 2 ms 8548 KB Output is correct
22 Correct 2 ms 8796 KB Output is correct
23 Correct 2 ms 8648 KB Output is correct
24 Correct 2 ms 8540 KB Output is correct
25 Correct 2 ms 8540 KB Output is correct
26 Correct 2 ms 8540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8540 KB Output is correct
2 Correct 2 ms 8540 KB Output is correct
3 Correct 2 ms 8516 KB Output is correct
4 Correct 2 ms 8536 KB Output is correct
5 Correct 2 ms 8540 KB Output is correct
6 Correct 2 ms 8652 KB Output is correct
7 Correct 2 ms 8796 KB Output is correct
8 Correct 2 ms 8540 KB Output is correct
9 Correct 2 ms 8540 KB Output is correct
10 Correct 2 ms 8540 KB Output is correct
11 Correct 2 ms 8540 KB Output is correct
12 Correct 2 ms 8540 KB Output is correct
13 Correct 3 ms 9048 KB Output is correct
14 Correct 2 ms 8540 KB Output is correct
15 Correct 2 ms 8540 KB Output is correct
16 Correct 3 ms 8644 KB Output is correct
17 Correct 2 ms 8540 KB Output is correct
18 Correct 3 ms 8540 KB Output is correct
19 Correct 2 ms 8644 KB Output is correct
20 Correct 2 ms 8540 KB Output is correct
21 Correct 2 ms 8548 KB Output is correct
22 Correct 2 ms 8796 KB Output is correct
23 Correct 2 ms 8648 KB Output is correct
24 Correct 2 ms 8540 KB Output is correct
25 Correct 2 ms 8540 KB Output is correct
26 Correct 2 ms 8540 KB Output is correct
27 Correct 2 ms 8792 KB Output is correct
28 Correct 2 ms 8540 KB Output is correct
29 Correct 2 ms 8540 KB Output is correct
30 Correct 2 ms 8528 KB Output is correct
31 Correct 2 ms 8540 KB Output is correct
32 Correct 2 ms 8644 KB Output is correct
33 Correct 3 ms 8792 KB Output is correct
34 Correct 2 ms 8796 KB Output is correct
35 Correct 2 ms 8540 KB Output is correct
36 Correct 2 ms 8540 KB Output is correct
37 Correct 2 ms 8536 KB Output is correct
38 Correct 3 ms 8796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8540 KB Output is correct
2 Correct 2 ms 8540 KB Output is correct
3 Correct 2 ms 8516 KB Output is correct
4 Correct 2 ms 8536 KB Output is correct
5 Correct 2 ms 8540 KB Output is correct
6 Correct 2 ms 8652 KB Output is correct
7 Correct 2 ms 8796 KB Output is correct
8 Correct 2 ms 8540 KB Output is correct
9 Correct 2 ms 8540 KB Output is correct
10 Correct 2 ms 8540 KB Output is correct
11 Correct 2 ms 8540 KB Output is correct
12 Correct 2 ms 8540 KB Output is correct
13 Correct 3 ms 9048 KB Output is correct
14 Correct 2 ms 8540 KB Output is correct
15 Correct 2 ms 8540 KB Output is correct
16 Correct 3 ms 8644 KB Output is correct
17 Correct 2 ms 8540 KB Output is correct
18 Correct 3 ms 8540 KB Output is correct
19 Correct 2 ms 8644 KB Output is correct
20 Correct 2 ms 8540 KB Output is correct
21 Correct 2 ms 8548 KB Output is correct
22 Correct 2 ms 8796 KB Output is correct
23 Correct 2 ms 8648 KB Output is correct
24 Correct 2 ms 8540 KB Output is correct
25 Correct 2 ms 8540 KB Output is correct
26 Correct 2 ms 8540 KB Output is correct
27 Correct 2 ms 8792 KB Output is correct
28 Correct 2 ms 8540 KB Output is correct
29 Correct 2 ms 8540 KB Output is correct
30 Correct 2 ms 8528 KB Output is correct
31 Correct 2 ms 8540 KB Output is correct
32 Correct 2 ms 8644 KB Output is correct
33 Correct 3 ms 8792 KB Output is correct
34 Correct 2 ms 8796 KB Output is correct
35 Correct 2 ms 8540 KB Output is correct
36 Correct 2 ms 8540 KB Output is correct
37 Correct 2 ms 8536 KB Output is correct
38 Correct 3 ms 8796 KB Output is correct
39 Correct 115 ms 13904 KB Output is correct
40 Correct 218 ms 17064 KB Output is correct
41 Correct 97 ms 12628 KB Output is correct
42 Correct 97 ms 12372 KB Output is correct
43 Correct 68 ms 11616 KB Output is correct
44 Correct 251 ms 19288 KB Output is correct
45 Correct 234 ms 19200 KB Output is correct
46 Correct 268 ms 19412 KB Output is correct
47 Correct 215 ms 19192 KB Output is correct
48 Correct 244 ms 19312 KB Output is correct
49 Correct 390 ms 19320 KB Output is correct
50 Correct 396 ms 19384 KB Output is correct
51 Correct 379 ms 19284 KB Output is correct
52 Correct 393 ms 19360 KB Output is correct
53 Correct 408 ms 19380 KB Output is correct
54 Correct 390 ms 19204 KB Output is correct
55 Correct 570 ms 19284 KB Output is correct
56 Correct 553 ms 19444 KB Output is correct
57 Correct 495 ms 19536 KB Output is correct
58 Correct 514 ms 19064 KB Output is correct
59 Correct 530 ms 19300 KB Output is correct
60 Correct 531 ms 19284 KB Output is correct
61 Correct 528 ms 19304 KB Output is correct
62 Correct 529 ms 19296 KB Output is correct