답안 #522070

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
522070 2022-02-03T18:04:21 Z Lobo Global Warming (CEOI18_glo) C++17
0 / 100
113 ms 9768 KB
#include<bits/stdc++.h>
using namespace std;

const long long inf = (long long) 1e18 + 10;
const int inf1 = (int) 1e9 + 10;
#define int long long
#define dbl long double
#define endl '\n'
#define sc second
#define fr first
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()

#define maxn 520000

int n, x, bit1[maxn], bit2[maxn], a[maxn], mxv, nx[maxn];

void att1(int pos, int val) {
    for(int i = pos; i <= mxv; i+= i&-i) {
        bit1[pos] = max(bit1[pos],val);
    }
}

int qrr1(int pos) {
    int val = 0;
    for(int i = pos; i > 0; i-= i&-i) {
        val = max(val,bit1[i]);
    }
    return val;
}

void att2(int pos, int val) {
    for(int i = pos; i <= mxv; i+= i&-i) {
        bit2[pos] = max(bit2[pos],val);
    }
}

int qrr2(int pos) {
    int val = 0;
    for(int i = pos; i > 0; i-= i&-i) {
        val = max(val,bit2[i]);
    }
    return val;
}


void solve() {
    cin >> n >> x;
    vector<int> cc;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
        cc.pb(a[i]);
        cc.pb(a[i]+x);
    }

    sort(all(cc));
    cc.erase(unique(all(cc)),cc.end());
    mxv = cc.size();

    for(int i = 1; i <= n; i++) {
        nx[i] = upper_bound(all(cc),a[i]+x) - cc.begin();
        a[i] = upper_bound(all(cc),a[i]) - cc.begin();
    }

    int ans = 0;
    for(int i = 1; i <= n; i++) {
        // cout << i << " " << a[i] << " " << nx[i] << endl;
        //se ja usou
        int ans2 = qrr2(a[i]-1) + 1;
        ans = max(ans, ans2);
        att2(a[i],ans2);

        //nao usou

        int ans3 = qrr1(nx[i]-1) + 1;
        ans = max(ans, ans3);
        att2(a[i],ans3);

        int ans1 = qrr1(a[i]-1) + 1;
        ans = max(ans, ans1);
        att1(a[i],ans1);

    }

    cout << ans << endl;
}

int32_t main() {
    ios::sync_with_stdio(false); cin.tie(0);

    // freopen("in.in", "r", stdin);
    //freopen("out.out", "w", stdout);
    
    int tt = 1;
    // cin >> tt;
    while(tt--) solve();

}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Incorrect 0 ms 332 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Incorrect 0 ms 332 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Incorrect 0 ms 332 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 113 ms 9768 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 30 ms 3516 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 75 ms 5156 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Incorrect 0 ms 332 KB Output isn't correct
3 Halted 0 ms 0 KB -