Submission #754374

#TimeUsernameProblemLanguageResultExecution timeMemory
754374phongcdGlobal Warming (CEOI18_glo)C++17
27 / 100
130 ms5424 KiB
#include <bits/stdc++.h> #define ll long long #define ii pair <int, int> #define ill pair <ll, ll> #define fi first #define se second #define all(x) x.begin(), x.end() #define file "test" using namespace std; const int N = 4e5 + 2; const int MOD = 1e9 + 7; const ll INF = 1e18; const int base = 311; const int BLOCK_SIZE = 2000; int n, x; struct tree { int bit[N] = {0}; void upd(int idx, int v) { for (; idx <= 2 * n; idx += idx & -idx) bit[idx] = max(bit[idx], v); } int get(int idx) { int ans = 0; for (; idx > 0; idx -= idx & -idx) ans = max(ans, bit[idx]); return ans; } } bit0, bit1; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> x; vector <int> a(n), b; for (int i = 0; i < n; i ++) { cin >> a[i]; b.push_back(a[i]); b.push_back(a[i] + x); } sort(all(b)); b.erase(unique(all(b)), b.end()); for (int i = 0; i < n; i ++) { a[i] = lower_bound(all(b), a[i]) - b.begin() + 1; int ac = lower_bound(all(b), a[i] + x) - b.begin() + 1; int res = bit0.get(a[i] - 1) + 1; int res2 = max(bit0.get(ac - 1), bit1.get(a[i] - 1)) + 1; bit0.upd(a[i], res); bit1.upd(a[i], res2); } cout << bit1.get(2 * n); } /* /\_/\ zzZ (= -_-) / >u >u */
#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...