답안 #133797

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
133797 2019-07-21T11:40:25 Z mirbek01 Global Warming (CEOI18_glo) C++11
100 / 100
403 ms 13544 KB
# include <bits/stdc++.h>

using namespace std;

const int N = 4e5 + 3;

int n, x, a[N], b[N], t[N * 4];
int f[N], s[N], ans;
vector <int> vec;

void upd(int pos, int val, int v = 1, int tl = 1, int tr = N - 1){
	if(tl == tr){
		t[v] = max(t[v], val);
	} else {
		int tm = (tl + tr) >> 1;
		if(pos <= tm)
			upd(pos, val, v << 1, tl, tm);
		else 
			upd(pos, val, v << 1 | 1, tm + 1, tr);
		t[v] = max(t[v << 1], t[v << 1 | 1]);
	}
}

int get(int l, int r, int v = 1, int tl = 1, int tr = N - 1){
	if(l > tr || tl > r) 
		return 0;
	if(l <= tl && tr <= r)
		return t[v];
	int tm = (tl + tr) >> 1;
	return max(get(l, r, v << 1, tl, tm), 
				get(l, r, v << 1 | 1, tm + 1, tr));
}

int main(){
	cin >> n >> x;
	
	for(int i = 1; i <= n; i ++){
		scanf("%d", a+i);
		b[i] = a[i] + x;
		vec.push_back(a[i]);
		vec.push_back(b[i]);
 	}
	
	sort(vec.begin(), vec.end());
	vec.resize( unique(vec.begin(), vec.end()) - vec.begin() );
	
	for(int i = 1; i <= n; i ++){
		a[i] = lower_bound(vec.begin(), vec.end(), a[i]) - vec.begin() + 1;
		b[i] = lower_bound(vec.begin(), vec.end(), b[i]) - vec.begin() + 1;
	}
	
	for(int i = n; i >= 1; i --){
		s[i] = get(b[i] + 1, N - 1) + 1;
		upd(b[i], s[i]);
		ans = max(ans, s[i]);
	}
		
	memset(t, 0, sizeof(t));

	for(int i = 1; i <= n; i ++){
		ans = max(ans, get(1, b[i] - 1) + s[i]);
		f[i] = get(1, a[i] - 1) + 1;
		upd(a[i], f[i]);
	}
	
	cout << ans << endl;
}

Compilation message

glo.cpp: In function 'int main()':
glo.cpp:38:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", a+i);
   ~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 6612 KB Output is correct
2 Correct 7 ms 6620 KB Output is correct
3 Correct 7 ms 6648 KB Output is correct
4 Correct 7 ms 6648 KB Output is correct
5 Correct 7 ms 6524 KB Output is correct
6 Correct 7 ms 6648 KB Output is correct
7 Correct 7 ms 6648 KB Output is correct
8 Correct 7 ms 6652 KB Output is correct
9 Correct 7 ms 6648 KB Output is correct
10 Correct 7 ms 6648 KB Output is correct
11 Correct 7 ms 6612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 6612 KB Output is correct
2 Correct 7 ms 6620 KB Output is correct
3 Correct 7 ms 6648 KB Output is correct
4 Correct 7 ms 6648 KB Output is correct
5 Correct 7 ms 6524 KB Output is correct
6 Correct 7 ms 6648 KB Output is correct
7 Correct 7 ms 6648 KB Output is correct
8 Correct 7 ms 6652 KB Output is correct
9 Correct 7 ms 6648 KB Output is correct
10 Correct 7 ms 6648 KB Output is correct
11 Correct 7 ms 6612 KB Output is correct
12 Correct 7 ms 6636 KB Output is correct
13 Correct 7 ms 6532 KB Output is correct
14 Correct 7 ms 6648 KB Output is correct
15 Correct 7 ms 6640 KB Output is correct
16 Correct 7 ms 6648 KB Output is correct
17 Correct 7 ms 6648 KB Output is correct
18 Correct 7 ms 6648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 6612 KB Output is correct
2 Correct 7 ms 6620 KB Output is correct
3 Correct 7 ms 6648 KB Output is correct
4 Correct 7 ms 6648 KB Output is correct
5 Correct 7 ms 6524 KB Output is correct
6 Correct 7 ms 6648 KB Output is correct
7 Correct 7 ms 6648 KB Output is correct
8 Correct 7 ms 6652 KB Output is correct
9 Correct 7 ms 6648 KB Output is correct
10 Correct 7 ms 6648 KB Output is correct
11 Correct 7 ms 6612 KB Output is correct
12 Correct 7 ms 6636 KB Output is correct
13 Correct 7 ms 6532 KB Output is correct
14 Correct 7 ms 6648 KB Output is correct
15 Correct 7 ms 6640 KB Output is correct
16 Correct 7 ms 6648 KB Output is correct
17 Correct 7 ms 6648 KB Output is correct
18 Correct 7 ms 6648 KB Output is correct
19 Correct 8 ms 6648 KB Output is correct
20 Correct 8 ms 6648 KB Output is correct
21 Correct 9 ms 6648 KB Output is correct
22 Correct 8 ms 6648 KB Output is correct
23 Correct 8 ms 6648 KB Output is correct
24 Correct 8 ms 6648 KB Output is correct
25 Correct 8 ms 6648 KB Output is correct
26 Correct 8 ms 6648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 364 ms 13376 KB Output is correct
2 Correct 370 ms 13376 KB Output is correct
3 Correct 366 ms 13376 KB Output is correct
4 Correct 362 ms 13284 KB Output is correct
5 Correct 208 ms 12644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 90 ms 8432 KB Output is correct
2 Correct 92 ms 8376 KB Output is correct
3 Correct 91 ms 8480 KB Output is correct
4 Correct 60 ms 8176 KB Output is correct
5 Correct 7 ms 6648 KB Output is correct
6 Correct 64 ms 8244 KB Output is correct
7 Correct 80 ms 8556 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 189 ms 10092 KB Output is correct
2 Correct 188 ms 10088 KB Output is correct
3 Correct 403 ms 13412 KB Output is correct
4 Correct 218 ms 12652 KB Output is correct
5 Correct 133 ms 9692 KB Output is correct
6 Correct 237 ms 12396 KB Output is correct
7 Correct 239 ms 13156 KB Output is correct
8 Correct 157 ms 10092 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 6612 KB Output is correct
2 Correct 7 ms 6620 KB Output is correct
3 Correct 7 ms 6648 KB Output is correct
4 Correct 7 ms 6648 KB Output is correct
5 Correct 7 ms 6524 KB Output is correct
6 Correct 7 ms 6648 KB Output is correct
7 Correct 7 ms 6648 KB Output is correct
8 Correct 7 ms 6652 KB Output is correct
9 Correct 7 ms 6648 KB Output is correct
10 Correct 7 ms 6648 KB Output is correct
11 Correct 7 ms 6612 KB Output is correct
12 Correct 7 ms 6636 KB Output is correct
13 Correct 7 ms 6532 KB Output is correct
14 Correct 7 ms 6648 KB Output is correct
15 Correct 7 ms 6640 KB Output is correct
16 Correct 7 ms 6648 KB Output is correct
17 Correct 7 ms 6648 KB Output is correct
18 Correct 7 ms 6648 KB Output is correct
19 Correct 8 ms 6648 KB Output is correct
20 Correct 8 ms 6648 KB Output is correct
21 Correct 9 ms 6648 KB Output is correct
22 Correct 8 ms 6648 KB Output is correct
23 Correct 8 ms 6648 KB Output is correct
24 Correct 8 ms 6648 KB Output is correct
25 Correct 8 ms 6648 KB Output is correct
26 Correct 8 ms 6648 KB Output is correct
27 Correct 364 ms 13376 KB Output is correct
28 Correct 370 ms 13376 KB Output is correct
29 Correct 366 ms 13376 KB Output is correct
30 Correct 362 ms 13284 KB Output is correct
31 Correct 208 ms 12644 KB Output is correct
32 Correct 90 ms 8432 KB Output is correct
33 Correct 92 ms 8376 KB Output is correct
34 Correct 91 ms 8480 KB Output is correct
35 Correct 60 ms 8176 KB Output is correct
36 Correct 7 ms 6648 KB Output is correct
37 Correct 64 ms 8244 KB Output is correct
38 Correct 80 ms 8556 KB Output is correct
39 Correct 189 ms 10092 KB Output is correct
40 Correct 188 ms 10088 KB Output is correct
41 Correct 403 ms 13412 KB Output is correct
42 Correct 218 ms 12652 KB Output is correct
43 Correct 133 ms 9692 KB Output is correct
44 Correct 237 ms 12396 KB Output is correct
45 Correct 239 ms 13156 KB Output is correct
46 Correct 157 ms 10092 KB Output is correct
47 Correct 187 ms 10044 KB Output is correct
48 Correct 185 ms 10216 KB Output is correct
49 Correct 397 ms 13376 KB Output is correct
50 Correct 233 ms 12644 KB Output is correct
51 Correct 181 ms 11064 KB Output is correct
52 Correct 252 ms 12752 KB Output is correct
53 Correct 246 ms 12788 KB Output is correct
54 Correct 251 ms 13456 KB Output is correct
55 Correct 325 ms 13544 KB Output is correct