Submission #1105638

#TimeUsernameProblemLanguageResultExecution timeMemory
1105638SamNguyenArcade (NOI20_arcade)C++14
100 / 100
266 ms37556 KiB
#include <bits/stdc++.h> using namespace std; template <int N> class BIT { private: int n, bit[N]; public: void init(int _n) { n = _n; fill(bit, bit + n + 1, 0); } inline void update(int i, int v) { for (; i <= n; i += i & -i) bit[i] = max(bit[i], v); } inline int get(int i) { int res = 0; for (; i > 0; i -= i & -i) res = max(res, bit[i]); return res; } }; const int MAX = 5e5 + 7; int D, N, T[MAX], A[MAX]; pair<int, int> coord[MAX]; vector<int> ys_by_x[MAX]; void input() { cin >> D >> N; for (int i = 1; i <= N; i++) cin >> T[i]; for (int i = 1; i <= N; i++) cin >> A[i]; vector<int> Xs, Ys; for (int i = 1; i <= N; i++) { int x = T[i] - A[i], y = T[i] + A[i]; Xs.push_back(x); Ys.push_back(y); coord[i] = make_pair(x, y); // cerr << "(" << x << ", " << y << ")" << endl; } sort(Xs.begin(), Xs.end()); sort(Ys.begin(), Ys.end()); Xs.resize(unique(Xs.begin(), Xs.end()) - Xs.begin()); Ys.resize(unique(Ys.begin(), Ys.end()) - Ys.begin()); for (int i = 1; i <= N; i++) { int x, y; tie(x, y) = coord[i]; x = lower_bound(Xs.begin(), Xs.end(), x) - Xs.begin() + 1; y = lower_bound(Ys.begin(), Ys.end(), y) - Ys.begin() + 1; // cerr << "[" << x << ", " << y << "]" << endl; coord[i] = make_pair(x, y); ys_by_x[x].push_back(y); } } // min chain = max path BIT<MAX> bit; void solve() { bit.init(N); for (int x = N; x >= 1; x--) { /* cerr << "x = " << setw(3) << x << " => "; for (int y : ys_by_x[x]) cerr << setw(3) << y; cerr << endl; */ vector<int> new_vals; for (int y : ys_by_x[x]) new_vals.push_back(bit.get(y - 1) + 1); auto it = new_vals.begin(); for (int y : ys_by_x[x]) bit.update(y, *(it++)); // cerr << " ==> " << bit.get(N) << endl; } int ans = bit.get(N); cout << ans; } int main(void) { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); input(); 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...