Submission #1042557

# Submission time Handle Problem Language Result Execution time Memory
1042557 2024-08-03T07:08:53 Z Whisper Money (IZhO17_money) C++17
100 / 100
128 ms 22908 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define int long long
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (b); i >= (a); i --)
#define REP(i, a) for (int i = 0; i < (a); ++i)
#define REPD(i, a) for (int i = (a) - 1; i >= 0; --i)

#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)


constexpr ll LINF = (1ll << 60);
constexpr int INF = (1ll << 30);
constexpr int Mod = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

/*
    Phu Trong from Nguyen Tat Thanh High School for gifted student
*/

template <class X, class Y>
    bool minimize(X &x, const Y &y){
        X eps = 1e-9;
        if (x > y + eps) {x = y; return 1;}
        return 0;
    }

template <class X, class Y>
    bool maximize(X &x, const Y &y){
        X eps = 1e-9;
        if (x + eps < y) {x = y; return 1;}
        return 0;
    }
#define MAX             1000005
int nArr;
int A[MAX];

struct FenwickTree{
    vector<int> F;
    int n;
    FenwickTree(int _n = 0){
        this -> n = _n;
        F.resize(n + 5, 0);
    }
    int low_bit(int p){
        return p & (-p);
    }

    void upd(int p){
        for (; p <= n; p += low_bit(p)){
            F[p]++;
        }
    }
    int query(int p){
        int res = 0;
        for (; p > 0; p -= low_bit(p)){
            res += F[p];
        }
        return res;
    }
    int query(int l, int r){
        return query(r) - query(l - 1);
    }
};

void process(void){
    cin >> nArr;
    for (int i = 1; i <= nArr; ++i) cin >> A[i];

    int ans = 1;
    int lim = *max_element(A + 1, A + nArr + 1);
    int head = 1;
    FenwickTree ft(lim);

    ft.upd(A[1]);
    for (int i = 2; i <= nArr; ++i){
        if (A[i] < A[i - 1]){
            while(head < i) ft.upd(A[head++]);
            ++ans;
            continue;
        }
        if(ft.query(A[head] + 1, A[i] - 1) > 0){
            while(head < i) ft.upd(A[head++]);
            ++ans;
        }
    }
    cout << ans;
}
signed main(){
    #define name "Whisper"
    cin.tie(nullptr) -> sync_with_stdio(false);
    //freopen(name".inp", "r", stdin);
    //freopen(name".out", "w", stdout);
    process();
    return (0 ^ 0);
}




# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 6236 KB Output is correct
8 Correct 2 ms 8028 KB Output is correct
9 Correct 1 ms 4956 KB Output is correct
10 Correct 1 ms 4956 KB Output is correct
11 Correct 1 ms 6748 KB Output is correct
12 Correct 1 ms 5980 KB Output is correct
13 Correct 2 ms 6748 KB Output is correct
14 Correct 1 ms 4824 KB Output is correct
15 Correct 1 ms 8284 KB Output is correct
16 Correct 2 ms 7260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 6236 KB Output is correct
8 Correct 2 ms 8028 KB Output is correct
9 Correct 1 ms 4956 KB Output is correct
10 Correct 1 ms 4956 KB Output is correct
11 Correct 1 ms 6748 KB Output is correct
12 Correct 1 ms 5980 KB Output is correct
13 Correct 2 ms 6748 KB Output is correct
14 Correct 1 ms 4824 KB Output is correct
15 Correct 1 ms 8284 KB Output is correct
16 Correct 2 ms 7260 KB Output is correct
17 Correct 2 ms 7772 KB Output is correct
18 Correct 1 ms 6748 KB Output is correct
19 Correct 1 ms 6748 KB Output is correct
20 Correct 2 ms 8028 KB Output is correct
21 Correct 1 ms 5720 KB Output is correct
22 Correct 2 ms 7516 KB Output is correct
23 Correct 2 ms 6748 KB Output is correct
24 Correct 2 ms 6236 KB Output is correct
25 Correct 2 ms 7000 KB Output is correct
26 Correct 1 ms 7772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 6236 KB Output is correct
8 Correct 2 ms 8028 KB Output is correct
9 Correct 1 ms 4956 KB Output is correct
10 Correct 1 ms 4956 KB Output is correct
11 Correct 1 ms 6748 KB Output is correct
12 Correct 1 ms 5980 KB Output is correct
13 Correct 2 ms 6748 KB Output is correct
14 Correct 1 ms 4824 KB Output is correct
15 Correct 1 ms 8284 KB Output is correct
16 Correct 2 ms 7260 KB Output is correct
17 Correct 2 ms 7772 KB Output is correct
18 Correct 1 ms 6748 KB Output is correct
19 Correct 1 ms 6748 KB Output is correct
20 Correct 2 ms 8028 KB Output is correct
21 Correct 1 ms 5720 KB Output is correct
22 Correct 2 ms 7516 KB Output is correct
23 Correct 2 ms 6748 KB Output is correct
24 Correct 2 ms 6236 KB Output is correct
25 Correct 2 ms 7000 KB Output is correct
26 Correct 1 ms 7772 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 2 ms 7516 KB Output is correct
33 Correct 1 ms 5724 KB Output is correct
34 Correct 2 ms 8028 KB Output is correct
35 Correct 1 ms 4440 KB Output is correct
36 Correct 2 ms 6584 KB Output is correct
37 Correct 2 ms 8028 KB Output is correct
38 Correct 2 ms 8164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 6236 KB Output is correct
8 Correct 2 ms 8028 KB Output is correct
9 Correct 1 ms 4956 KB Output is correct
10 Correct 1 ms 4956 KB Output is correct
11 Correct 1 ms 6748 KB Output is correct
12 Correct 1 ms 5980 KB Output is correct
13 Correct 2 ms 6748 KB Output is correct
14 Correct 1 ms 4824 KB Output is correct
15 Correct 1 ms 8284 KB Output is correct
16 Correct 2 ms 7260 KB Output is correct
17 Correct 2 ms 7772 KB Output is correct
18 Correct 1 ms 6748 KB Output is correct
19 Correct 1 ms 6748 KB Output is correct
20 Correct 2 ms 8028 KB Output is correct
21 Correct 1 ms 5720 KB Output is correct
22 Correct 2 ms 7516 KB Output is correct
23 Correct 2 ms 6748 KB Output is correct
24 Correct 2 ms 6236 KB Output is correct
25 Correct 2 ms 7000 KB Output is correct
26 Correct 1 ms 7772 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 2 ms 7516 KB Output is correct
33 Correct 1 ms 5724 KB Output is correct
34 Correct 2 ms 8028 KB Output is correct
35 Correct 1 ms 4440 KB Output is correct
36 Correct 2 ms 6584 KB Output is correct
37 Correct 2 ms 8028 KB Output is correct
38 Correct 2 ms 8164 KB Output is correct
39 Correct 43 ms 14456 KB Output is correct
40 Correct 71 ms 18956 KB Output is correct
41 Correct 31 ms 13404 KB Output is correct
42 Correct 35 ms 14420 KB Output is correct
43 Correct 34 ms 11376 KB Output is correct
44 Correct 94 ms 22264 KB Output is correct
45 Correct 92 ms 21764 KB Output is correct
46 Correct 91 ms 22612 KB Output is correct
47 Correct 68 ms 22404 KB Output is correct
48 Correct 77 ms 21328 KB Output is correct
49 Correct 104 ms 22908 KB Output is correct
50 Correct 109 ms 22908 KB Output is correct
51 Correct 123 ms 22612 KB Output is correct
52 Correct 111 ms 22772 KB Output is correct
53 Correct 124 ms 22776 KB Output is correct
54 Correct 128 ms 22608 KB Output is correct
55 Correct 107 ms 22608 KB Output is correct
56 Correct 108 ms 22700 KB Output is correct
57 Correct 111 ms 22656 KB Output is correct
58 Correct 111 ms 22608 KB Output is correct
59 Correct 112 ms 22608 KB Output is correct
60 Correct 106 ms 22608 KB Output is correct
61 Correct 109 ms 22612 KB Output is correct
62 Correct 113 ms 22784 KB Output is correct