Submission #607504

#TimeUsernameProblemLanguageResultExecution timeMemory
607504PietraGlobal Warming (CEOI18_glo)C++14
5 / 100
2077 ms139496 KiB
#include<bits/stdc++.h> #define ll long long using namespace std ; const ll maxn = 2e5 + 5 ; const ll inf = 1e15 + 1 ; ll n, x ; ll v[maxn] ; map<ll,ll> bit ; struct BIT{ void upd(ll pos, ll val){ if(pos <= 0) return ; for(; pos < 4*inf ; pos += pos&-pos) bit[pos] = max(bit[pos], val) ; } ll query(ll pos){ if(pos <= 0) return 0 ; ll tot = 0 ; for(; pos > 0 ; pos -= pos&-pos) tot = max(tot, bit[pos]) ; return tot ; } } Bit ; void solve_1(){ ll val = 0 ; for(ll i = 1 ; i <= n ; i++){ ll mx = Bit.query(v[i] - 1) ; Bit.upd(v[i], mx + 1) ; val = max(val, v[i]) ; } ll ans = Bit.query(val+1) ; cout << ans << "\n" ; } ll try_val(ll l, ll r, ll val){ // cout << l << " " << r << " " << val << "\n" ; bit.clear() ; for(ll i = l ; i <= r ; i++) v[i] += val ; ll va = 0 ; for(ll i = 1 ; i <= n ; i++){ ll mx = Bit.query(v[i] - 1) ; Bit.upd(v[i], mx + 1) ; va = max(va, v[i]) ; } ll ans = Bit.query(va+1) ; for(ll i = l ; i <= r ; i++) v[i] -= val ; return ans ; } void solve_2(){ ll ans = try_val(1, n, 0) ; for(ll i = 1 ; i <= x ; i++){ // add for(ll l = 1 ; l <= n ; l++){ for(ll r = l ; r <= n ; r++){ ans = max(ans, try_val(l, r, i)) ; ans = max(ans, try_val(l, r, -i)) ; } } } cout << ans << "\n" ; } int main(){ ios_base::sync_with_stdio(false) ; cin.tie(NULL) ; cin >> n >> x ; for(ll i = 1 ; i <= n ; i++){ cin >> v[i] ; v[i] += (x + 1) ; } if(x == 0) solve_1() ; else solve_2() ; }
#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...