Submission #396774

#TimeUsernameProblemLanguageResultExecution timeMemory
396774abdzagGlobal Warming (CEOI18_glo)C++17
0 / 100
642 ms21492 KiB
#include<bits/stdc++.h> #define rep(i,a,b) for(int i=int(a);i<int(b);i++) #define rrep(i,a,b) for(int i=int(a);i>int(b); i--); #define all(v) v.begin(),v.end() #define trav(a,v) for(auto&a:v) using namespace std; const long long inf = 1e15; typedef long long ll; struct MaxTree { typedef ll T; static constexpr T unit =0; vector<T> s; T f(T a, T b) { return max(a, b); } ll n; MaxTree(ll n=0) : n(n), s(2*n,unit){} void update(ll pos, T val) { for (s[pos += n] = val; pos /= 2;) { s[pos] = f(s[2 * pos], s[2 * pos + 1]); } } T query(ll l, ll r) { T a = unit, b = unit; for (l += n, r += n; l < r; l /= 2, r /= 2) { if (l % 2)a = f(a, s[l++]); if (r % 2) b = f(b, s[--r]); } return f(a, b); } }; int main(){ cin.sync_with_stdio(false); ll n,x; cin >> n >> x; vector<ll> v(n); rep(i, 0, n) cin >> v[i]; ll ans = 0; vector<ll> sorted = v; sort(all(sorted)); map<ll, ll> maping; rep(i, 0, n)maping[sorted[i]] = i; vector<ll> lis(n); MaxTree tree(n); rep(i, 0, n) { lis[i] = 1 + tree.query(0, maping[v[i]]); tree.update(maping[v[i]],lis[i]); } trav(a, lis)ans = max(a, ans); rep(i, 0, n) { tree.update(maping[v[i]], 0); ans = max(ans,lis[i] + tree.query(maping[v[i]], n)); } cout << ans << endl; return 0; }

Compilation message (stderr)

glo.cpp: In constructor 'MaxTree::MaxTree(ll)':
glo.cpp:20:5: warning: 'MaxTree::n' will be initialized after [-Wreorder]
   20 |  ll n;
      |     ^
glo.cpp:16:12: warning:   'std::vector<long long int> MaxTree::s' [-Wreorder]
   16 |  vector<T> s;
      |            ^
glo.cpp:21:2: warning:   when initialized here [-Wreorder]
   21 |  MaxTree(ll n=0) : n(n), s(2*n,unit){}
      |  ^~~~~~~
#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...