Submission #1159063

#TimeUsernameProblemLanguageResultExecution timeMemory
1159063MisterReaperMoney (IZhO17_money)C++20
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>

using i64 = long long;

#ifdef DEBUG
    #include "debug.h"
#else
    #define debug(...) void(23)
#endif

struct Fenwick {
    int n;
    std::vector<int> tree;
    Fenwick(int n_) : n(n_), tree(n + 1) {}
    void modify(int p, int x) {
        for (p += 1; p <= n; p += p & -p) {
            tree[p] += x;
        }
    }
    int query(int p) {
        int res = 0;
        for (p += 1; p; p -= p & -p) {
            res += tree[p];
        }
        return res;
    }
    int query(int l, int r) {
        return query(r) - query(l - 1);
    }
};

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

    int N;
    std::cin >> N;
    std::vector<int> A(N);
    for (int i = 0; i < N; ++i) {
        std::cin >> A[i];
    }

    std::vector<int> vec(A.begin(), A.end());
    std::sort(vec.begin(), vec.end());
    vec.erase(std::unique(vec.begin(), vec.end()), vec.end());
    for (int i = 0; i < N; ++i) {
        A[i] = std::lower_bound(vec.begin(), vec.end(), A[i]) - vec.begin();
    }

    Fenwick fen(N);
    int ans = 0;
    for (int i = 0, j = 0; i < N; i = ++j) {
        while (j + 1 < N && A[j] <= A[j + 1]) {
            j++;
            mn = A[i];
            mx = A[j];
            if (mn + 1 <= mx - 1 && fen.query(mn + 1, mx - 1)) {
                --j;
                break;
            }
        }
        for (int k = i; k <= j; ++k) {
            fen.modify(A[k], +1);
        }
        ans++;
    }

    std::cout << ans << '\n';

    return 0;
}

Compilation message (stderr)

money.cpp: In function 'int main()':
money.cpp:55:13: error: 'mn' was not declared in this scope; did you mean 'yn'?
   55 |             mn = A[i];
      |             ^~
      |             yn
money.cpp:56:13: error: 'mx' was not declared in this scope
   56 |             mx = A[j];
      |             ^~