제출 #731554

#제출 시각아이디문제언어결과실행 시간메모리
731554hafoGlobal Warming (CEOI18_glo)C++14
100 / 100
164 ms7068 KiB
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define pb push_back
#define pa pair<int, int>
#define pall pair<ll, int>
#define fi first
#define se second
#define TASK "test"
#define all(x) x.begin(), x.end()
using namespace std;

template<typename T1, typename T2> bool mini (T1 &a, T2 b) {if(a > b) a = b; else return 0; return 1;}
template<typename T1, typename T2> bool maxi (T1 &a, T2 b) {if(a < b) a = b; else return 0; return 1;}

const int MOD = 1e9 + 7;
const int LOG = 20;
const int maxn = 2e5 + 7;
const ll oo = 1e17 + 69;

int n, x, a[maxn], dp[maxn];

struct BIT {
    int bit[2 * maxn];

    void init() {
        fill_n(bit, 2 * n + 1, 0);
    }

    void update(int x, int val) {
        for(; x <= 2 * n; x += x&-x) maxi(bit[x], val);
    }

    int get(int x) {
        int ans = 0;
        for(; x; x-= x&-x) maxi(ans, bit[x]);
        return ans;
    }
} bit;

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

    //freopen(TASK".inp", "r", stdin);
    //freopen(TASK".out", "w", stdout);

    cin>>n>>x;
    vector<int> val;
    for(int i = 1; i <= n; i++) {
        cin>>a[i];
        val.pb(a[i]);
        val.pb(a[i] - x);
    }
    sort(all(val));
    dp[0] = 1;
    int ans = 0;
    for(int i = 1; i <= n; i++) {
        int id = lower_bound(all(val), a[i]) - val.begin() + 1;
        dp[i] = bit.get(id - 1) + 1;
        bit.update(id, dp[i]);
        maxi(ans, dp[i]);
    }

    bit.init();
    for(int i = n; i >= 1; i--) {
        int id = lower_bound(all(val), a[i] - x) - val.begin() + 1;
        maxi(ans, dp[i] + bit.get(2 * n - id));

        id = lower_bound(all(val), a[i]) - val.begin() + 1;
        int cur = bit.get(2 * n - id) + 1;
        bit.update(2 * n - id + 1, cur);
    }
    cout<<ans;
    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...
#Verdict Execution timeMemoryGrader output
Fetching results...