제출 #1171164

#제출 시각아이디문제언어결과실행 시간메모리
1171164arkanefuryGlobal Warming (CEOI18_glo)C++20
0 / 100
109 ms22868 KiB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define in insert
#define lb lower_bound
#define F first
#define S second
#define sz size()
#define all(v) v.begin(),v.end()
#define FOR1(x, n) for(int j = x; j <= n; j ++)
#define FOR(x, n, m, d) for(int x = n; x <= m; x += d)
#define FORR(x, n, m, d) for(int x = n; x >= m; x -= d)
#define nikita ios_base::sync_with_stdio(0), cin.tie(0);
const int N =  3e5+5;
int a[N], b[N], pref[N], dp[N], c[N], timer = 1;
int n,m,k,sum=0,x,y, ans, r, cnt, l, mod = 1e9+7;
string s, str;
struct tt{
    int val, l, r;
}t[N*6];
void upd(int pos, int val, int v = 1, int tl = 1, int tr = 1e9){
    if(tl == tr){
        t[v].val = max( t[v].val, val );
        return;
    }
    int tm = (tl + tr) >> 1;
    if(pos <= tm){
        if(!t[v].l)t[v].l = ++timer;
        upd(pos, val, t[v].l, tl, tm);
    }
    else{
        if(!t[v].r)t[v].r = ++timer;
        upd(pos, val, t[v].r, tm+1, tr);
    }
    t[v].val = max(t[t[v].l].val, t[t[v].r].val);
}
int get(int r, int v = 1, int tl = 1, int tr = 1e9){
    if(tr <= r){
        return t[v].val;
    }
    if(tl > r)return 0;
    int tm = (tl + tr) >> 1;
    int x = y = 0;
    if(t[v].l)x = get(r, t[v].l, tl, tm);
    if(t[v].r)y = get(r, t[v].r, tm+1, tr);
    return max(x, y);
}
void solve(){
    cin >> n >> m;
    FOR(i, 1, n, 1){
        cin >> a[i];
    }
    upd(a[1], 1);
    ans = 1;
    FOR(i, 2, n, 1){
        dp[i] = get(min((int)1e9, a[i] + m));
        ans = max( ans, dp[i] + 1 );
        x = get(a[i]) + 1;
        upd(a[i], x);
    }
    cout << ans;
}
signed main(){
    nikita
    int tt = 1;
    if(!tt)cin >> tt;
    FOR(i, 1, tt, 1)solve();
}
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...