Submission #1125785

#TimeUsernameProblemLanguageResultExecution timeMemory
1125785vladiliusGlobal Warming (CEOI18_glo)C++20
0 / 100
2094 ms8752 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; #define pb push_back #define ff first #define ss second struct ST{ vector<int> t; int n; ST(int ns){ n = ns; t.resize(4 * n); } void upd(int v, int tl, int tr, int& p, int& x){ if (tl == tr){ t[v] = max(t[v], x); return; } int tm = (tl + tr) / 2, vv = 2 * v; if (p <= tm){ upd(vv, tl, tm, p, x); } else { upd(vv + 1, tm + 1, tr, p, x); } t[v] = max(t[vv], t[vv + 1]); } void upd(int p, int x){ upd(1, 1, n, p, x); } int get(int v, int tl, int tr, int& p){ if (tl > p) return 0; if (tr <= p){ return t[v]; } int tm = (tl + tr) / 2, vv = 2 * v; return max(get(vv, tl, tm, vv), get(vv + 1, tm + 1, tr, p)); } int get(int p){ if (!p) return 0; return get(1, 1, n, p); } }; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, x; cin>>n>>x; vector<int> a(n + 1); for (int i = 1; i <= n; i++){ cin>>a[i]; } auto lis = [&](vector<int> x){ vector<pii> all; for (int i = 1; i <= n; i++){ all.pb({x[i], i}); } sort(all.begin(), all.end()); int i = 0, cc = 1; while (i < n){ int j = i; while (j < n && all[i] == all[j]){ x[all[j].ss] = cc; j++; } i = j; cc++; } ST T(n); vector<int> dp(n + 1); int ret = 0; for (int i = 1; i <= n; i++){ dp[i] = 1 + T.get(x[i] - 1); ret = max(ret, dp[i]); T.upd(x[i], dp[i]); } return ret; }; int out = lis(a); for (int l = 1; l <= n; l++){ for (int r = l; r <= n; r++){ a[r] += x; out = max(out, lis(a)); } for (int r = l; r <= n; r++){ a[r] -= x; } for (int r = l; r <= n; r++){ a[r] -= x; out = max(out, lis(a)); } for (int r = l; r <= n; r++){ a[r] += x; } } cout<<out<<"\n"; }
#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...