Submission #77951

# Submission time Handle Problem Language Result Execution time Memory
77951 2018-10-01T11:27:30 Z aminra Global Warming (CEOI18_glo) C++14
100 / 100
706 ms 32640 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int MOD = (int)1e9 + 7;
const int MAXN = (int)2e5 + 7;
const int infint = (int)1e9;
const ll inf = (ll)1e18;
int seg1[4 * MAXN], seg2[4 * MAXN], x, n, a[MAXN];
unordered_map<int, int> hsh, rev;
void add(int node, int st, int en, int idx, int val, bool c)
{
	if(en - st < 2)
	{
		if(c)
			seg1[node] = max(seg1[node], val);
		else
			seg2[node] = max(seg2[node], val);
		return;
	}
	int mid = (st + en) >> 1;
	if(idx < mid)
		add(node << 1, st, mid, idx, val, c);
	else
		add(node << 1 | 1, mid, en, idx, val, c);
	seg1[node] = max(seg1[node << 1], seg1[node << 1 | 1]);
	seg2[node] = max(seg2[node << 1], seg2[node << 1 | 1]);
}
int get(int node, int st, int en, int l, int r, int c)
{
	if(st >= r || l >= en)
		return 0;
	if(l <= st && en <= r)
	{
		if(c)
			return seg1[node];
		else
			return seg2[node];
	}
	int mid = (st + en) >> 1;
	return max(get(node << 1, st, mid, l, r, c), get(node << 1 | 1, mid, en, l, r, c));
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cin >> n >> x;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	set<int> S;
	for (int i = 0; i < n; i++)
		S.insert(a[i]);
	int cnt = 0;
	vector<int> v;
	for (auto u : S)
		v.push_back(u), hsh[u] = cnt, rev[cnt++] = u;
	add(1, 0, n, hsh[a[0]], 1, 0);
	add(1, 0, n, hsh[a[0]], 1, 1);
	for (int i = 1; i < n; i++)
	{
		int t = upper_bound(v.begin(), v.end(), a[i] + x - 1) - v.begin();
		int p = get(1, 0, n, 0, t, 1);
		if(hsh[a[i]] != 0)
			 p = max(p, get(1, 0, n, 0, hsh[a[i]], 0));
		add(1, 0, n, hsh[a[i]], p + 1, 0);	
		//--------------
		if(hsh[a[i]] == 0)
			p = 0;
		else
			p = get(1, 0, n, 0, hsh[a[i]], 1);
		add(1, 0, n, hsh[a[i]], p + 1, 1);
	}
	cout << get(1, 0, n, 0, n, 0) << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 564 KB Output is correct
3 Correct 2 ms 564 KB Output is correct
4 Correct 2 ms 564 KB Output is correct
5 Correct 2 ms 564 KB Output is correct
6 Correct 2 ms 564 KB Output is correct
7 Correct 2 ms 564 KB Output is correct
8 Correct 2 ms 564 KB Output is correct
9 Correct 2 ms 592 KB Output is correct
10 Correct 2 ms 592 KB Output is correct
11 Correct 2 ms 592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 564 KB Output is correct
3 Correct 2 ms 564 KB Output is correct
4 Correct 2 ms 564 KB Output is correct
5 Correct 2 ms 564 KB Output is correct
6 Correct 2 ms 564 KB Output is correct
7 Correct 2 ms 564 KB Output is correct
8 Correct 2 ms 564 KB Output is correct
9 Correct 2 ms 592 KB Output is correct
10 Correct 2 ms 592 KB Output is correct
11 Correct 2 ms 592 KB Output is correct
12 Correct 2 ms 608 KB Output is correct
13 Correct 2 ms 612 KB Output is correct
14 Correct 2 ms 636 KB Output is correct
15 Correct 2 ms 636 KB Output is correct
16 Correct 5 ms 640 KB Output is correct
17 Correct 2 ms 644 KB Output is correct
18 Correct 2 ms 648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 564 KB Output is correct
3 Correct 2 ms 564 KB Output is correct
4 Correct 2 ms 564 KB Output is correct
5 Correct 2 ms 564 KB Output is correct
6 Correct 2 ms 564 KB Output is correct
7 Correct 2 ms 564 KB Output is correct
8 Correct 2 ms 564 KB Output is correct
9 Correct 2 ms 592 KB Output is correct
10 Correct 2 ms 592 KB Output is correct
11 Correct 2 ms 592 KB Output is correct
12 Correct 2 ms 608 KB Output is correct
13 Correct 2 ms 612 KB Output is correct
14 Correct 2 ms 636 KB Output is correct
15 Correct 2 ms 636 KB Output is correct
16 Correct 5 ms 640 KB Output is correct
17 Correct 2 ms 644 KB Output is correct
18 Correct 2 ms 648 KB Output is correct
19 Correct 5 ms 908 KB Output is correct
20 Correct 4 ms 908 KB Output is correct
21 Correct 3 ms 908 KB Output is correct
22 Correct 5 ms 908 KB Output is correct
23 Correct 3 ms 908 KB Output is correct
24 Correct 3 ms 908 KB Output is correct
25 Correct 3 ms 908 KB Output is correct
26 Correct 3 ms 908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 698 ms 32048 KB Output is correct
2 Correct 702 ms 32048 KB Output is correct
3 Correct 681 ms 32064 KB Output is correct
4 Correct 706 ms 32200 KB Output is correct
5 Correct 298 ms 32200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 132 ms 32200 KB Output is correct
2 Correct 134 ms 32200 KB Output is correct
3 Correct 135 ms 32200 KB Output is correct
4 Correct 67 ms 32200 KB Output is correct
5 Correct 2 ms 32200 KB Output is correct
6 Correct 59 ms 32200 KB Output is correct
7 Correct 100 ms 32200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 280 ms 32200 KB Output is correct
2 Correct 377 ms 32200 KB Output is correct
3 Correct 660 ms 32200 KB Output is correct
4 Correct 296 ms 32200 KB Output is correct
5 Correct 146 ms 32200 KB Output is correct
6 Correct 262 ms 32200 KB Output is correct
7 Correct 271 ms 32200 KB Output is correct
8 Correct 194 ms 32200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 564 KB Output is correct
3 Correct 2 ms 564 KB Output is correct
4 Correct 2 ms 564 KB Output is correct
5 Correct 2 ms 564 KB Output is correct
6 Correct 2 ms 564 KB Output is correct
7 Correct 2 ms 564 KB Output is correct
8 Correct 2 ms 564 KB Output is correct
9 Correct 2 ms 592 KB Output is correct
10 Correct 2 ms 592 KB Output is correct
11 Correct 2 ms 592 KB Output is correct
12 Correct 2 ms 608 KB Output is correct
13 Correct 2 ms 612 KB Output is correct
14 Correct 2 ms 636 KB Output is correct
15 Correct 2 ms 636 KB Output is correct
16 Correct 5 ms 640 KB Output is correct
17 Correct 2 ms 644 KB Output is correct
18 Correct 2 ms 648 KB Output is correct
19 Correct 5 ms 908 KB Output is correct
20 Correct 4 ms 908 KB Output is correct
21 Correct 3 ms 908 KB Output is correct
22 Correct 5 ms 908 KB Output is correct
23 Correct 3 ms 908 KB Output is correct
24 Correct 3 ms 908 KB Output is correct
25 Correct 3 ms 908 KB Output is correct
26 Correct 3 ms 908 KB Output is correct
27 Correct 698 ms 32048 KB Output is correct
28 Correct 702 ms 32048 KB Output is correct
29 Correct 681 ms 32064 KB Output is correct
30 Correct 706 ms 32200 KB Output is correct
31 Correct 298 ms 32200 KB Output is correct
32 Correct 132 ms 32200 KB Output is correct
33 Correct 134 ms 32200 KB Output is correct
34 Correct 135 ms 32200 KB Output is correct
35 Correct 67 ms 32200 KB Output is correct
36 Correct 2 ms 32200 KB Output is correct
37 Correct 59 ms 32200 KB Output is correct
38 Correct 100 ms 32200 KB Output is correct
39 Correct 280 ms 32200 KB Output is correct
40 Correct 377 ms 32200 KB Output is correct
41 Correct 660 ms 32200 KB Output is correct
42 Correct 296 ms 32200 KB Output is correct
43 Correct 146 ms 32200 KB Output is correct
44 Correct 262 ms 32200 KB Output is correct
45 Correct 271 ms 32200 KB Output is correct
46 Correct 194 ms 32200 KB Output is correct
47 Correct 266 ms 32200 KB Output is correct
48 Correct 279 ms 32200 KB Output is correct
49 Correct 683 ms 32200 KB Output is correct
50 Correct 294 ms 32200 KB Output is correct
51 Correct 199 ms 32200 KB Output is correct
52 Correct 341 ms 32556 KB Output is correct
53 Correct 281 ms 32556 KB Output is correct
54 Correct 309 ms 32556 KB Output is correct
55 Correct 534 ms 32640 KB Output is correct