Submission #811982

#TimeUsernameProblemLanguageResultExecution timeMemory
811982vjudge1Financial Report (JOI21_financial)C++14
31 / 100
1426 ms42632 KiB
#include<bits/stdc++.h> #define fi first #define se second #define ll long long using namespace std ; const ll N = (1 << 19) ; ll n, d, cnt, a[N + 1], dp[N + 1], mx[2 * N + 1] ; set<ll> s ; map<ll, ll> mp ; void update(ll l, ll r, ll ind, ll num, ll v) { if(l > ind || r < ind) return ; if(l == r) { mx[v] = num ; return ; } ll mid = (l + r) >> 1 ; update(l, mid, ind, num, v * 2) ; update(mid + 1, r, ind, num, v * 2 + 1) ; mx[v] = max(mx[v * 2], mx[v * 2 + 1]) ; } ll get_max(ll l, ll r,ll l1, ll r1, ll v) { if(l > r1 || r < l1) return 0 ; if(l1 <= l && r <= r1) return mx[v] ; ll mid = (l + r) >> 1 ; return max(get_max(l, mid, l1, r1, v * 2), get_max(mid + 1, r, l1, r1, v * 2 + 1)) ; } signed main() { ios_base::sync_with_stdio( 0 ) ; cin.tie( 0 ) ; cout.tie( 0 ) ; cin >> n >> d ; for(ll i = 1 ; i <= n ; i++) { cin >> a[i] ; s.insert(a[i]) ; } for(ll i : s) { cnt++ ; mp[i] = cnt ; } for(ll i = 1 ; i <= n ; i++) a[i] = mp[a[i]] ; if(n <= 7000) { ll ans = 0 ; for(ll i = n ; i >= 1 ; i--) { ll mx = 0, ls = i, now = a[i] ; pair<ll, ll> mn = {1e9, 1e9} ; for(ll j = i + 1 ; j <= n ; j++) { if((j - ls) == d + 1) { ls = mn.se ; now = max(now, mn.fi) ; mn = {1e9, 1e9} ; } mn = min(mn, {a[j], j}) ; if(a[j] > now) mx = max(mx, dp[j]) ; } dp[i] = mx + 1 ; ans = max(ans, dp[i]) ; } cout << ans ; return 0 ; } if(n <= 20) { ll ans = 0 ; for(ll i = 0 ; i < (1 << n) ; i++) { ll now = 0, mx = -1, ls = 1e9 ; for(ll j = 0 ; j < n ; j++) if(j - ls <= d && ((1 << j) & i)) { ls = j ; if(mx < a[j + 1]) now++ ; mx = max(mx, a[j + 1]) ; } ans = max(ans, now) ; } cout << ans ; return 0 ; } if(d == 1) { ll ans = 0 ; for(ll i = 1 ; i <= n ; i++) update(1, N, i, a[i], 1) ; for(ll i = n ; i >= 1 ; i--) { ll l = i, r = n + 1 ; while(l + 1 < r) { ll mid = (l + r) >> 1 ; if(get_max(1, N, i, mid, 1) > a[i]) r = mid ; else l = mid ; } dp[i] = dp[r] + 1 ; ans = max(ans, dp[i]) ; } cout << ans ; return 0 ; } if(d == n) { ll ans = 0 ; for(ll i = 1 ; i <= n ; i++) { ll num = get_max(1, N, 1, a[i] - 1, 1) ; ans = max(ans, num + 1) ; update(1, N, a[i], num + 1, 1) ; } cout << ans ; return 0 ; } return 0 ; }
#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...