답안 #609777

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
609777 2022-07-27T21:51:22 Z Pietra Global Warming (CEOI18_glo) C++14
100 / 100
467 ms 36808 KB
#include<bits/stdc++.h>
#define meio ((i+j)>>1)
using namespace std ; 

const int maxn = 2e5 + 5 ; 
const int MAX = 2e5 + 5 ; 
const int lmt = 2e9 + 5 ; 

int n, x, v[maxn], suf[maxn] ; 
vector<int> e, d, mx ; 

struct SEG{

	int node(){
		e.push_back(0), d.push_back(0), mx.push_back(0) ; 
		return max(0, (int)d.size() - 1) ; 
	}

	void upd(int no, int i, int j, int pos, int val){
		if(!no) return ;
		if(i == j){
			mx[no] = max(val, mx[no]) ; return ; 
		}
		if(pos <= meio){
			if(!e[no]){
				int aux = node() ; 
				e[no] = aux ; 
			}
			upd(e[no], i, meio, pos, val) ; 
		}
		else{
			if(!d[no]){
				int aux = node() ; 
				d[no] = aux ; 
			}
			upd(d[no], meio + 1, j, pos, val) ; 
		}
		mx[no] = max(mx[e[no]], mx[d[no]]) ; 
	}

	int query(int no, int i, int j, int l, int r){
		if(!no || l > j || r < i) return 0 ; 
		if(r >= j && l <= i) return mx[no] ; 
		return max(query(e[no], i, meio, l, r), query(d[no], meio + 1, j, l, r)) ; 
	}

} Seg ; 

int main(){

	ios_base::sync_with_stdio(false) ; cin.tie(NULL) ; 

	cin >> n >> x ; 

	for(int i = 1 ; i <= n ; i++){
		cin >> v[i] ; 
		v[i]++ ; 
	}	

	Seg.node() ; Seg.node() ;

	for(int i = n ; i > 0 ; i--){
		int mx = Seg.query(1, 1, lmt, v[i] + 1, lmt) ; 
		Seg.upd(1, 1, lmt, v[i], mx + 1) ; 
		suf[i] = mx + 1 ; 
	}

	// for(int i = 1 ; i <= n ; i++) cout << suf[i] << " " ; 
	// cout << "\n" ; 

	int ans = Seg.query(1, 1, lmt, 1, lmt) ; 

	e.clear() ; d.clear() ; mx.clear() ; 
	Seg.node() ; Seg.node() ;

	for(int i = 1 ; i <= n ; i++){
		int val = Seg.query(1, 1, lmt, 1, v[i] - 1) ;
		int valor = Seg.query(1, 1, lmt, 1, v[i] + x - 1) ;
		ans = max(ans, suf[i] + valor) ; 
		Seg.upd(1, 1, lmt, v[i], val + 1) ; 
	} 

	cout << ans << "\n" ; 

}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 224 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 224 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 324 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 224 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 324 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 324 KB Output is correct
19 Correct 2 ms 724 KB Output is correct
20 Correct 2 ms 724 KB Output is correct
21 Correct 2 ms 720 KB Output is correct
22 Correct 2 ms 724 KB Output is correct
23 Correct 2 ms 468 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 2 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 456 ms 36632 KB Output is correct
2 Correct 449 ms 36612 KB Output is correct
3 Correct 457 ms 36632 KB Output is correct
4 Correct 467 ms 36808 KB Output is correct
5 Correct 213 ms 20076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 82 ms 10368 KB Output is correct
2 Correct 108 ms 10384 KB Output is correct
3 Correct 87 ms 10348 KB Output is correct
4 Correct 57 ms 5928 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 51 ms 2112 KB Output is correct
7 Correct 67 ms 9612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 183 ms 19236 KB Output is correct
2 Correct 173 ms 19084 KB Output is correct
3 Correct 400 ms 36616 KB Output is correct
4 Correct 191 ms 20096 KB Output is correct
5 Correct 90 ms 4068 KB Output is correct
6 Correct 179 ms 7568 KB Output is correct
7 Correct 179 ms 8228 KB Output is correct
8 Correct 117 ms 14316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 224 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 324 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 324 KB Output is correct
19 Correct 2 ms 724 KB Output is correct
20 Correct 2 ms 724 KB Output is correct
21 Correct 2 ms 720 KB Output is correct
22 Correct 2 ms 724 KB Output is correct
23 Correct 2 ms 468 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 2 ms 340 KB Output is correct
27 Correct 456 ms 36632 KB Output is correct
28 Correct 449 ms 36612 KB Output is correct
29 Correct 457 ms 36632 KB Output is correct
30 Correct 467 ms 36808 KB Output is correct
31 Correct 213 ms 20076 KB Output is correct
32 Correct 82 ms 10368 KB Output is correct
33 Correct 108 ms 10384 KB Output is correct
34 Correct 87 ms 10348 KB Output is correct
35 Correct 57 ms 5928 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 51 ms 2112 KB Output is correct
38 Correct 67 ms 9612 KB Output is correct
39 Correct 183 ms 19236 KB Output is correct
40 Correct 173 ms 19084 KB Output is correct
41 Correct 400 ms 36616 KB Output is correct
42 Correct 191 ms 20096 KB Output is correct
43 Correct 90 ms 4068 KB Output is correct
44 Correct 179 ms 7568 KB Output is correct
45 Correct 179 ms 8228 KB Output is correct
46 Correct 117 ms 14316 KB Output is correct
47 Correct 202 ms 19116 KB Output is correct
48 Correct 202 ms 19024 KB Output is correct
49 Correct 438 ms 36536 KB Output is correct
50 Correct 271 ms 20080 KB Output is correct
51 Correct 136 ms 4728 KB Output is correct
52 Correct 198 ms 7972 KB Output is correct
53 Correct 180 ms 7968 KB Output is correct
54 Correct 177 ms 8588 KB Output is correct
55 Correct 344 ms 26564 KB Output is correct