Submission #515715

#TimeUsernameProblemLanguageResultExecution timeMemory
515715MilosMilutinovicGlobal Warming (CEOI18_glo)C++14
38 / 100
2071 ms6288 KiB
#include <bits/stdc++.h> using namespace std; template <typename T> class fenwick { public: vector<T> fenw; int n; fenwick(int _n) : n(_n) { fenw.resize(n); } void modify(int x, T v) { while (x < n) { fenw[x] += v; x |= (x + 1); } } T get(int x) { T v{}; while (x >= 0) { v += fenw[x]; x = (x & (x + 1)) - 1; } return v; } }; struct node { int a = 0; // don't forget to set default value inline void operator += (node &other) { a = max(a, other.a); } }; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, x; cin >> n >> x; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } auto Solve = [&](vector<int> v) { vector<int> cs; for (int i = 0; i < n; i++) { cs.push_back(v[i]); } sort(cs.begin(), cs.end()); cs.erase(unique(cs.begin(), cs.end()), cs.end()); fenwick<node> fenw(n); vector<int> dp(n); for (int i = 0; i < n; i++) { v[i] = lower_bound(cs.begin(), cs.end(), v[i]) - cs.begin(); dp[i] = fenw.get(v[i] - 1).a + 1; fenw.modify(v[i], {dp[i]}); } return *max_element(dp.begin(), dp.end()); }; int ans = Solve(a); if (x == 0) { cout << ans << '\n'; // lol return 0; } for (int i = 0; i < n; i++) { a[n - i - 1] += x; ans = max(ans, Solve(a)); } for (int i = 0; i < n; i++) { a[i] -= x; ans = max(ans, Solve(a)); } cout << ans << '\n'; 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...