답안 #605220

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
605220 2022-07-25T14:10:52 Z Evirir Global Warming (CEOI18_glo) C++17
100 / 100
88 ms 10080 KB
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;

#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2")
#define watch(x) cout<<(#x)<<"="<<(x)<<'\n'
#define mset(d,val) memset(d,val,sizeof(d))
#define cbug if(DEBUG) cout
#define setp(x) cout<<fixed<<setprecision(x)
#define sz(x) (int)(x).size()
#define all(x) begin(x), end(x)
#define forn(i,a,b) for(int i=(a);i<(b);i++)
#define fore(i,a,b) for(int i=(a);i<=(b);i++)
#define pb push_back
#define F first
#define S second
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
//template<typename T>
//using pbds = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
void SD(int t=0){ cout<<"PASSED "<<t<<endl; }
ostream& operator<<(ostream &out, ii x){ out<<"("<<x.F<<","<<x.S<<")"; return out; }
template<typename T> void amax(T &a, T b){ a=max(a,b); }
template<typename T> void amin(T &a, T b){ a=min(a,b); }
const ll INF = ll(1e18);
const int MOD = 998244353;

const bool DEBUG = 0;
const int MAXN = 200005;
const int LG = 21;

int n;
ll X;
ll a[MAXN];
vi dpl, dpr;
vii chg;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	cin>>n>>X;
	forn(i,0,n) cin>>a[i];

	dpl.resize(n + 1, INF);
	dpl[0] = -INF;
	dpr.resize(n + 1, -INF);
	dpr[0] = INF;
	chg.resize(n);

	for (int i = n - 1; i >= 0; i--)
	{
		int p = lower_bound(all(dpr), a[i], greater<ll>()) - dpr.begin();
		chg[i] = {p, dpr[p]};
		dpr[p] = a[i];
	}

	int ans = 0;
	forn(i, 0, n)
	{
		int pl = lower_bound(all(dpl), a[i]) - dpl.begin();
		int pr = chg[i].F;
		dpl[pl] = a[i];
		dpr[pr] = chg[i].S;

		int q = lower_bound(all(dpr), dpl[pl] - X, greater<ll>()) - dpr.begin() - 1;
		ans = max(ans, pl + q);

		q = lower_bound(all(dpl), dpr[pr] + X) - dpl.begin() - 1;
		ans = max(ans, q + pr);
	}

	int cur = 0;
	while (cur + 1 <= n && dpl[cur + 1] != INF)
		cur++;
	ans = max(ans, cur);

	cout << ans << '\n';
	
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 328 KB Output is correct
8 Correct 0 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 324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 328 KB Output is correct
8 Correct 0 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 324 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 328 KB Output is correct
8 Correct 0 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 324 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 76 ms 10076 KB Output is correct
2 Correct 88 ms 10080 KB Output is correct
3 Correct 87 ms 10076 KB Output is correct
4 Correct 72 ms 10004 KB Output is correct
5 Correct 48 ms 9316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 2772 KB Output is correct
2 Correct 17 ms 2768 KB Output is correct
3 Correct 19 ms 2752 KB Output is correct
4 Correct 12 ms 2556 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 13 ms 2560 KB Output is correct
7 Correct 13 ms 2772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 5136 KB Output is correct
2 Correct 33 ms 5160 KB Output is correct
3 Correct 75 ms 10008 KB Output is correct
4 Correct 53 ms 9248 KB Output is correct
5 Correct 32 ms 4824 KB Output is correct
6 Correct 43 ms 8960 KB Output is correct
7 Correct 44 ms 9552 KB Output is correct
8 Correct 23 ms 5204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 328 KB Output is correct
8 Correct 0 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 324 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 76 ms 10076 KB Output is correct
28 Correct 88 ms 10080 KB Output is correct
29 Correct 87 ms 10076 KB Output is correct
30 Correct 72 ms 10004 KB Output is correct
31 Correct 48 ms 9316 KB Output is correct
32 Correct 16 ms 2772 KB Output is correct
33 Correct 17 ms 2768 KB Output is correct
34 Correct 19 ms 2752 KB Output is correct
35 Correct 12 ms 2556 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 13 ms 2560 KB Output is correct
38 Correct 13 ms 2772 KB Output is correct
39 Correct 27 ms 5136 KB Output is correct
40 Correct 33 ms 5160 KB Output is correct
41 Correct 75 ms 10008 KB Output is correct
42 Correct 53 ms 9248 KB Output is correct
43 Correct 32 ms 4824 KB Output is correct
44 Correct 43 ms 8960 KB Output is correct
45 Correct 44 ms 9552 KB Output is correct
46 Correct 23 ms 5204 KB Output is correct
47 Correct 42 ms 5204 KB Output is correct
48 Correct 40 ms 5140 KB Output is correct
49 Correct 72 ms 10076 KB Output is correct
50 Correct 48 ms 9256 KB Output is correct
51 Correct 37 ms 7000 KB Output is correct
52 Correct 53 ms 9412 KB Output is correct
53 Correct 42 ms 9428 KB Output is correct
54 Correct 47 ms 10060 KB Output is correct
55 Correct 59 ms 10060 KB Output is correct