Submission #522077

# Submission time Handle Problem Language Result Execution time Memory
522077 2022-02-03T18:44:01 Z LucaDantas Global Warming (CEOI18_glo) C++17
100 / 100
619 ms 12120 KB
#include <cstdio>
#include <cstring>
#include <map>
#include <algorithm>

constexpr int maxn = 2e5+10;
constexpr unsigned int maxT = 0x7fffffff;

int coord = 0;
std::map<int,int> mp;

void build() {
	coord = 0;
	for(auto& x : mp)
		x.second = ++coord;
}

int norm(int x) {
	auto k = mp.upper_bound(x);
	if(k == mp.end()) return coord;
	return k->second-1;
}

struct BIT {
	int bit[maxn];
	void upd(int x, int v) {
		x = norm(x);
		for(x++; x < maxn; x += x&-x)
			bit[x] = std::max(bit[x], v);
	}
	int query(int x) {
		int ans = 0;
		x = norm(x);
		for(x++; x > 0; x -= x&-x)
			ans = std::max(ans, bit[x]);
		return ans;
	}
	void clear() { memset(bit, 0, sizeof bit); }
} bit;

int t[maxn], dp[maxn], max_temp;

int main() {
	int n, x; scanf("%d %d", &n, &x);
	for(int i = 0; i < n; i++)
		scanf("%d", t+i), max_temp = std::max(max_temp, t[i]), mp[t[i]] = 0;
	build();

	for(int i = 0; i < n; i++) {
		dp[i] = bit.query(t[i]-1)+1;
		bit.upd(t[i], dp[i]);
	}

	bit.clear();

	int ans = 0;
	std::reverse(t, t+n);
	std::reverse(dp, dp+n);
	mp.clear();
	for(int i = 0; i < n; i++)
		t[i] = max_temp - t[i] + 1, mp[t[i]] = 0;
	build();

	for(int i = 0; i < n; i++) {
		ans = std::max(ans, dp[i] + bit.query(t[i] + x - 1));
		bit.upd(t[i], bit.query(t[i]-1)+1);
	}

	printf("%d\n", ans);
}

Compilation message

glo.cpp: In function 'int main()':
glo.cpp:44:17: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |  int n, x; scanf("%d %d", &n, &x);
      |            ~~~~~^~~~~~~~~~~~~~~~~
glo.cpp:46:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |   scanf("%d", t+i), max_temp = std::max(max_temp, t[i]), mp[t[i]] = 0;
      |   ~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 972 KB Output is correct
2 Correct 1 ms 972 KB Output is correct
3 Correct 1 ms 972 KB Output is correct
4 Correct 1 ms 972 KB Output is correct
5 Correct 1 ms 972 KB Output is correct
6 Correct 1 ms 972 KB Output is correct
7 Correct 1 ms 972 KB Output is correct
8 Correct 1 ms 972 KB Output is correct
9 Correct 1 ms 972 KB Output is correct
10 Correct 1 ms 972 KB Output is correct
11 Correct 1 ms 1016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 972 KB Output is correct
2 Correct 1 ms 972 KB Output is correct
3 Correct 1 ms 972 KB Output is correct
4 Correct 1 ms 972 KB Output is correct
5 Correct 1 ms 972 KB Output is correct
6 Correct 1 ms 972 KB Output is correct
7 Correct 1 ms 972 KB Output is correct
8 Correct 1 ms 972 KB Output is correct
9 Correct 1 ms 972 KB Output is correct
10 Correct 1 ms 972 KB Output is correct
11 Correct 1 ms 1016 KB Output is correct
12 Correct 1 ms 972 KB Output is correct
13 Correct 1 ms 972 KB Output is correct
14 Correct 1 ms 972 KB Output is correct
15 Correct 1 ms 972 KB Output is correct
16 Correct 1 ms 972 KB Output is correct
17 Correct 1 ms 972 KB Output is correct
18 Correct 1 ms 972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 972 KB Output is correct
2 Correct 1 ms 972 KB Output is correct
3 Correct 1 ms 972 KB Output is correct
4 Correct 1 ms 972 KB Output is correct
5 Correct 1 ms 972 KB Output is correct
6 Correct 1 ms 972 KB Output is correct
7 Correct 1 ms 972 KB Output is correct
8 Correct 1 ms 972 KB Output is correct
9 Correct 1 ms 972 KB Output is correct
10 Correct 1 ms 972 KB Output is correct
11 Correct 1 ms 1016 KB Output is correct
12 Correct 1 ms 972 KB Output is correct
13 Correct 1 ms 972 KB Output is correct
14 Correct 1 ms 972 KB Output is correct
15 Correct 1 ms 972 KB Output is correct
16 Correct 1 ms 972 KB Output is correct
17 Correct 1 ms 972 KB Output is correct
18 Correct 1 ms 972 KB Output is correct
19 Correct 2 ms 1100 KB Output is correct
20 Correct 2 ms 1100 KB Output is correct
21 Correct 3 ms 1100 KB Output is correct
22 Correct 2 ms 1100 KB Output is correct
23 Correct 1 ms 1100 KB Output is correct
24 Correct 1 ms 1100 KB Output is correct
25 Correct 1 ms 1100 KB Output is correct
26 Correct 1 ms 1100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 506 ms 11948 KB Output is correct
2 Correct 532 ms 11932 KB Output is correct
3 Correct 513 ms 11996 KB Output is correct
4 Correct 502 ms 12004 KB Output is correct
5 Correct 159 ms 7308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 72 ms 3700 KB Output is correct
2 Correct 72 ms 3780 KB Output is correct
3 Correct 75 ms 3788 KB Output is correct
4 Correct 33 ms 2620 KB Output is correct
5 Correct 1 ms 972 KB Output is correct
6 Correct 33 ms 2616 KB Output is correct
7 Correct 53 ms 3788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 207 ms 6528 KB Output is correct
2 Correct 156 ms 6440 KB Output is correct
3 Correct 505 ms 12000 KB Output is correct
4 Correct 169 ms 7256 KB Output is correct
5 Correct 89 ms 6448 KB Output is correct
6 Correct 167 ms 11460 KB Output is correct
7 Correct 183 ms 11472 KB Output is correct
8 Correct 149 ms 6436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 972 KB Output is correct
2 Correct 1 ms 972 KB Output is correct
3 Correct 1 ms 972 KB Output is correct
4 Correct 1 ms 972 KB Output is correct
5 Correct 1 ms 972 KB Output is correct
6 Correct 1 ms 972 KB Output is correct
7 Correct 1 ms 972 KB Output is correct
8 Correct 1 ms 972 KB Output is correct
9 Correct 1 ms 972 KB Output is correct
10 Correct 1 ms 972 KB Output is correct
11 Correct 1 ms 1016 KB Output is correct
12 Correct 1 ms 972 KB Output is correct
13 Correct 1 ms 972 KB Output is correct
14 Correct 1 ms 972 KB Output is correct
15 Correct 1 ms 972 KB Output is correct
16 Correct 1 ms 972 KB Output is correct
17 Correct 1 ms 972 KB Output is correct
18 Correct 1 ms 972 KB Output is correct
19 Correct 2 ms 1100 KB Output is correct
20 Correct 2 ms 1100 KB Output is correct
21 Correct 3 ms 1100 KB Output is correct
22 Correct 2 ms 1100 KB Output is correct
23 Correct 1 ms 1100 KB Output is correct
24 Correct 1 ms 1100 KB Output is correct
25 Correct 1 ms 1100 KB Output is correct
26 Correct 1 ms 1100 KB Output is correct
27 Correct 506 ms 11948 KB Output is correct
28 Correct 532 ms 11932 KB Output is correct
29 Correct 513 ms 11996 KB Output is correct
30 Correct 502 ms 12004 KB Output is correct
31 Correct 159 ms 7308 KB Output is correct
32 Correct 72 ms 3700 KB Output is correct
33 Correct 72 ms 3780 KB Output is correct
34 Correct 75 ms 3788 KB Output is correct
35 Correct 33 ms 2620 KB Output is correct
36 Correct 1 ms 972 KB Output is correct
37 Correct 33 ms 2616 KB Output is correct
38 Correct 53 ms 3788 KB Output is correct
39 Correct 207 ms 6528 KB Output is correct
40 Correct 156 ms 6440 KB Output is correct
41 Correct 505 ms 12000 KB Output is correct
42 Correct 169 ms 7256 KB Output is correct
43 Correct 89 ms 6448 KB Output is correct
44 Correct 167 ms 11460 KB Output is correct
45 Correct 183 ms 11472 KB Output is correct
46 Correct 149 ms 6436 KB Output is correct
47 Correct 215 ms 6468 KB Output is correct
48 Correct 170 ms 6532 KB Output is correct
49 Correct 619 ms 11908 KB Output is correct
50 Correct 159 ms 7264 KB Output is correct
51 Correct 115 ms 6796 KB Output is correct
52 Correct 218 ms 12120 KB Output is correct
53 Correct 179 ms 11972 KB Output is correct
54 Correct 192 ms 12120 KB Output is correct
55 Correct 274 ms 11888 KB Output is correct