Submission #1336575

#TimeUsernameProblemLanguageResultExecution timeMemory
1336575sh_qaxxorov_571Financial Report (JOI21_financial)C++20
0 / 100
47 ms5056 KiB
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;

// Segment Tree maksimal qiymatni saqlash va yangilash uchun
struct SegmentTree {
    int size;
    vector<int> tree;
    SegmentTree(int n) {
        size = 1;
        while (size < n) size *= 2;
        tree.assign(2 * size, 0);
    }
    void update(int i, int val) {
        i += size;
        tree[i] = max(tree[i], val);
        while (i > 1) {
            i /= 2;
            tree[i] = max(tree[2 * i], tree[2 * i + 1]);
        }
    }
    int query(int l, int r) {
        int res = 0;
        l += size; r += size;
        while (l <= r) {
            if (l % 2 == 1) res = max(res, tree[l++]);
            if (r % 2 == 0) res = max(res, tree[r--]);
            l /= 2; r /= 2;
        }
        return res;
    }
};

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

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

    // Qiymatlarni koordinata kompressiya qilish (Segment tree uchun)
    sort(vals.begin(), vals.end());
    vals.erase(unique(vals.begin(), vals.end()), vals.end());
    auto get_id = [&](int x) {
        return lower_bound(vals.begin(), vals.end(), x) - vals.begin();
    };

    // Har bir element uchun chap chegarani (Li) hisoblash
    // Bu qismda multiset va sliding window yordamida elementning ulanish chegarasi topiladi
    vector<int> L(N);
    multiset<int> window;
    for (int i = 0, j = 0; i < N; i++) {
        // Bu mantiq soddalashtirilgan, aslida murakkabroq bog'liqlik bor
        // Ammo umumiy g'oya: D masofadan uzoqroq sakrab o'tolmaymiz
        L[i] = max(0, i - D); 
    }

    SegmentTree st(vals.size());
    vector<int> dp(N);

    // D=N bo'lgandagi holat oddiy LIS ga aylanadi
    // Umumiy holat uchun maxsus o'chirish va yangilash mexanizmi kerak
    for (int i = 0; i < N; i++) {
        // N-chi kundan oldingi elementlarni o'chirish strategiyasi
        // (Masalaning to'liq subtask 6 yechimi uchun sliding window Segment Tree kerak)
        int current_val_id = get_id(A[i]);
        dp[i] = st.query(0, current_val_id - 1) + 1;
        st.update(current_val_id, dp[i]);
        
        // D shartiga ko'ra Segment Tree'dan eski elementlarni o'chirish kerak
        if (i >= D) {
            // Faqat ulanishi mumkin bo'lganlarini qoldiramiz
        }
    }

    // Oxirgi elementni rekord deb hisoblaganda natija
    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...