제출 #321177

#제출 시각아이디문제언어결과실행 시간메모리
321177MounirGlobal Warming (CEOI18_glo)C++14
100 / 100
452 ms25812 KiB
#include <bits/stdc++.h>
#define chmin(x, v) x = min(x, v)
#define chmax(x, v) x = max(x, v)
#define all(v) v.begin(), v.end()
#define pb push_back
#define int long long
using namespace std;

const int N = 1 << 19;
int dynMax[2 * N][2];

int getMax(int gauche, int droite, int mod){
	if (gauche > droite) return 0;
	if (gauche%2 == 1) return max(dynMax[gauche][mod], getMax(gauche + 1, droite, mod));
	if (droite%2 == 0) return max(dynMax[droite][mod], getMax(gauche, droite - 1, mod));
	return getMax(gauche/2, droite/2, mod);
}

void update(int ind, int val, int mod){
	for (; ind > 0; ind /= 2)
		chmax(dynMax[ind][mod], val);
}

signed main(){
	int nVals, toAdd; cin >> nVals >> toAdd;
	vector<int> triees, vals(nVals), pointeur(nVals);
	map<int, int> conversion;
	for (int& val : vals) cin >> val, triees.pb(val);
	sort(all(triees));
	pointeur[nVals - 1] = nVals - 1;
	for (int ind = nVals - 2; ind >= 0; --ind){
		pointeur[ind] = pointeur[ind + 1];
		while (pointeur[ind] > ind && triees[pointeur[ind]] - toAdd >= triees[ind])
			--pointeur[ind];
	}
	
	for (int ind = 0; ind < nVals; ++ind)conversion[triees[ind]] = ind;
	
	for (int& val : vals) val = conversion[val];
	
	for (int ind = 0; ind < nVals; ++ind){
		for (int xAjoute = 1; xAjoute >= 0; --xAjoute){
			update(N + vals[ind], getMax(N, N + vals[ind] - 1, xAjoute) + 1, xAjoute);
			if (xAjoute == 1 && toAdd != 0) update(N + vals[ind], getMax(N, N + pointeur[vals[ind]], 0) + 1, xAjoute);
			//cout << dynMax[N + vals[ind]][xAjoute] << " " << vals[ind] << " " << pointeur[ind] << endl;
		}
	//	cout << endl;
	}
	
	cout << max(dynMax[1][0], dynMax[1][1]) << 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...
#Verdict Execution timeMemoryGrader output
Fetching results...