Submission #1345502

#TimeUsernameProblemLanguageResultExecution timeMemory
1345502chithanhnguyenArcade (NOI20_arcade)C++20
100 / 100
151 ms10156 KiB
/*
Author: Nguyen Chi Thanh - High School for the Gifted - VNU.HCM (i2528)
*/
#include <bits/stdc++.h>
using namespace std;

/* START OF TEMPALTE */

// #define int long long
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fi first
#define se second
#define __builtin_popcount __builtin_popcountll
#define all(x) (x).begin(), (x).end()
#define BIT(x, i) (((x) >> (i)) & 1)
#define MASK(x) (1ll << (x))
#define SZ(a) ((int32_t)a.size())

#define debug(a, l, r) {for (int _i = (l); _i <= (r); ++_i) cout << (a)[_i] << ' '; cout << '\n';}

template<class X, class Y>
bool minimize(X &x, const Y &y) {
    if (x > y) {
        x = y;
        return true;
    } else return false;
}

template<class X, class Y>
bool maximize(X &x, const Y &y) {
    if (x < y) {
        x = y;
        return true;
    } else return false;
}

/* END OF TEMPALTE */

const int MAXN = 5e5 + 5;
int n, m, a[MAXN], dp[MAXN];
pii info[MAXN];

struct Normalize{
    vector<int> vals;

    void add(int x) {
        vals.push_back(x);
    }

    void build() {
        sort(all(vals));
        vals.erase(unique(all(vals)), end(vals));
    }

    int get(int x) {
        return (int)(lower_bound(all(vals), x) - begin(vals)) + 1;
    }
};

struct FenwickTree {
    int n;
    vector<int> fen;

    FenwickTree() {

    }

    void init(int _n) {
        n = _n;
        fen.resize(n + 5, 0);
    }

    void update(int idx, int v) {
        for (int i = idx; i <= n; i += i & -i)
            maximize(fen[i], v);
    }

    int get(int idx) {
        int res = 0;
        for (int i = idx; i; i -= i & -i)
            maximize(res, fen[i]);
        return res;
    }
};

void init() {
    cin >> n >> m;
    for (int i = 1; i <= m; ++i) cin >> info[i].fi;
    for (int i = 1; i <= m; ++i) cin >> info[i].se;
    for (int i = 1; i <= m; ++i)
        info[i] = {info[i].fi + info[i].se, info[i].fi - info[i].se};
    sort(info + 1, info + m + 1);
    
    Normalize norm;
    for (int i = 1; i <= m; ++i)
        norm.add(-info[i].se);
    norm.build();

    for (int i = 1; i <= m; ++i)
        a[i] = norm.get(-info[i].se);
}

void solve() {
    FenwickTree fen;
    fen.init(m);

    for (int i = 1; i <= m; ++i) {
        dp[i] = 1 + fen.get(a[i] - 1);
        fen.update(a[i], dp[i]);
    }

    cout << *max_element(dp + 1, dp + m + 1);
}

signed main() {
    #ifdef NCTHANH
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr); cout.tie(nullptr);

    init();
    solve();

    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...