Submission #666755

#TimeUsernameProblemLanguageResultExecution timeMemory
666755I_love_Chou_GiangGlobal Warming (CEOI18_glo)C++14
100 / 100
72 ms4280 KiB
#include <algorithm> #include <bits/stdc++.h> using namespace std; typedef long long ll; #define vt vector #define pb push_back #define all(x) (x).begin(), (x).end() #define sz(x) (int)(x).size() #define R_EP(i, a, b, s) for (int i = (a); (s) > 0 ? i < (b) : i > (b); i += (s)) #define R_EP1(e) R_EP(i, 0, e, 1) #define R_EP2(i, e) R_EP(i, 0, e, 1) #define R_EP3(i, b, e) R_EP(i, b, e, 1) #define R_EP4(i, b, e, s) R_EP(i, b, e, s) #define GET5(a, b, c, d, e, ...) e #define R_EPC(...) GET5(__VA_ARGS__, R_EP4, R_EP3, R_EP2, R_EP1) #define rep(...) R_EPC(__VA_ARGS__)(__VA_ARGS__) #define trav(x, a) for (auto x : a) template<typename T> inline bool umax(T&x, const T& y) { if (x >= y) return false; x = y; return true; } template<typename T> inline bool umin(T&x, const T& y) { if (x <= y) return false; x = y; return true; } const int MOD = int(1e9) + 7, naxm = 200000; int n, x, a[naxm + 5]; namespace Sub2 { void tst() { int ans = 0; rep(i, 1, n + 1) { rep(j, i, n + 1) { rep(t, -x, x + 1) { vt<int> dp; rep(k, 1, n + 1) { int v = a[k] + (k >= i && k <= j ? t : 0); int l = lower_bound(all(dp), v) - dp.begin(); if (l < sz(dp)) dp[l] = v; else dp.pb(v); } umax(ans, sz(dp)); } } } cout << ans << "\n"; } }; namespace Sub3 { void tst() { int ans = 0; rep(i, 1, n + 1) { vt<int> dp; rep(j, 1, n + 1) { int v = a[j] + (j <= i ? -x : 0); int l = lower_bound(all(dp), v) - dp.begin(); if (l < sz(dp)) dp[l] = v; else dp.pb(v); } umax(ans, sz(dp)); } cout << ans << "\n"; } }; namespace Sub4 { void tst() { vt<int> dp; rep(i, 1, n + 1) { int l = lower_bound(all(dp), a[i]) - dp.begin(); if (l < sz(dp)) dp[l] = a[i]; else dp.pb(a[i]); } cout << sz(dp) << "\n"; } }; namespace Sub7 { const int naxm = 200000; int LIS_prefix[naxm + 5]; void tst() { int ans = 0; vt<int> dp; rep(i, 1, n + 1) { int l = lower_bound(all(dp), a[i]) - dp.begin(); LIS_prefix[i] = l + 1; if (l < sz(dp)) dp[l] = a[i]; else dp.pb(a[i]); } ans = sz(dp); dp.clear(); rep(i, n, 0, -1) { int l = lower_bound(all(dp), -a[i] + x) - dp.begin(); umax(ans, LIS_prefix[i] + l); l = lower_bound(all(dp), -a[i]) - dp.begin(); if (l < sz(dp)) dp[l] = -a[i]; else dp.pb(-a[i]); } cout << ans << "\n"; } }; int main() { ios_base::sync_with_stdio(false), cin.tie(nullptr); cin >> n >> x; rep(i, 1, n + 1) cin >> a[i]; if (max(n, x) <= 50) Sub2::tst(); else if (n <= 1000) Sub3::tst(); else if (!x) Sub4::tst(); else Sub7::tst(); 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...