제출 #1126725

#제출 시각아이디문제언어결과실행 시간메모리
1126725vladiliusFinancial Report (JOI21_financial)C++20
48 / 100
4094 ms6140 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define pb push_back
#define ff first
#define ss second

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    int n, d; cin>>n>>d;
    vector<int> a(n + 1);
    vector<pii> all;
    for (int i = 1; i <= n; i++){
        cin>>a[i];
        all.pb({a[i], i});
    }
    sort(all.begin(), all.end());
    int i = 0, m = 0;
    while (i < n){
        int j = i; m++;
        while (j < n && all[i].ff == all[j].ff){
            a[all[j].ss] = m;
            j++;
        }
        i = j;
    }

    vector<int> t(n + 1), x(n + 1);
    for (int i = 1; i <= n; i++){
        int v = (t[a[i] - 1] >= (i - d)) ? (x[a[i] - 1] + 1) : 1;
        if (t[a[i]] >= (i - d)) v = max(v, x[a[i]]);
        
        int j = a[i] + 1;
        while (j <= m && t[j] < (i - d)) j++;
        while (j <= m && x[j] < v) j++;
        
        for (int t = a[i]; t < j; t++) x[t] = v;

        for (int j = a[i]; j <= m; j++){
            t[j] = i;
        }
    }
    
    cout<<x[m]<<"\n";
}
#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...