답안 #99109

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
99109 2019-02-28T18:24:15 Z thiago4532 Global Warming (CEOI18_glo) C++17
100 / 100
958 ms 173252 KB
#include <bits/stdc++.h>
#define int int64_t

using namespace std;
const int maxv = 2e9 + 10;
const int maxn = 2e5 + 10;
const int inf = 0x3f3f3f3f3f3f3f3fll;
int n, x;
int dp[maxn], dp2[maxn], v[maxn];

struct node{
	int v;
	node *l, *r;
	node(int v=0): v(v), l(0), r(0) {}
};

void update(node* no, int p, int v, int ini=0, int fim=maxv){
	if(ini == fim){
		no->v = max(no->v, v);
		return;
	}

	int meio = (ini+fim)>>1;
	if(p <= meio){
		if(!no->l) no->l = new node;
		update(no->l, p, v, ini, meio);
	}else{
		if(!no->r) no->r = new node;
		update(no->r, p, v, meio+1, fim);
	}
	no->v = max((no->l?no->l->v:0), (no->r?no->r->v:0));
}

int query(node* no, int l, int r, int ini=0, int fim=maxv){
	if(!no || ini > fim || ini > r || fim < l) return 0;
	else if(l <= ini && fim <= r) return no->v;

	int meio = (ini+fim)>>1;
	int p1 = (no->l?query(no->l, l, r, ini, meio):0);
	int p2 = (no->r?query(no->r, l, r, meio+1, fim):0);
	return max(p1, p2);
}

int32_t main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n >> x;
	for(int i=1;i<=n;i++)
		cin >> v[i];

	node *n1 = new node, *n2 = new node;

	for(int i=1;i<=n;i++){
		dp[i] = dp2[i] = 1;

		dp[i] = 1 + query(n1, 0, v[i]-1);
		dp2[i] = 1 + max(query(n1, 0, v[i]+x-1), query(n2, 0, v[i]-1));
		// if(i==2) cout << "DEBUG: " << query(n1, -maxv, v[i]+x-1) << " " << v[i]+x-1 << "\n";
		// for(int j=1;j<i;j++){
		// 	if(v[j] - x >= v[i]) continue;
		// 	dp2[i] = max(dp2[i], 1 + dp[j]);
		// 	if(v[j] >= v[i]) continue;
		// 	dp[i] = max(dp[i], 1 + dp[j]);
		// 	dp2[i] = max(dp2[i], 1 + dp2[j]);
		// }
		update(n1, v[i], dp[i]);
		update(n2, v[i], dp2[i]);
	}

	int ans=0;
	for(int i=1;i<=n;i++)
		ans = max(ans, dp2[i]);

	cout << ans << "\n";
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 412 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 412 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 356 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 412 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 356 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 8 ms 1672 KB Output is correct
20 Correct 6 ms 1664 KB Output is correct
21 Correct 6 ms 1764 KB Output is correct
22 Correct 6 ms 1792 KB Output is correct
23 Correct 4 ms 1280 KB Output is correct
24 Correct 4 ms 1152 KB Output is correct
25 Correct 3 ms 512 KB Output is correct
26 Correct 3 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 949 ms 173216 KB Output is correct
2 Correct 902 ms 173080 KB Output is correct
3 Correct 947 ms 172996 KB Output is correct
4 Correct 879 ms 173176 KB Output is correct
5 Correct 373 ms 95292 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 214 ms 49764 KB Output is correct
2 Correct 199 ms 49784 KB Output is correct
3 Correct 251 ms 49908 KB Output is correct
4 Correct 113 ms 27128 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 95 ms 6520 KB Output is correct
7 Correct 159 ms 36088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 456 ms 92960 KB Output is correct
2 Correct 447 ms 93048 KB Output is correct
3 Correct 831 ms 173044 KB Output is correct
4 Correct 329 ms 95376 KB Output is correct
5 Correct 105 ms 15224 KB Output is correct
6 Correct 214 ms 28692 KB Output is correct
7 Correct 249 ms 28788 KB Output is correct
8 Correct 244 ms 67296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 412 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 356 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 8 ms 1672 KB Output is correct
20 Correct 6 ms 1664 KB Output is correct
21 Correct 6 ms 1764 KB Output is correct
22 Correct 6 ms 1792 KB Output is correct
23 Correct 4 ms 1280 KB Output is correct
24 Correct 4 ms 1152 KB Output is correct
25 Correct 3 ms 512 KB Output is correct
26 Correct 3 ms 512 KB Output is correct
27 Correct 949 ms 173216 KB Output is correct
28 Correct 902 ms 173080 KB Output is correct
29 Correct 947 ms 172996 KB Output is correct
30 Correct 879 ms 173176 KB Output is correct
31 Correct 373 ms 95292 KB Output is correct
32 Correct 214 ms 49764 KB Output is correct
33 Correct 199 ms 49784 KB Output is correct
34 Correct 251 ms 49908 KB Output is correct
35 Correct 113 ms 27128 KB Output is correct
36 Correct 2 ms 384 KB Output is correct
37 Correct 95 ms 6520 KB Output is correct
38 Correct 159 ms 36088 KB Output is correct
39 Correct 456 ms 92960 KB Output is correct
40 Correct 447 ms 93048 KB Output is correct
41 Correct 831 ms 173044 KB Output is correct
42 Correct 329 ms 95376 KB Output is correct
43 Correct 105 ms 15224 KB Output is correct
44 Correct 214 ms 28692 KB Output is correct
45 Correct 249 ms 28788 KB Output is correct
46 Correct 244 ms 67296 KB Output is correct
47 Correct 435 ms 93168 KB Output is correct
48 Correct 430 ms 93368 KB Output is correct
49 Correct 958 ms 173252 KB Output is correct
50 Correct 362 ms 95540 KB Output is correct
51 Correct 151 ms 16632 KB Output is correct
52 Correct 319 ms 30428 KB Output is correct
53 Correct 223 ms 30332 KB Output is correct
54 Correct 228 ms 30328 KB Output is correct
55 Correct 619 ms 125848 KB Output is correct