Submission #754253

#TimeUsernameProblemLanguageResultExecution timeMemory
754253MetalPowerGlobal Warming (CEOI18_glo)C++14
17 / 100
238 ms12636 KiB
#include <bits/stdc++.h> using namespace std; const int MX = 2e5 + 10; const int INF = 1e9 + 7; struct segtree{ int st[MX << 2], lz[MX << 2]; void build(int id, int l, int r){ if(l == r){ st[id] = -INF; lz[id] = 0; }else{ int mid = l + r >> 1; build(id << 1, l, mid); build(id << 1|1, mid + 1, r); st[id] = max(st[id << 1], st[id << 1|1]); } } void prop(int id, int l, int r){ if(lz[id] == 0) return; st[id] += lz[id]; if(l != r){ lz[id << 1] += lz[id]; lz[id << 1|1] += lz[id]; } lz[id] = 0; } void upd_pos(int id, int l, int r, int p, int v){ prop(id, l, r); if(r < p || l > p) return; if(l == p && p == r){ st[id] = v; }else{ int mid = l + r >> 1; upd_pos(id << 1, l, mid, p, v); upd_pos(id << 1|1, mid + 1, r, p, v); st[id] = max(st[id << 1], st[id << 1|1]); } } void upd(int id, int l, int r, int from, int to, int v){ prop(id, l, r); if(r < from || l > to) return; if(from <= l && r <= to){ lz[id] += v; prop(id, l, r); }else{ int mid = l + r >> 1; upd(id << 1, l, mid, from, to, v); upd(id << 1|1, mid + 1, r, from, to, v); st[id] = max(st[id << 1], st[id << 1|1]); } } int que(int id, int l, int r, int from, int to){ prop(id, l, r); if(r < from || l > to) return -INF; if(from <= l && r <= to){ return st[id]; }else{ int mid = l + r >> 1; return max( que(id << 1, l, mid, from, to), que(id << 1|1, mid + 1, r, from, to) ); } } } S, T; void chmax(int& a, int b){ if(b > a) a = b; } vector<int> cc; int N, X, arr[MX], pref[MX], suff[MX]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> N >> X; for(int i = 0; i < N; i++){ cin >> arr[i]; cc.push_back(arr[i]); } cc.push_back(0); sort(cc.begin(), cc.end()); cc.resize(unique(cc.begin(), cc.end()) - cc.begin()); S.build(1, 0, N); S.upd_pos(1, 0, N, 0, 0); for(int i = 0; i < N; i++) arr[i] = lower_bound(cc.begin(), cc.end(), arr[i]) - cc.begin(); for(int i = 0; i < N; i++){ pref[i] = S.que(1, 0, N, 0, arr[i] - 1) + 1; S.upd_pos(1, 0, N, arr[i], pref[i]); if(i > 0) chmax(pref[i], pref[i - 1]); } T.build(1, 1, N + 1); T.upd_pos(1, 1, N + 1, N + 1, 0); for(int i = N - 1; i >= 0; i--){ suff[i] = T.que(1, 1, N + 1, arr[i] + 1, N + 1) + 1; T.upd_pos(1, 1, N + 1, arr[i], suff[i]); if(i < N - 1) chmax(suff[i], suff[i + 1]); } int ans = suff[0]; for(int i = 0; i < N; i++) chmax(ans, pref[i] + suff[i + 1]); cout << ans << '\n'; }

Compilation message (stderr)

glo.cpp: In member function 'void segtree::build(int, int, int)':
glo.cpp:15:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   15 |    int mid = l + r >> 1;
      |              ~~^~~
glo.cpp: In member function 'void segtree::upd_pos(int, int, int, int, int)':
glo.cpp:38:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   38 |    int mid = l + r >> 1;
      |              ~~^~~
glo.cpp: In member function 'void segtree::upd(int, int, int, int, int, int)':
glo.cpp:52:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   52 |    int mid = l + r >> 1;
      |              ~~^~~
glo.cpp: In member function 'int segtree::que(int, int, int, int, int)':
glo.cpp:65:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   65 |    int mid = l + r >> 1;
      |              ~~^~~
#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...