제출 #813462

#제출 시각아이디문제언어결과실행 시간메모리
813462ZHIRDILBILDIZFinancial Report (JOI21_financial)C++14
0 / 100
196 ms23352 KiB
#include<bits/stdc++.h> #define fi first #define se second #define ll long long using namespace std ; const int N = (1 << 19) ; int n, d, cnt, ans, dp[N + 1], p[N + 1], kol[N + 1], mn[N + 1], mx[N + 1] ; pair<int, int> a[N + 1] ; int get(int a) { while(a != p[a]) a = p[a] ; return a ; } void join(int a, int b) { a = get(a) ; b = get(b) ; if(a == b) return ; if(kol[a] > kol[b]) swap(a, b) ; mn[b] = min(mn[a], mn[b]) ; kol[b] += kol[a] ; kol[a] = 0 ; p[a] = b ; } int get_min(int a) { a = get(a) ; return mn[a] ; } void update(int l, int r, int ind, int num, int v) { if(l > ind || r < ind) return ; if(l == r) { mx[v] = num ; return ; } int 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]) ; } int get_max(int l, int r, int l1, int r1, int v) { if(l > r1 || r < l1) return 0 ; if(l1 <= l && r <= r1) return mx[v] ; int mid = (l + r) >> 1 ; return max(get_max(l, mid, l1, r1, v * 2), get_max(mid + 1, r, l1, r1, v * 2 + 1)) ; } bool cmp(pair<int, int> p1, pair<int, int> p2) { if(p1.fi != p2.fi) return p1.fi < p2.fi ; else return p1.se > p2.se ; } signed main() { ios_base::sync_with_stdio( 0 ) ; cin.tie( 0 ) ; cout.tie( 0 ) ; cin >> n >> d ; for(int i = 1 ; i <= n ; i++) { cin >> a[i].fi ; p[i] = i ; mn[i] = i ; kol[i] = 1 ; a[i].se = i ; } sort(a + 1, a + n + 1, cmp) ; for(int i = 1 ; i <= n ; i++) { cnt++ ; a[i].fi = cnt ; } set<int> all ; for(int i = 1 ; i <= n ; i++) { auto it = all.lower_bound(a[i].se) ; if(it != all.end() && *it - d <= i) join(*it, a[i].se) ; if(it != all.begin() && *--it + d >= i) join(*it, a[i].se) ; int num = get_max(1, N, get_min(a[i].se), a[i].se, 1) ; dp[a[i].se] = num + 1 ; update(1, N, a[i].se, num + 1, 1) ; ans = max(ans, dp[a[i].se]) ; all.insert(a[i].se) ; } cout << ans ; return 0 ; } //8 8 //4 5 1 3 6 2 7 10
#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...