Submission #396809

#TimeUsernameProblemLanguageResultExecution timeMemory
396809abdzagGlobal Warming (CEOI18_glo)C++17
0 / 100
935 ms61720 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); } T getVal(ll pos) { return s[pos + n]; } }; int main(){ cin.sync_with_stdio(false); ll n,x; cin >> n >> x; vector<vector<ll>> before(2 * n + 1); vector<ll> v(n); rep(i, 0, n) cin >> v[i]; ll ans = 0; rep(i, 0, n)v.push_back(v[i] - x); vector<ll> sorted = v; sort(all(sorted)); map<ll,ll> maping; rep(i, 0, 2*n)maping[sorted[i]] = i; vector<ll> lis(n); MaxTree tree(2*n+1); vector<ll> v2; rep(i, n, 2 * n) v2.push_back(v[i]); rep(i, 0, n) { lis[i] = 1 + tree.query(0, maping[v2[i]]); if (tree.getVal(i)) before[maping[v2[i]]].push_back(tree.getVal(i)); tree.update(maping[v2[i]],lis[i]); } MaxTree tree2(2*n+1); vector<ll> lis2(n); rep(i, 0, n-1) { ll curval = 1 + tree2.query(maping[v[n - 1 - i]]+1,2*n+1); lis2[i] = curval; tree2.update(maping[v[n-1-i]], curval); if(before[maping[v2[n - 1 - i]]].empty())tree.update(maping[v2[n - 1 - i]], 0); else { tree.update(maping[v2[n - 1 - i]], before[maping[v2[n - 1 - i]]].back()); before[maping[v2[n - 1 - i]]].pop_back(); } ans = max(ans,curval+tree.query(0, maping[v[n - 1 - i]-1]+1)); } 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...