Submission #720866

# Submission time Handle Problem Language Result Execution time Memory
720866 2023-04-09T15:36:22 Z WonderfulWhale Global Warming (CEOI18_glo) C++17
100 / 100
355 ms 15356 KB
#include<bits/stdc++.h>
using namespace std;

#define pb push_back
#define st first
#define nd second
#define pii pair<int, int>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()

struct SegTree {
	const static int T = 1<<18;
	int t[2*T];
	void update(int x, int val) {
		x+=T;
		t[x] = max(t[x], val);
		x/=2;
		while(x) {
			t[x] = max(t[2*x], t[2*x+1]);
			x/=2;
		}
	}
	int query(int l, int r) {
		l+=T;
		r+=T;
		int ret = max(t[l], t[r]);
		while(l/2!=r/2) {
			if(l%2==0) ret = max(ret, t[l+1]);
			if(r%2==1) ret = max(ret, t[r-1]);
			l/=2;
			r/=2;
		}
		return ret;
	}
} seg1, seg2;

map<int, int> M;

int tab[200009];

int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n, d;
	cin >> n >> d;
	vector<int> v;
	for(int i=0;i<n;i++) {
		cin >> tab[i];
		v.pb(tab[i]);
	}
	sort(all(v));
	v.erase(unique(all(v)), v.end());
	for(int i=0;i<sz(v);i++) {
		M[v[i]] = i;
	}
	for(int i=0;i<n;i++) {
		int pos = M[tab[i]];
		auto it1 = M.upper_bound(tab[i]-1);
		auto it2 = M.upper_bound(tab[i]+d-1);
		if(it2!=M.begin()) {
			it2--;
			seg2.update(pos, 1+seg1.query(0, it2->nd));
		} else {
			seg2.update(pos, 1);
		}
		if(it1!=M.begin()) {
			it1--;
			seg2.update(pos, 1+seg2.query(0, it1->nd));
			seg1.update(pos, 1+seg1.query(0, it1->nd));
		} else {
			seg2.update(pos, 1);
			seg1.update(pos, 1);
		}
	}
	cout << seg2.query(0, n) << "\n";
}

# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 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 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 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 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 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 424 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 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 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 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 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 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 424 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 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 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 468 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 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 343 ms 15256 KB Output is correct
2 Correct 355 ms 15316 KB Output is correct
3 Correct 349 ms 15336 KB Output is correct
4 Correct 330 ms 15328 KB Output is correct
5 Correct 131 ms 9024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 56 ms 3936 KB Output is correct
2 Correct 58 ms 3892 KB Output is correct
3 Correct 57 ms 3948 KB Output is correct
4 Correct 28 ms 2380 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 34 ms 2360 KB Output is correct
7 Correct 50 ms 3936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 133 ms 8324 KB Output is correct
2 Correct 129 ms 8292 KB Output is correct
3 Correct 343 ms 15356 KB Output is correct
4 Correct 142 ms 9032 KB Output is correct
5 Correct 89 ms 7904 KB Output is correct
6 Correct 183 ms 14720 KB Output is correct
7 Correct 179 ms 14656 KB Output is correct
8 Correct 109 ms 8276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 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 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 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 424 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 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 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 468 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 468 KB Output is correct
27 Correct 343 ms 15256 KB Output is correct
28 Correct 355 ms 15316 KB Output is correct
29 Correct 349 ms 15336 KB Output is correct
30 Correct 330 ms 15328 KB Output is correct
31 Correct 131 ms 9024 KB Output is correct
32 Correct 56 ms 3936 KB Output is correct
33 Correct 58 ms 3892 KB Output is correct
34 Correct 57 ms 3948 KB Output is correct
35 Correct 28 ms 2380 KB Output is correct
36 Correct 0 ms 340 KB Output is correct
37 Correct 34 ms 2360 KB Output is correct
38 Correct 50 ms 3936 KB Output is correct
39 Correct 133 ms 8324 KB Output is correct
40 Correct 129 ms 8292 KB Output is correct
41 Correct 343 ms 15356 KB Output is correct
42 Correct 142 ms 9032 KB Output is correct
43 Correct 89 ms 7904 KB Output is correct
44 Correct 183 ms 14720 KB Output is correct
45 Correct 179 ms 14656 KB Output is correct
46 Correct 109 ms 8276 KB Output is correct
47 Correct 143 ms 7900 KB Output is correct
48 Correct 132 ms 8004 KB Output is correct
49 Correct 324 ms 15084 KB Output is correct
50 Correct 135 ms 8732 KB Output is correct
51 Correct 128 ms 8336 KB Output is correct
52 Correct 188 ms 14912 KB Output is correct
53 Correct 184 ms 14872 KB Output is correct
54 Correct 186 ms 15000 KB Output is correct
55 Correct 240 ms 14920 KB Output is correct