Submission #1313264

#TimeUsernameProblemLanguageResultExecution timeMemory
1313264huoiGlobal Warming (CEOI18_glo)C++17
100 / 100
126 ms28616 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define INF struct FenwickTree { int n; vector<int> t; FenwickTree(int n) : n(n), t(n) {} int lsb(int x) { return x & -x; } void update(int p, int x) { while (p <= n) { t[p] = max(t[p], x); p += lsb(p); } } int query(int p) { int ans = 0; while (p > 0) { ans = max(ans, t[p]); p -= lsb(p); } return ans; } }; void solve() { int n, x; cin >> n >> x; vector<int> t(n), a; for (int i = 0; i < n; i++) { cin >> t[i]; a.push_back(t[i]); a.push_back(t[i] - x); } sort(a.begin(), a.end()); a.erase(unique(a.begin(), a.end()), a.end()); vector<pair<int, int>> v(n); for (int i = 0; i < n; i++) { v[i].first = lower_bound(a.begin(), a.end(), t[i]) - a.begin() + 1; v[i].second = lower_bound(a.begin(), a.end(), t[i] - x) - a.begin() + 1; } int ans = 1; vector<vector<int>> dp(n, vector<int>(2, 1)); vector<FenwickTree> ft(2, FenwickTree(2 * n + 1)); for (int i = 0; i < n; i++) { dp[i][0] = max(ft[0].query(v[i].first - 1), ft[1].query(v[i].first - 1)) + 1; dp[i][1] = ft[1].query(v[i].second - 1) + 1; ft[0].update(v[i].first, dp[i][0]); ft[1].update(v[i].second, dp[i][1]); ans = max(ans, max(dp[i][0], dp[i][1])); } cout << ans; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); 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...