Submission #1312323

#TimeUsernameProblemLanguageResultExecution timeMemory
1312323olocFinancial Report (JOI21_financial)C++20
65 / 100
395 ms48060 KiB
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vect;
//#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
//#define ordered_multiset tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>
#define pb push_back
#define f first
#define s second

const int N = 1024 * 512;
int tree[2 * N];


void upd(int v, int val){
    v += N;
    tree[v] = val;
    v /= 2;
    while(v){
        tree[v] = max(tree[2 * v], tree[2 * v + 1]);
        v /= 2;
    }
}

int query(int l, int r){
    l += N; r += N;
    int wyn = 0;
    while(l <= r){
        if(l % 2 == 1){
            wyn = max(tree[l], wyn);
            l++;
        }
        if(r % 2 == 0){
            wyn = max(tree[r], wyn);
            r--;
        }
        l /= 2; r /= 2;
    }
    return wyn;
}


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

    int n, d;
    cin >> n >> d;

    vect a(n + 1);
    a[0] = 0;

    for(int i = 1; i<= n; i++){
        cin >> a[i];
    }

    map<int, int> skal;
    int it = 1;
    for(int i = 1; i <= n; i++){
        skal[a[i]] = 1;
    }
    for(auto& x : skal){
        x.s = it++;
    }


    for(int i = 1; i <= n; i++){
        a[i] = skal[a[i]];
    }

    vect dp(n + 1);
    dp[0] = 0;

    multiset<int> aktyw, okno;
    for(int i = 1; i <= n; i++){
        int w1 = query(0, a[i] - 1) + 1, w2 = query(a[i], a[i]);
        dp[i] = w1;
        upd(a[i], max(w1, w2));
        aktyw.insert(a[i]);
        okno.insert(a[i]);
        if(i - d > 0){
            okno.erase(a[i - d]);
            while(!aktyw.empty() && *aktyw.begin() < *okno.begin()){
                upd(*aktyw.begin(), 0);
                aktyw.erase(aktyw.begin());
            }
        }

//        cout << "i: " << dp[i] << "\n";

    }

    int best = 0;
    for(int i = 1; i <= n; i++){
        best = max(best, dp[i]);
    }

    cout << best << "\n";



    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...