제출 #811462

#제출 시각아이디문제언어결과실행 시간메모리
811462vjudge1Financial Report (JOI21_financial)C++14
5 / 100
527 ms32100 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, a[N + 1], dp[N + 1], mx[2 * N + 1] ; set<int> s ; map<int, int> mp ; 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)) ; } 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] ; s.insert(a[i]) ; } if(n <= 7000) { int ans = 0 ; a[0] = -1 ; for(int i = 1 ; i <= n ; i++) { int mx = 0 ; for(int j = max(0, i - d) ; j < i ; j++) if(a[j] < a[i]) mx = max(mx, dp[j]) ; dp[i] = mx + 1 ; ans = max(ans, dp[i]) ; } cout << ans << '\n' ; return 0 ; } if(d == n) { int ans = 0 ; for(int i : s) { cnt++ ; mp[i] = cnt ; } for(int i = 1 ; i <= n ; i++) { a[i] = mp[a[i]] ; int 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...