Submission #938152

#TimeUsernameProblemLanguageResultExecution timeMemory
938152WhisperGlobal Warming (CEOI18_glo)C++17
0 / 100
2 ms860 KiB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using str = string;
using ld = long double;
using T = tuple<ll, ll, ll>;

#define int long long
#define Base 31
#define sz(a) (int)a.size()
#define FOR(i, a, b) for ( int i = a ; i <= b ; i++ )
#define FORD(i, a, b) for (int i = a; i >= b; i --)
#define REP(i, n) for ( int i = 0 ; i < n ; ++i )
#define REPD(i, n) for ( int i =  n - 1 ; ~(--i) ; )
#define all(x) x.begin() , x.end()
#define pii pair<int , int>
#define fi first
#define se second
#define Lg(x) 31 - __builtin_clz(x)

constexpr ll LINF = (1ll << 62);
constexpr int INF = (1ll << 30);
constexpr int MAX = 2e3 + 5;
constexpr int Mod = 1e9 + 7;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void setupIO(){
    #define name "Whisper"
    //Phu Trong from Nguyen Tat Thanh High School for gifted student
    srand(time(NULL));
    cin.tie(nullptr)->sync_with_stdio(false); cout.tie(nullptr);
    // freopen(name".inp", "r", stdin);
    // freopen(name".out", "w", stdout);
    cout << fixed << setprecision(10);
}
pii a[MAX];
int n, d;

struct FenwickTree{
    int n;
    vector<int> f;
    FenwickTree(int _n){
        this -> n = _n;
        f.resize(n + 5, 0);
    }

    void modify(int x, int val){
        for ( ; x < n; x += x & (-x)) f[x] = max(val, f[x]);
    }
    int query(int x){
        int res = 0;
        for ( ; x; x -= x & (-x)) res = max(res, f[x]);
        return res;
    }
};

int f[MAX];

void Whisper(){ 
    cin >> n >> d;
    vector<int> cur;
    FOR(i, 1, n){
        int x; cin >> x;
        a[i] = {x - d, x + d};
        cur.push_back(x - d);
        cur.push_back(x + d);
    }
    sort(all(cur));
    cur.resize(unique(all(cur)) - cur.begin());
    for (int i = 1 ; i <= n ; i++){
        a[i].fi = lower_bound(all(cur), a[i].fi) - cur.begin() + 1;
        a[i].se = lower_bound(all(cur), a[i].se) - cur.begin() + 1;
    }
    FenwickTree fen(MAX);

    int ans = 0;
    for (int i = 1 ; i <= n ; i++){
        for (int j = a[i].se ; j >= a[i].fi ; j--){
            f[j] = fen.query(j) + 1;
            fen.modify(j, f[j]);
        } 
    }

    for (int i = 1 ; i < MAX ; i++) ans = max(ans, f[i]);
    cout << ans;
}       

signed main(){  
    setupIO();
    int Test = 1;
    // cin >> Test;
    for ( int i = 1 ; i <= Test ; i++ ){
        Whisper();
        if (i < Test) cout << '\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...
#Verdict Execution timeMemoryGrader output
Fetching results...