답안 #445321

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
445321 2021-07-17T13:11:31 Z hhhhaura Global Warming (CEOI18_glo) C++14
100 / 100
136 ms 13196 KB
#define wiwihorz
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma loop-opt(on)

#define rep(i, a, b) for(int i = a; i <= b; i ++)
#define rrep(i, a, b) for(int i = b; i >= a; i --)
#define all(x) x.begin(), x.end()
#define ceil(a, b) ((a + b - 1) / (b))

#define INF 1000000000000000000
#define MOD 1000000007
#define eps (1e-9)

using namespace std;

#define int long long int
#define lld long double
#define pii pair<int, int> 
#define random mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count())

#ifdef wiwihorz
#define print(a...) cerr << "Line " << __LINE__ << ": ", kout("[" + string(#a) + "] = ", a)
void vprint(auto L, auto R) {while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
void kout() { cerr << endl; }
template<class T1, class ... T2> void kout(T1 a, T2 ... e) { cerr << a << " ", kout(e...); }
#else
#define print(...) 0
#define vprint(...) 0
#endif
namespace solver {
	int n, x;
	vector<int> dp, cnt, a;
	void init_(int _n, int _x) {
		n = _n, x = _x;
		dp.assign(n + 1, INF);
		a.assign(n + 1, 0);
		cnt.assign(n + 1, 0);
	}
	int solve() {
		rep(i, 1, n) {
			int id = lower_bound(all(dp), a[i]) - dp.begin();
			cnt[i] = id + 1, dp[id] = a[i];
		}
		int ans = cnt[n];
		dp.assign(n + 1, INF);
		map<int, int> mp;
		rrep(i, 1, n) {
			int id = lower_bound(all(dp), -a[i]) - dp.begin();
			dp[id] = -a[i];
			auto it = mp.upper_bound(a[i]);
			if(it == mp.end() || it -> second < id + 1) {
				if(it != mp.begin()) {
					it = prev(it);
					while(true) {
						if(it -> second > id + 1) break;
						auto temp = it;
						if(it == mp.begin()) {
							mp.erase(temp);
							break;
						}
						else it = prev(it), mp.erase(temp);
					}
				}
				mp[a[i]] = id + 1; 
			}
			it = mp.upper_bound(a[i - 1] - x);
			if(it != mp.end())ans = max(ans, it -> second + cnt[i - 1]);
		}
		return ans;
	}
};
using namespace solver;
signed main() {
	ios::sync_with_stdio(false), cin.tie(0);
	int n, x; cin >> n >> x;
	init_(n, x);
	rep(i, 1, n) cin >> a[i];
	cout << solve() << "\n";
	return 0;
}

Compilation message

glo.cpp:4: warning: ignoring '#pragma loop ' [-Wunknown-pragmas]
    4 | #pragma loop-opt(on)
      | 
glo.cpp:24:13: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   24 | void vprint(auto L, auto R) {while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
      |             ^~~~
glo.cpp:24:21: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   24 | void vprint(auto L, auto R) {while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
      |                     ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 316 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 316 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 1 ms 204 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 0 ms 204 KB Output is correct
2 Correct 0 ms 316 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 1 ms 204 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 332 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 308 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 116 ms 6920 KB Output is correct
2 Correct 117 ms 7060 KB Output is correct
3 Correct 116 ms 6932 KB Output is correct
4 Correct 117 ms 6932 KB Output is correct
5 Correct 131 ms 12356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 1984 KB Output is correct
2 Correct 27 ms 2004 KB Output is correct
3 Correct 28 ms 1988 KB Output is correct
4 Correct 29 ms 3320 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 30 ms 3264 KB Output is correct
7 Correct 22 ms 2012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 52 ms 3648 KB Output is correct
2 Correct 50 ms 3656 KB Output is correct
3 Correct 105 ms 6948 KB Output is correct
4 Correct 136 ms 12484 KB Output is correct
5 Correct 62 ms 6260 KB Output is correct
6 Correct 92 ms 11844 KB Output is correct
7 Correct 118 ms 12532 KB Output is correct
8 Correct 44 ms 3680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 316 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 1 ms 204 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 332 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 308 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 116 ms 6920 KB Output is correct
28 Correct 117 ms 7060 KB Output is correct
29 Correct 116 ms 6932 KB Output is correct
30 Correct 117 ms 6932 KB Output is correct
31 Correct 131 ms 12356 KB Output is correct
32 Correct 27 ms 1984 KB Output is correct
33 Correct 27 ms 2004 KB Output is correct
34 Correct 28 ms 1988 KB Output is correct
35 Correct 29 ms 3320 KB Output is correct
36 Correct 0 ms 204 KB Output is correct
37 Correct 30 ms 3264 KB Output is correct
38 Correct 22 ms 2012 KB Output is correct
39 Correct 52 ms 3648 KB Output is correct
40 Correct 50 ms 3656 KB Output is correct
41 Correct 105 ms 6948 KB Output is correct
42 Correct 136 ms 12484 KB Output is correct
43 Correct 62 ms 6260 KB Output is correct
44 Correct 92 ms 11844 KB Output is correct
45 Correct 118 ms 12532 KB Output is correct
46 Correct 44 ms 3680 KB Output is correct
47 Correct 59 ms 3632 KB Output is correct
48 Correct 57 ms 3640 KB Output is correct
49 Correct 116 ms 6924 KB Output is correct
50 Correct 128 ms 12360 KB Output is correct
51 Correct 101 ms 10944 KB Output is correct
52 Correct 133 ms 12504 KB Output is correct
53 Correct 90 ms 12484 KB Output is correct
54 Correct 122 ms 13196 KB Output is correct
55 Correct 92 ms 6920 KB Output is correct