Submission #836256

#TimeUsernameProblemLanguageResultExecution timeMemory
836256Sohsoh84Global Warming (CEOI18_glo)C++17
0 / 100
70 ms9332 KiB
// Wounds should become scars but I'm cracked instead U+1FAE0 #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> pll; #define all(x) (x).begin(),(x).end() #define X first #define Y second #define sep ' ' #define endl '\n' #define debug(x) cerr << #x << ": " << x << endl; const ll MAXN = 1e6 + 10; int pre_dp[MAXN], suff_dp[MAXN], n, fen[MAXN], A[MAXN]; vector<int> comp_vec; inline void update(int ind, int val) { for (++ind; ind < MAXN; ind += ind & -ind) fen[ind] = max(fen[ind], val); } inline int query(int ind) { int ans = 0; for (++ind; ind > 0; ind -= ind & -ind) ans = max(ans, fen[ind]); return ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; for (int i = 1; i <= n; i++) { cin >> A[i]; comp_vec.push_back(A[i]); } sort(all(comp_vec)); for (int i = 1; i <= n; i++) A[i] = lower_bound(all(comp_vec), A[i]) - comp_vec.begin() + 1; for (int i = 1; i <= n; i++) { pre_dp[i] = query(A[i] - 1) + 1; update(A[i], pre_dp[i]); pre_dp[i] = max(pre_dp[i], pre_dp[i - 1]); } memset(fen, 0, sizeof fen); for (int i = n; i > 0; i--) { suff_dp[i] = query(n - A[i] - 1) + 1; update(n - A[i], suff_dp[i]); suff_dp[i] = max(suff_dp[i], suff_dp[i + 1]); } int ans = pre_dp[n]; for (int i = 1; i < n; i++) ans = max(ans, pre_dp[i] + suff_dp[i + 1]); cout << ans << endl; 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...