제출 #1336600

#제출 시각아이디문제언어결과실행 시간메모리
1336600sh_qaxxorov_571Financial Report (JOI21_financial)C++20
0 / 100
123 ms26272 KiB
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;

const int INF = 1e9 + 7;

struct SegmentTree {
    int n;
    vector<int> tree;
    SegmentTree(int _n) : n(_n), tree(4 * _n + 1, 0) {}

    void update(int node, int start, int end, int idx, int val) {
        if (start == end) {
            tree[node] = val;
            return;
        }
        int mid = (start + end) / 2;
        if (idx <= mid) update(2 * node, start, mid, idx, val);
        else update(2 * node + 1, mid + 1, end, idx, val);
        tree[node] = max(tree[2 * node], tree[2 * node + 1]);
    }

    int query(int node, int start, int end, int l, int r) {
        if (r < start || end < l || l > r) return 0;
        if (l <= start && end <= r) return tree[node];
        int mid = (start + end) / 2;
        return max(query(2 * node, start, mid, l, r), query(2 * node + 1, mid + 1, end, l, r));
    }
};

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

    int N, D;
    cin >> N >> D;

    vector<int> A(N);
    vector<int> coords;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        coords.push_back(A[i]);
    }

    sort(coords.begin(), coords.end());
    coords.erase(unique(coords.begin(), coords.end()), coords.end());
    auto get_rank = [&](int val) {
        return lower_bound(coords.begin(), coords.end(), val) - coords.begin() + 1;
    };

    int M = coords.size();
    SegmentTree st(M);
    vector<int> dp(N);
    
    vector<int> L(N);
    multiset<int> window;
    for (int i = 0, j = 0; i < N; i++) {
        if (i > 0) {
            window.insert(A[i - 1]);
            if (window.size() > D) {
                window.erase(window.find(A[i - 1 - D]));
            }
        }
        
        while (j < i) {
            bool can_jump = true;
            if (i - j > D) can_jump = false;
            if (can_jump) break;
            j++;
        }
        L[i] = j;
    }

    vector<vector<int>> to_remove(N + 1);
    for (int i = 0; i < N; i++) {
        int r = get_rank(A[i]);
        
        for (int idx : to_remove[i]) {
            st.update(1, 1, M, get_rank(A[idx]), 0);
        }

        dp[i] = st.query(1, 1, M, 1, r - 1) + 1;
        st.update(1, 1, M, r, dp[i]);
        
        int limit = i + D + 1;
        if (limit < N) {
            // D shartiga ko'ra o'chirish mantiqi
        }
    }

    int ans = 0;
    int cur_max = -1;
    for (int i = N - 1; i >= 0; i--) {
        if (A[i] > cur_max) {
            ans = max(ans, dp[i]);
            // pm = N sharti uchun max qiymatni tekshirish
        }
    }

    cout << dp[N - 1] << endl;

    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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...