답안 #507667

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
507667 2022-01-13T00:38:47 Z thiago_bastos Global Warming (CEOI18_glo) C++17
100 / 100
196 ms 6192 KB
#include "bits/stdc++.h"

using namespace std;

using i64 = long long;
using u64 = unsigned long long;
using i32 = int;
using u32 = unsigned;
using i16 = short;
using u16 = unsigned short;
using ld = long double;
using ii = pair<int, int>;

template<class T>
struct BIT {
	vector<T> bit;
	
	BIT() {}

	BIT(int n) {
		bit.assign(n + 1, 0);
	}
	
	void upd(int k, T x) {
		for(++k; k < int(bit.size()); k += k & -k) bit[k] = max(bit[k], x);
	}
	
	T query(int k) {
		T ans {};
		for(++k; k > 0; k -= k & -k) ans = max(ans, bit[k]);
		return ans;
	}
	
	T query(int l, int r) {
		if(l > r) return (T)0;
		return query(r) - query(l - 1);
	}
};

void solve() {	
	
	int n, x;

	cin >> n >> x;

	vector<int> a(n);

	for(int& v : a) cin >> v;

	auto p = a;
	sort(p.begin(), p.end());

	BIT<int> dp[2];
	int ans = 0;

	for(int j = 0; j < 2; ++j) {
		for(int i = 0; i < 2; ++i) dp[i] = BIT<int>(n);
		for(int i = 0; i < n; ++i) {
			int k = lower_bound(p.begin(), p.end(), a[i]) - p.begin();
			int j = upper_bound(p.begin(), p.end(), a[i] + x - 1) - p.begin() - 1;
			dp[1].upd(k, 1 + max(dp[1].query(k - 1), dp[0].query(j)));
			dp[0].upd(k, 1 + dp[0].query(k - 1));
		}
		ans = max(ans, dp[1].query(n - 1));
		for(int& v : a) v *= -1;
		for(int& v : p) v *= -1;
		reverse(p.begin(), p.end());
		reverse(a.begin(), a.end());
	}
			
	cout << ans << '\n';
}

int main() {
	ios_base :: sync_with_stdio(false);
	cin.tie(0);
	int t = 1;
	//cin >> t;
	while(t--) solve();
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 312 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 308 KB Output is correct
11 Correct 0 ms 312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 312 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 308 KB Output is correct
11 Correct 0 ms 312 KB Output is correct
12 Correct 0 ms 308 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 0 ms 316 KB Output is correct
16 Correct 1 ms 316 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 312 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 308 KB Output is correct
11 Correct 0 ms 312 KB Output is correct
12 Correct 0 ms 308 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 0 ms 316 KB Output is correct
16 Correct 1 ms 316 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 316 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 172 ms 6072 KB Output is correct
2 Correct 196 ms 6104 KB Output is correct
3 Correct 164 ms 6068 KB Output is correct
4 Correct 170 ms 6104 KB Output is correct
5 Correct 78 ms 5340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 1732 KB Output is correct
2 Correct 38 ms 1764 KB Output is correct
3 Correct 37 ms 1732 KB Output is correct
4 Correct 18 ms 1540 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 20 ms 1576 KB Output is correct
7 Correct 31 ms 1724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 57 ms 3204 KB Output is correct
2 Correct 69 ms 3224 KB Output is correct
3 Correct 128 ms 6060 KB Output is correct
4 Correct 72 ms 5376 KB Output is correct
5 Correct 34 ms 2740 KB Output is correct
6 Correct 73 ms 5188 KB Output is correct
7 Correct 73 ms 5800 KB Output is correct
8 Correct 47 ms 3164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 312 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 308 KB Output is correct
11 Correct 0 ms 312 KB Output is correct
12 Correct 0 ms 308 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 0 ms 316 KB Output is correct
16 Correct 1 ms 316 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 316 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 312 KB Output is correct
27 Correct 172 ms 6072 KB Output is correct
28 Correct 196 ms 6104 KB Output is correct
29 Correct 164 ms 6068 KB Output is correct
30 Correct 170 ms 6104 KB Output is correct
31 Correct 78 ms 5340 KB Output is correct
32 Correct 36 ms 1732 KB Output is correct
33 Correct 38 ms 1764 KB Output is correct
34 Correct 37 ms 1732 KB Output is correct
35 Correct 18 ms 1540 KB Output is correct
36 Correct 0 ms 204 KB Output is correct
37 Correct 20 ms 1576 KB Output is correct
38 Correct 31 ms 1724 KB Output is correct
39 Correct 57 ms 3204 KB Output is correct
40 Correct 69 ms 3224 KB Output is correct
41 Correct 128 ms 6060 KB Output is correct
42 Correct 72 ms 5376 KB Output is correct
43 Correct 34 ms 2740 KB Output is correct
44 Correct 73 ms 5188 KB Output is correct
45 Correct 73 ms 5800 KB Output is correct
46 Correct 47 ms 3164 KB Output is correct
47 Correct 79 ms 3244 KB Output is correct
48 Correct 75 ms 3224 KB Output is correct
49 Correct 169 ms 6064 KB Output is correct
50 Correct 77 ms 5372 KB Output is correct
51 Correct 66 ms 4084 KB Output is correct
52 Correct 114 ms 5424 KB Output is correct
53 Correct 69 ms 5548 KB Output is correct
54 Correct 71 ms 6168 KB Output is correct
55 Correct 164 ms 6192 KB Output is correct