Submission #676496

# Submission time Handle Problem Language Result Execution time Memory
676496 2022-12-31T03:44:56 Z penguin133 Global Warming (CEOI18_glo) C++17
100 / 100
771 ms 22648 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pi pair<int, int>
#define pii pair<int, pi>
#define fi first
#define se second


int P[300005], S[300005];
int n, x;
int A[300005], B[300005], C[300005];
int ft[300005];

void upd(int p, int v){
	for(;p<=n;p+=(p & -p))ft[p] = max(ft[p], v);
}

int query(int p){
	int res = 0;
	for(;p;p-=(p & -p))res = max(res, ft[p]);
	return res;
}
int32_t main(){
	cin >> n >> x;
	for(int i=1;i<=n;i++)cin >> A[i];
	map<int, int> mp;
	for(int i=1;i<=n;i++)C[i] = A[i];
	sort(C+1, C+n+1);
	int pre= -1e18, cnt = 0;
	for(int i=1;i<=n;i++){
		if(pre != C[i])mp[C[i]] = ++cnt;
		else mp[C[i]] = cnt;
		pre = C[i];
	}
	for(int i=1;i<=n;i++){
		P[i] = 1 + query(mp[A[i]] - 1);
		upd(mp[A[i]], P[i]);
	}
	for(int i=1;i<=n;i++)ft[i] = 0;
	for(int i=n;i>=1;i--){
		S[i] = 1 + query(n - mp[A[i]]);
		upd(n - mp[A[i]] + 1, S[i]);
	}
	for(int i=1;i<=n;i++){
		//cout << P[i].fi << " " << P[i].se << " " << S[i].fi << " " << S[i].se << '\n';
	}
	//for(int i=1;i<=n;i++)cout << mp[A[i]] << " ";
	//cout << '\n';
	int mini = 1e10;
	int ans = 0;
	for(int i=1;i<=n;i++)ft[i] = 0;
	for(int i=1;i<=n;i++){
		int res = A[i] + x;
		int s = 1, e = n, ans2 = 0;
		while(s <= e){
			int m = (s + e)>>1;
			if(C[m] < res)ans2 = m, s = m + 1;
			else e = m - 1;
		}
		ans = max(ans,query(mp[C[ans2]]) + S[i]);
		//cout << query(mp[C[ans2]]) + S[i].fi << '\n';
		upd(mp[A[i]], P[i]);
	}
	cout << ans;
}
	

Compilation message

glo.cpp: In function 'int32_t main()':
glo.cpp:51:6: warning: unused variable 'mini' [-Wunused-variable]
   51 |  int mini = 1e10;
      |      ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 308 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 308 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 304 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 308 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 308 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 304 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 308 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 308 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 304 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 440 KB Output is correct
20 Correct 1 ms 444 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 2 ms 444 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
# Verdict Execution time Memory Grader output
1 Correct 771 ms 22612 KB Output is correct
2 Correct 720 ms 22584 KB Output is correct
3 Correct 705 ms 22604 KB Output is correct
4 Correct 707 ms 22648 KB Output is correct
5 Correct 188 ms 15524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 93 ms 5836 KB Output is correct
2 Correct 119 ms 5844 KB Output is correct
3 Correct 105 ms 5880 KB Output is correct
4 Correct 40 ms 4036 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 44 ms 4032 KB Output is correct
7 Correct 76 ms 5792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 219 ms 11340 KB Output is correct
2 Correct 242 ms 11548 KB Output is correct
3 Correct 663 ms 22484 KB Output is correct
4 Correct 199 ms 15476 KB Output is correct
5 Correct 114 ms 11060 KB Output is correct
6 Correct 225 ms 20832 KB Output is correct
7 Correct 252 ms 21408 KB Output is correct
8 Correct 167 ms 11424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 308 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 308 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 304 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 440 KB Output is correct
20 Correct 1 ms 444 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 2 ms 444 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 771 ms 22612 KB Output is correct
28 Correct 720 ms 22584 KB Output is correct
29 Correct 705 ms 22604 KB Output is correct
30 Correct 707 ms 22648 KB Output is correct
31 Correct 188 ms 15524 KB Output is correct
32 Correct 93 ms 5836 KB Output is correct
33 Correct 119 ms 5844 KB Output is correct
34 Correct 105 ms 5880 KB Output is correct
35 Correct 40 ms 4036 KB Output is correct
36 Correct 0 ms 340 KB Output is correct
37 Correct 44 ms 4032 KB Output is correct
38 Correct 76 ms 5792 KB Output is correct
39 Correct 219 ms 11340 KB Output is correct
40 Correct 242 ms 11548 KB Output is correct
41 Correct 663 ms 22484 KB Output is correct
42 Correct 199 ms 15476 KB Output is correct
43 Correct 114 ms 11060 KB Output is correct
44 Correct 225 ms 20832 KB Output is correct
45 Correct 252 ms 21408 KB Output is correct
46 Correct 167 ms 11424 KB Output is correct
47 Correct 254 ms 11340 KB Output is correct
48 Correct 243 ms 11552 KB Output is correct
49 Correct 725 ms 22568 KB Output is correct
50 Correct 192 ms 15544 KB Output is correct
51 Correct 164 ms 13256 KB Output is correct
52 Correct 277 ms 21832 KB Output is correct
53 Correct 237 ms 21904 KB Output is correct
54 Correct 269 ms 22600 KB Output is correct
55 Correct 368 ms 22608 KB Output is correct