제출 #396782

#제출 시각아이디문제언어결과실행 시간메모리
396782abdzagGlobal Warming (CEOI18_glo)C++17
0 / 100
775 ms36692 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; 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[v[i]]); tree.update(maping[v[i]],lis[i]); } MaxTree tree2(2*n+1); rep(i, 0, n-1) { tree2.update(maping[v[n-1-i]], 1+tree2.query(0,maping[v[n-1-i]])); ans = max(ans,lis[n-2-i] + tree2.query(maping[v2[n-2-i]]+1, 2*n+1)); } cout << ans << endl; return 0; }

컴파일 시 표준 에러 (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...