제출 #518723

#제출 시각아이디문제언어결과실행 시간메모리
518723zhangjishenGlobal Warming (CEOI18_glo)C++98
100 / 100
65 ms3412 KiB
#include<bits/stdc++.h>
using namespace std;

#define mp make_pair
#define pb push_back
#define fi first
#define se second
template<typename T> bool chkmin(T &a, T b){return b < a ? a = b, 1 : 0;}
template<typename T> bool chkmax(T &a, T b){return b > a ? a = b, 1 : 0;}
const int inf = 2e9 + 10, MAXN = 2e5 + 10;

int n, x, a[MAXN], f[MAXN], L[MAXN], R[MAXN];
int main(){
	// input
	scanf("%d %d", &n, &x);
	for(int i = 1; i <= n; i++)
		scanf("%d", &a[i]);
	// L
	for(int i = 1; i <= n; i++)
		f[i] = inf;
	for(int i = 1; i <= n; i++){
		L[i] = lower_bound(f + 1, f + 1 + n, a[i] + x) - f;
		int j = lower_bound(f + 1, f + 1 + n, a[i]) - f;
		f[j] = a[i];
	}
	// R
	for(int i = 1; i <= n; i++)
		f[i] = inf;
	for(int i = n; i >= 1; i--){	// LDS of reverse = LIS of - reverse
		R[i] = lower_bound(f + 1, f + 1 + n, -a[i]) - f;
		f[R[i]] = -a[i];
	}
	// ans
	int ans = 0;
	for(int i = 1; i <= n; i++)
		chkmax(ans, L[i] + R[i] - 1);
	printf("%d\n", ans);
}

컴파일 시 표준 에러 (stderr) 메시지

glo.cpp: In function 'int main()':
glo.cpp:15:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |  scanf("%d %d", &n, &x);
      |  ~~~~~^~~~~~~~~~~~~~~~~
glo.cpp:17:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |   scanf("%d", &a[i]);
      |   ~~~~~^~~~~~~~~~~~~
#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...