제출 #864192

#제출 시각아이디문제언어결과실행 시간메모리
864192vjudge1Financial Report (JOI21_financial)C++17
65 / 100
1621 ms408284 KiB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<long long, long long> pll;
typedef pair<int,int> pii;
typedef vector<long long> vl;
typedef vector<int> vi;
int n, d;
vi arr;
const int INF = 2e9;
int cnt[300010], can_jump[7100][7100], idx[300100], bit[300100];
void update(int node){
	while(node <= n){
		bit[node]++;
		node+=node&-node;
	}return;
}
int query(int node){
	int ret =0 ;
	while(node){
		ret += bit[node];
		node-=node&-node;
	}
	return ret;
}
int main(){
	cin>>n>>d;
	for(int i = 1; i <= n; i++){
		cin>>cnt[i];
		arr.pb(cnt[i]);
	}
	if(d == n){
		vi niza(n);
		for(int i = 1; i <= n; i++)
			niza[i-1] = cnt[i];
		vi d(n+1, INF);
		d[0] = -INF;
		for(int i = 0; i < n; i++){
			int l = upper_bound(d.begin(), d.end(), niza[i]) - d.begin();
			if(d[l-1] < niza[i] && niza[i] < d[l])
				d[l] = niza[i];
		}
		int ans = 0;
		for(int l = 0; l <= n; l++){
			if(d[l] < INF)
				ans =l;
		}
		cout<<ans<<endl;
		return 0;
	}
	if(d == 1){
		stack<int> st;
		for(int i = 1; i <= n; i++){
			while(!st.empty()){
				if(cnt[st.top()] < cnt[i])	st.pop();
				else{
					idx[i] = st.top();
					break;
				}
			}
			st.push(i);
		}
		int ans = 0;
		for(int i = n; i>0; i--){
			update(idx[i]+1);
			ans = max(ans, query(i));
		}
		cout<<ans<<endl;
		return 0;
	}
	sort(arr.begin(), arr.end());
	memset(can_jump, 0, sizeof can_jump);
	arr.erase(unique(arr.begin(), arr.end()), arr.end());
	for(int i = 1; i <= n; i++)	cnt[i] = lower_bound(arr.begin(), arr.end(), cnt[i]) - arr.begin() + 1;
	for(int i = 1; i <= n; i++){
		int last = i;
		for(int j = i +1; j <= n; j++){
			if(j - last <= d && cnt[i] < cnt[j])	can_jump[i][j] = 1;
			if(j - last <= d && cnt[i] >= cnt[j])	last = j;
		}
	}
	int dp[n+1];
	for(int i = 1; i <= n; i++){
		dp[i] = 1;
		for(int j = 1; j < i; j++){
			if(!can_jump[j][i])	continue;
			dp[i] = max(dp[i], dp[j] + 1);
		}
	}
	int ans = 0;
	for(int i = 1; i <= n; i++)
		ans = max(ans, dp[i]);
		
	cout<<ans<<endl;
	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...