답안 #482505

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
482505 2021-10-25T05:34:01 Z ArianKheirandish Global Warming (CEOI18_glo) C++14
100 / 100
326 ms 24388 KB
// in the name of God//

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x)	x.begin(),x.end()
#define F		first
#define S		second
#define MP		make_pair

const int maxn = 4e5 + 20;
ll n, x, ans;
ll a[2][maxn], dp[maxn], pd[maxn];
ll seg[maxn << 2];

void Update(int idx, ll val, int id = 1, int l = 1, int r = maxn){
	if(l == r - 1){
		seg[id] = max(seg[id], val);
		return;
	}

	int mid = (l + r) >> 1;
	if(idx < mid)
		Update(idx, val, id << 1, l, mid);
	else
		Update(idx, val, id << 1 | 1, mid, r);

	seg[id] = max(seg[id << 1], seg[id << 1 | 1]);
}

ll Get(int l, int r, int id = 1, int L = 1, int R = maxn){
	if(R <= l || r <= L)
		return 0;

	if(l <= L && R <= r)
		return seg[id];

	int mid = (L + R) >> 1;
	return max(Get(l, r, id << 1, L, mid), 
				Get(l, r, id << 1 | 1, mid, R));
}

vector<ll> v;

int main(){
	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);

	cin >> n >> x;
	for(int i = 1 ; i <= n ; i ++){
		cin >> a[0][i];
		v.push_back(a[0][i]);
		v.push_back(a[1][i] = a[0][i] + x);
	}

	sort(all(v));
	v.resize(unique(all(v)) - v.begin());

	for(int i = 1 ; i <= n ; i ++){
		a[0][i] = lower_bound(all(v), a[0][i]) - v.begin() + 1;
		a[1][i] = lower_bound(all(v), a[1][i]) - v.begin() + 1;
	}

	for(int i = n ; i >= 1 ; i --){
		dp[i] = Get(a[1][i] + 1, maxn - 1) + 1ll;
		ans = max(ans, dp[i]);
		Update(a[1][i], dp[i]);
	}
	
	ans = max(ans, seg[1]);
	
	for(int i = 0 ; i < (maxn << 2) ; i ++)
		seg[i] = 0;

	for(int i = 1 ; i <= n ; i ++){
		ll tmp = Get(1, a[1][i]) + dp[i];
		pd[i] = Get(1, a[0][i]) + 1;
		ans = max(ans, tmp);
		Update(a[0][i], pd[i]);
	}
	
	ans = max(ans, seg[1]);
	cout << ans << '\n';

	return 0;
}

/*
	Hasbi Allah	
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 12876 KB Output is correct
2 Correct 5 ms 12864 KB Output is correct
3 Correct 5 ms 12748 KB Output is correct
4 Correct 5 ms 12876 KB Output is correct
5 Correct 5 ms 12876 KB Output is correct
6 Correct 5 ms 12844 KB Output is correct
7 Correct 5 ms 12876 KB Output is correct
8 Correct 5 ms 12748 KB Output is correct
9 Correct 5 ms 12876 KB Output is correct
10 Correct 5 ms 12748 KB Output is correct
11 Correct 6 ms 12748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 12876 KB Output is correct
2 Correct 5 ms 12864 KB Output is correct
3 Correct 5 ms 12748 KB Output is correct
4 Correct 5 ms 12876 KB Output is correct
5 Correct 5 ms 12876 KB Output is correct
6 Correct 5 ms 12844 KB Output is correct
7 Correct 5 ms 12876 KB Output is correct
8 Correct 5 ms 12748 KB Output is correct
9 Correct 5 ms 12876 KB Output is correct
10 Correct 5 ms 12748 KB Output is correct
11 Correct 6 ms 12748 KB Output is correct
12 Correct 5 ms 12876 KB Output is correct
13 Correct 5 ms 12876 KB Output is correct
14 Correct 5 ms 12876 KB Output is correct
15 Correct 5 ms 12876 KB Output is correct
16 Correct 5 ms 12876 KB Output is correct
17 Correct 5 ms 12876 KB Output is correct
18 Correct 5 ms 12876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 12876 KB Output is correct
2 Correct 5 ms 12864 KB Output is correct
3 Correct 5 ms 12748 KB Output is correct
4 Correct 5 ms 12876 KB Output is correct
5 Correct 5 ms 12876 KB Output is correct
6 Correct 5 ms 12844 KB Output is correct
7 Correct 5 ms 12876 KB Output is correct
8 Correct 5 ms 12748 KB Output is correct
9 Correct 5 ms 12876 KB Output is correct
10 Correct 5 ms 12748 KB Output is correct
11 Correct 6 ms 12748 KB Output is correct
12 Correct 5 ms 12876 KB Output is correct
13 Correct 5 ms 12876 KB Output is correct
14 Correct 5 ms 12876 KB Output is correct
15 Correct 5 ms 12876 KB Output is correct
16 Correct 5 ms 12876 KB Output is correct
17 Correct 5 ms 12876 KB Output is correct
18 Correct 5 ms 12876 KB Output is correct
19 Correct 6 ms 12876 KB Output is correct
20 Correct 6 ms 12876 KB Output is correct
21 Correct 6 ms 12876 KB Output is correct
22 Correct 8 ms 12876 KB Output is correct
23 Correct 6 ms 12852 KB Output is correct
24 Correct 6 ms 12876 KB Output is correct
25 Correct 6 ms 12876 KB Output is correct
26 Correct 6 ms 12848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 307 ms 24292 KB Output is correct
2 Correct 311 ms 24240 KB Output is correct
3 Correct 293 ms 24240 KB Output is correct
4 Correct 307 ms 24204 KB Output is correct
5 Correct 201 ms 23612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 73 ms 15716 KB Output is correct
2 Correct 75 ms 15712 KB Output is correct
3 Correct 75 ms 15808 KB Output is correct
4 Correct 50 ms 15548 KB Output is correct
5 Correct 5 ms 12876 KB Output is correct
6 Correct 54 ms 15552 KB Output is correct
7 Correct 66 ms 15716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 149 ms 18616 KB Output is correct
2 Correct 148 ms 18648 KB Output is correct
3 Correct 324 ms 24268 KB Output is correct
4 Correct 192 ms 23444 KB Output is correct
5 Correct 107 ms 18264 KB Output is correct
6 Correct 181 ms 23092 KB Output is correct
7 Correct 199 ms 23896 KB Output is correct
8 Correct 128 ms 18652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 12876 KB Output is correct
2 Correct 5 ms 12864 KB Output is correct
3 Correct 5 ms 12748 KB Output is correct
4 Correct 5 ms 12876 KB Output is correct
5 Correct 5 ms 12876 KB Output is correct
6 Correct 5 ms 12844 KB Output is correct
7 Correct 5 ms 12876 KB Output is correct
8 Correct 5 ms 12748 KB Output is correct
9 Correct 5 ms 12876 KB Output is correct
10 Correct 5 ms 12748 KB Output is correct
11 Correct 6 ms 12748 KB Output is correct
12 Correct 5 ms 12876 KB Output is correct
13 Correct 5 ms 12876 KB Output is correct
14 Correct 5 ms 12876 KB Output is correct
15 Correct 5 ms 12876 KB Output is correct
16 Correct 5 ms 12876 KB Output is correct
17 Correct 5 ms 12876 KB Output is correct
18 Correct 5 ms 12876 KB Output is correct
19 Correct 6 ms 12876 KB Output is correct
20 Correct 6 ms 12876 KB Output is correct
21 Correct 6 ms 12876 KB Output is correct
22 Correct 8 ms 12876 KB Output is correct
23 Correct 6 ms 12852 KB Output is correct
24 Correct 6 ms 12876 KB Output is correct
25 Correct 6 ms 12876 KB Output is correct
26 Correct 6 ms 12848 KB Output is correct
27 Correct 307 ms 24292 KB Output is correct
28 Correct 311 ms 24240 KB Output is correct
29 Correct 293 ms 24240 KB Output is correct
30 Correct 307 ms 24204 KB Output is correct
31 Correct 201 ms 23612 KB Output is correct
32 Correct 73 ms 15716 KB Output is correct
33 Correct 75 ms 15712 KB Output is correct
34 Correct 75 ms 15808 KB Output is correct
35 Correct 50 ms 15548 KB Output is correct
36 Correct 5 ms 12876 KB Output is correct
37 Correct 54 ms 15552 KB Output is correct
38 Correct 66 ms 15716 KB Output is correct
39 Correct 149 ms 18616 KB Output is correct
40 Correct 148 ms 18648 KB Output is correct
41 Correct 324 ms 24268 KB Output is correct
42 Correct 192 ms 23444 KB Output is correct
43 Correct 107 ms 18264 KB Output is correct
44 Correct 181 ms 23092 KB Output is correct
45 Correct 199 ms 23896 KB Output is correct
46 Correct 128 ms 18652 KB Output is correct
47 Correct 144 ms 18648 KB Output is correct
48 Correct 147 ms 18616 KB Output is correct
49 Correct 326 ms 24288 KB Output is correct
50 Correct 183 ms 23508 KB Output is correct
51 Correct 147 ms 20784 KB Output is correct
52 Correct 207 ms 23608 KB Output is correct
53 Correct 188 ms 23600 KB Output is correct
54 Correct 192 ms 24240 KB Output is correct
55 Correct 271 ms 24388 KB Output is correct