Submission #1022889

# Submission time Handle Problem Language Result Execution time Memory
1022889 2024-07-14T07:13:05 Z vjudge1 Radio Towers (IOI22_towers) C++17
41 / 100
4000 ms 267952 KB
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;

const int maxn = 1e5 + 100;

int n, k;
int a[maxn];
int t[maxn];
int dp[maxn];
vector<pii> g[maxn];
int l[maxn];
int r[maxn];
int pref[maxn];

void upd(int i, int x){
	for(; i <= n; i |= (i + 1)) t[i] = max(t[i], x);
}

int get(int i){
	int res = 0;
	for(; i > 0; i = (i & (i + 1)) - 1) res = max(res, t[i]);
	return res;
}

void init(int N, std::vector<int> H){
	n = N; 
	for(int i = 1; i <= n; i++){
		a[i] = H[i-1];
	}
	k = 1;
	while(k < n && a[k+1] > a[k]) k++;
	for(int i = k + 1; i <= n; i++){
		if(a[i-1] < a[i]) k = 0;
	}
	for(int i = 1; i <= n; i++){
		pref[i] = pref[i-1];
		if(a[i] < min(a[i+1], a[i-1])) pref[i]++;
	}
}

int max_towers(int L, int R, int D){
	if(L == R) return 1;
	L++; R++;
	if(k){
		if(L < k && k < R && max(a[L], a[R]) + D <= a[k]) return 2;
		return 1;
	}
	if(D == 1){
		int ans = pref[R-1] - pref[L];
		if(a[L] < a[L+1]) ans++;
		if(a[R] < a[R-1]) ans++;
		return ans;
	}
	for(int i = 1; i <= n; i++){
		t[i] = 0;
		g[i].clear();
	}
	vector<int> v;
	for(int i = L; i <= R; i++){
		while(v.size() && a[v.back()] <= a[i]) v.pop_back();
		v.push_back(i);
		l[i] = L - 1;
		for(int tl = 0, tr = v.size() - 1; tl <= tr;){
			int mid = (tl + tr) >> 1;
			if(a[v[mid]] - D < a[i]) tr = mid - 1;
			else tl = mid + 1, l[i] = v[mid];
		}
	}
	v.clear();
	for(int i = R; i >= L; i--){
		while(v.size() && a[v.back()] <= a[i]) v.pop_back();
		v.push_back(i);
		r[i] = R + 1;
		for(int tl = 0, tr = v.size() - 1; tl <= tr;){
			int mid = (tl + tr) >> 1;
			if(a[v[mid]] - D < a[i]) tr = mid - 1;
			else tl = mid + 1, r[i] = v[mid];
		}
	}
	int ans = 0;
	for(int i = L; i <= R; i++){
		for(auto [p, x]: g[i]){
			upd(p, x);
		}
		dp[i] = get(l[i]) + 1;
		g[r[i]].push_back({i, dp[i]});
		ans = max(ans, dp[i]);
	}
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 333 ms 5208 KB Output is correct
2 Correct 644 ms 5720 KB Output is correct
3 Correct 630 ms 5720 KB Output is correct
4 Correct 603 ms 5720 KB Output is correct
5 Correct 664 ms 4952 KB Output is correct
6 Correct 634 ms 5720 KB Output is correct
7 Correct 650 ms 5720 KB Output is correct
8 Correct 1 ms 4440 KB Output is correct
9 Correct 1 ms 4440 KB Output is correct
10 Correct 1 ms 3672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3672 KB Output is correct
2 Correct 2 ms 3672 KB Output is correct
3 Correct 2 ms 3672 KB Output is correct
4 Correct 1 ms 4548 KB Output is correct
5 Correct 1 ms 4440 KB Output is correct
6 Correct 1 ms 3672 KB Output is correct
7 Correct 1 ms 4440 KB Output is correct
8 Correct 1 ms 3672 KB Output is correct
9 Correct 1 ms 3672 KB Output is correct
10 Correct 1 ms 4440 KB Output is correct
11 Correct 1 ms 4440 KB Output is correct
12 Correct 1 ms 4440 KB Output is correct
13 Correct 1 ms 3672 KB Output is correct
14 Correct 1 ms 4440 KB Output is correct
15 Correct 1 ms 4440 KB Output is correct
16 Correct 1 ms 4440 KB Output is correct
17 Correct 1 ms 4692 KB Output is correct
18 Correct 1 ms 4440 KB Output is correct
19 Correct 1 ms 3672 KB Output is correct
20 Correct 1 ms 3672 KB Output is correct
21 Correct 1 ms 3672 KB Output is correct
22 Correct 2 ms 3924 KB Output is correct
23 Correct 2 ms 3672 KB Output is correct
24 Correct 1 ms 3672 KB Output is correct
25 Correct 1 ms 3672 KB Output is correct
26 Correct 1 ms 3672 KB Output is correct
27 Correct 1 ms 4440 KB Output is correct
28 Correct 1 ms 4440 KB Output is correct
29 Correct 2 ms 4440 KB Output is correct
30 Correct 1 ms 4440 KB Output is correct
31 Correct 1 ms 4440 KB Output is correct
32 Correct 1 ms 3672 KB Output is correct
33 Correct 1 ms 3672 KB Output is correct
34 Correct 1 ms 3672 KB Output is correct
35 Correct 1 ms 4440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3672 KB Output is correct
2 Correct 2 ms 3672 KB Output is correct
3 Correct 2 ms 3672 KB Output is correct
4 Correct 1 ms 4548 KB Output is correct
5 Correct 1 ms 4440 KB Output is correct
6 Correct 1 ms 3672 KB Output is correct
7 Correct 1 ms 4440 KB Output is correct
8 Correct 1 ms 3672 KB Output is correct
9 Correct 1 ms 3672 KB Output is correct
10 Correct 1 ms 4440 KB Output is correct
11 Correct 1 ms 4440 KB Output is correct
12 Correct 1 ms 4440 KB Output is correct
13 Correct 1 ms 3672 KB Output is correct
14 Correct 1 ms 4440 KB Output is correct
15 Correct 1 ms 4440 KB Output is correct
16 Correct 1 ms 4440 KB Output is correct
17 Correct 1 ms 4692 KB Output is correct
18 Correct 1 ms 4440 KB Output is correct
19 Correct 1 ms 3672 KB Output is correct
20 Correct 1 ms 3672 KB Output is correct
21 Correct 1 ms 3672 KB Output is correct
22 Correct 2 ms 3924 KB Output is correct
23 Correct 2 ms 3672 KB Output is correct
24 Correct 1 ms 3672 KB Output is correct
25 Correct 1 ms 3672 KB Output is correct
26 Correct 1 ms 3672 KB Output is correct
27 Correct 1 ms 4440 KB Output is correct
28 Correct 1 ms 4440 KB Output is correct
29 Correct 2 ms 4440 KB Output is correct
30 Correct 1 ms 4440 KB Output is correct
31 Correct 1 ms 4440 KB Output is correct
32 Correct 1 ms 3672 KB Output is correct
33 Correct 1 ms 3672 KB Output is correct
34 Correct 1 ms 3672 KB Output is correct
35 Correct 1 ms 4440 KB Output is correct
36 Correct 8 ms 5464 KB Output is correct
37 Correct 11 ms 5940 KB Output is correct
38 Correct 12 ms 5720 KB Output is correct
39 Correct 11 ms 5840 KB Output is correct
40 Correct 11 ms 5720 KB Output is correct
41 Correct 16 ms 6352 KB Output is correct
42 Correct 16 ms 4304 KB Output is correct
43 Correct 18 ms 4180 KB Output is correct
44 Correct 9 ms 4180 KB Output is correct
45 Correct 9 ms 5072 KB Output is correct
46 Correct 12 ms 4344 KB Output is correct
47 Correct 9 ms 4184 KB Output is correct
48 Correct 9 ms 4184 KB Output is correct
49 Correct 9 ms 4952 KB Output is correct
50 Correct 15 ms 4220 KB Output is correct
51 Correct 9 ms 4184 KB Output is correct
52 Correct 9 ms 4332 KB Output is correct
53 Correct 9 ms 4184 KB Output is correct
54 Correct 9 ms 4184 KB Output is correct
55 Correct 9 ms 4184 KB Output is correct
56 Correct 10 ms 5720 KB Output is correct
57 Correct 22 ms 6576 KB Output is correct
58 Correct 29 ms 6856 KB Output is correct
59 Correct 19 ms 6820 KB Output is correct
60 Correct 17 ms 7344 KB Output is correct
61 Correct 22 ms 7124 KB Output is correct
62 Correct 18 ms 6864 KB Output is correct
63 Correct 16 ms 7372 KB Output is correct
64 Correct 9 ms 5720 KB Output is correct
65 Correct 10 ms 5720 KB Output is correct
66 Correct 30 ms 7264 KB Output is correct
67 Correct 24 ms 7368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 464 ms 5720 KB Output is correct
2 Correct 638 ms 5068 KB Output is correct
3 Correct 711 ms 5720 KB Output is correct
4 Correct 645 ms 5720 KB Output is correct
5 Correct 676 ms 5720 KB Output is correct
6 Correct 663 ms 5720 KB Output is correct
7 Correct 558 ms 5720 KB Output is correct
8 Correct 646 ms 5872 KB Output is correct
9 Correct 597 ms 5684 KB Output is correct
10 Correct 635 ms 5724 KB Output is correct
11 Correct 572 ms 4952 KB Output is correct
12 Correct 584 ms 5720 KB Output is correct
13 Correct 592 ms 5720 KB Output is correct
14 Correct 1 ms 4440 KB Output is correct
15 Correct 1 ms 4440 KB Output is correct
16 Correct 1 ms 4440 KB Output is correct
17 Correct 9 ms 4952 KB Output is correct
18 Correct 10 ms 4968 KB Output is correct
19 Correct 9 ms 5720 KB Output is correct
20 Correct 9 ms 5820 KB Output is correct
21 Correct 9 ms 5720 KB Output is correct
22 Correct 15 ms 5708 KB Output is correct
23 Correct 9 ms 5720 KB Output is correct
24 Correct 13 ms 5720 KB Output is correct
25 Correct 9 ms 4968 KB Output is correct
26 Correct 9 ms 5720 KB Output is correct
27 Correct 1 ms 4440 KB Output is correct
28 Correct 1 ms 4440 KB Output is correct
29 Correct 2 ms 4532 KB Output is correct
30 Correct 1 ms 4440 KB Output is correct
31 Correct 1 ms 4440 KB Output is correct
32 Correct 1 ms 4440 KB Output is correct
33 Correct 2 ms 4440 KB Output is correct
34 Correct 1 ms 4440 KB Output is correct
35 Correct 1 ms 4440 KB Output is correct
36 Correct 2 ms 4440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 4025 ms 267952 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3672 KB Output is correct
2 Correct 2 ms 3672 KB Output is correct
3 Correct 2 ms 3672 KB Output is correct
4 Correct 1 ms 4548 KB Output is correct
5 Correct 1 ms 4440 KB Output is correct
6 Correct 1 ms 3672 KB Output is correct
7 Correct 1 ms 4440 KB Output is correct
8 Correct 1 ms 3672 KB Output is correct
9 Correct 1 ms 3672 KB Output is correct
10 Correct 1 ms 4440 KB Output is correct
11 Correct 1 ms 4440 KB Output is correct
12 Correct 1 ms 4440 KB Output is correct
13 Correct 1 ms 3672 KB Output is correct
14 Correct 1 ms 4440 KB Output is correct
15 Correct 1 ms 4440 KB Output is correct
16 Correct 1 ms 4440 KB Output is correct
17 Correct 1 ms 4692 KB Output is correct
18 Correct 1 ms 4440 KB Output is correct
19 Correct 1 ms 3672 KB Output is correct
20 Correct 1 ms 3672 KB Output is correct
21 Correct 1 ms 3672 KB Output is correct
22 Correct 2 ms 3924 KB Output is correct
23 Correct 2 ms 3672 KB Output is correct
24 Correct 1 ms 3672 KB Output is correct
25 Correct 1 ms 3672 KB Output is correct
26 Correct 1 ms 3672 KB Output is correct
27 Correct 1 ms 4440 KB Output is correct
28 Correct 1 ms 4440 KB Output is correct
29 Correct 2 ms 4440 KB Output is correct
30 Correct 1 ms 4440 KB Output is correct
31 Correct 1 ms 4440 KB Output is correct
32 Correct 1 ms 3672 KB Output is correct
33 Correct 1 ms 3672 KB Output is correct
34 Correct 1 ms 3672 KB Output is correct
35 Correct 1 ms 4440 KB Output is correct
36 Correct 8 ms 5464 KB Output is correct
37 Correct 11 ms 5940 KB Output is correct
38 Correct 12 ms 5720 KB Output is correct
39 Correct 11 ms 5840 KB Output is correct
40 Correct 11 ms 5720 KB Output is correct
41 Correct 16 ms 6352 KB Output is correct
42 Correct 16 ms 4304 KB Output is correct
43 Correct 18 ms 4180 KB Output is correct
44 Correct 9 ms 4180 KB Output is correct
45 Correct 9 ms 5072 KB Output is correct
46 Correct 12 ms 4344 KB Output is correct
47 Correct 9 ms 4184 KB Output is correct
48 Correct 9 ms 4184 KB Output is correct
49 Correct 9 ms 4952 KB Output is correct
50 Correct 15 ms 4220 KB Output is correct
51 Correct 9 ms 4184 KB Output is correct
52 Correct 9 ms 4332 KB Output is correct
53 Correct 9 ms 4184 KB Output is correct
54 Correct 9 ms 4184 KB Output is correct
55 Correct 9 ms 4184 KB Output is correct
56 Correct 10 ms 5720 KB Output is correct
57 Correct 22 ms 6576 KB Output is correct
58 Correct 29 ms 6856 KB Output is correct
59 Correct 19 ms 6820 KB Output is correct
60 Correct 17 ms 7344 KB Output is correct
61 Correct 22 ms 7124 KB Output is correct
62 Correct 18 ms 6864 KB Output is correct
63 Correct 16 ms 7372 KB Output is correct
64 Correct 9 ms 5720 KB Output is correct
65 Correct 10 ms 5720 KB Output is correct
66 Correct 30 ms 7264 KB Output is correct
67 Correct 24 ms 7368 KB Output is correct
68 Correct 464 ms 5720 KB Output is correct
69 Correct 638 ms 5068 KB Output is correct
70 Correct 711 ms 5720 KB Output is correct
71 Correct 645 ms 5720 KB Output is correct
72 Correct 676 ms 5720 KB Output is correct
73 Correct 663 ms 5720 KB Output is correct
74 Correct 558 ms 5720 KB Output is correct
75 Correct 646 ms 5872 KB Output is correct
76 Correct 597 ms 5684 KB Output is correct
77 Correct 635 ms 5724 KB Output is correct
78 Correct 572 ms 4952 KB Output is correct
79 Correct 584 ms 5720 KB Output is correct
80 Correct 592 ms 5720 KB Output is correct
81 Correct 1 ms 4440 KB Output is correct
82 Correct 1 ms 4440 KB Output is correct
83 Correct 1 ms 4440 KB Output is correct
84 Correct 9 ms 4952 KB Output is correct
85 Correct 10 ms 4968 KB Output is correct
86 Correct 9 ms 5720 KB Output is correct
87 Correct 9 ms 5820 KB Output is correct
88 Correct 9 ms 5720 KB Output is correct
89 Correct 15 ms 5708 KB Output is correct
90 Correct 9 ms 5720 KB Output is correct
91 Correct 13 ms 5720 KB Output is correct
92 Correct 9 ms 4968 KB Output is correct
93 Correct 9 ms 5720 KB Output is correct
94 Correct 1 ms 4440 KB Output is correct
95 Correct 1 ms 4440 KB Output is correct
96 Correct 2 ms 4532 KB Output is correct
97 Correct 1 ms 4440 KB Output is correct
98 Correct 1 ms 4440 KB Output is correct
99 Correct 1 ms 4440 KB Output is correct
100 Correct 2 ms 4440 KB Output is correct
101 Correct 1 ms 4440 KB Output is correct
102 Correct 1 ms 4440 KB Output is correct
103 Correct 2 ms 4440 KB Output is correct
104 Execution timed out 4038 ms 66688 KB Time limit exceeded
105 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 333 ms 5208 KB Output is correct
2 Correct 644 ms 5720 KB Output is correct
3 Correct 630 ms 5720 KB Output is correct
4 Correct 603 ms 5720 KB Output is correct
5 Correct 664 ms 4952 KB Output is correct
6 Correct 634 ms 5720 KB Output is correct
7 Correct 650 ms 5720 KB Output is correct
8 Correct 1 ms 4440 KB Output is correct
9 Correct 1 ms 4440 KB Output is correct
10 Correct 1 ms 3672 KB Output is correct
11 Correct 1 ms 3672 KB Output is correct
12 Correct 2 ms 3672 KB Output is correct
13 Correct 2 ms 3672 KB Output is correct
14 Correct 1 ms 4548 KB Output is correct
15 Correct 1 ms 4440 KB Output is correct
16 Correct 1 ms 3672 KB Output is correct
17 Correct 1 ms 4440 KB Output is correct
18 Correct 1 ms 3672 KB Output is correct
19 Correct 1 ms 3672 KB Output is correct
20 Correct 1 ms 4440 KB Output is correct
21 Correct 1 ms 4440 KB Output is correct
22 Correct 1 ms 4440 KB Output is correct
23 Correct 1 ms 3672 KB Output is correct
24 Correct 1 ms 4440 KB Output is correct
25 Correct 1 ms 4440 KB Output is correct
26 Correct 1 ms 4440 KB Output is correct
27 Correct 1 ms 4692 KB Output is correct
28 Correct 1 ms 4440 KB Output is correct
29 Correct 1 ms 3672 KB Output is correct
30 Correct 1 ms 3672 KB Output is correct
31 Correct 1 ms 3672 KB Output is correct
32 Correct 2 ms 3924 KB Output is correct
33 Correct 2 ms 3672 KB Output is correct
34 Correct 1 ms 3672 KB Output is correct
35 Correct 1 ms 3672 KB Output is correct
36 Correct 1 ms 3672 KB Output is correct
37 Correct 1 ms 4440 KB Output is correct
38 Correct 1 ms 4440 KB Output is correct
39 Correct 2 ms 4440 KB Output is correct
40 Correct 1 ms 4440 KB Output is correct
41 Correct 1 ms 4440 KB Output is correct
42 Correct 1 ms 3672 KB Output is correct
43 Correct 1 ms 3672 KB Output is correct
44 Correct 1 ms 3672 KB Output is correct
45 Correct 1 ms 4440 KB Output is correct
46 Correct 8 ms 5464 KB Output is correct
47 Correct 11 ms 5940 KB Output is correct
48 Correct 12 ms 5720 KB Output is correct
49 Correct 11 ms 5840 KB Output is correct
50 Correct 11 ms 5720 KB Output is correct
51 Correct 16 ms 6352 KB Output is correct
52 Correct 16 ms 4304 KB Output is correct
53 Correct 18 ms 4180 KB Output is correct
54 Correct 9 ms 4180 KB Output is correct
55 Correct 9 ms 5072 KB Output is correct
56 Correct 12 ms 4344 KB Output is correct
57 Correct 9 ms 4184 KB Output is correct
58 Correct 9 ms 4184 KB Output is correct
59 Correct 9 ms 4952 KB Output is correct
60 Correct 15 ms 4220 KB Output is correct
61 Correct 9 ms 4184 KB Output is correct
62 Correct 9 ms 4332 KB Output is correct
63 Correct 9 ms 4184 KB Output is correct
64 Correct 9 ms 4184 KB Output is correct
65 Correct 9 ms 4184 KB Output is correct
66 Correct 10 ms 5720 KB Output is correct
67 Correct 22 ms 6576 KB Output is correct
68 Correct 29 ms 6856 KB Output is correct
69 Correct 19 ms 6820 KB Output is correct
70 Correct 17 ms 7344 KB Output is correct
71 Correct 22 ms 7124 KB Output is correct
72 Correct 18 ms 6864 KB Output is correct
73 Correct 16 ms 7372 KB Output is correct
74 Correct 9 ms 5720 KB Output is correct
75 Correct 10 ms 5720 KB Output is correct
76 Correct 30 ms 7264 KB Output is correct
77 Correct 24 ms 7368 KB Output is correct
78 Correct 464 ms 5720 KB Output is correct
79 Correct 638 ms 5068 KB Output is correct
80 Correct 711 ms 5720 KB Output is correct
81 Correct 645 ms 5720 KB Output is correct
82 Correct 676 ms 5720 KB Output is correct
83 Correct 663 ms 5720 KB Output is correct
84 Correct 558 ms 5720 KB Output is correct
85 Correct 646 ms 5872 KB Output is correct
86 Correct 597 ms 5684 KB Output is correct
87 Correct 635 ms 5724 KB Output is correct
88 Correct 572 ms 4952 KB Output is correct
89 Correct 584 ms 5720 KB Output is correct
90 Correct 592 ms 5720 KB Output is correct
91 Correct 1 ms 4440 KB Output is correct
92 Correct 1 ms 4440 KB Output is correct
93 Correct 1 ms 4440 KB Output is correct
94 Correct 9 ms 4952 KB Output is correct
95 Correct 10 ms 4968 KB Output is correct
96 Correct 9 ms 5720 KB Output is correct
97 Correct 9 ms 5820 KB Output is correct
98 Correct 9 ms 5720 KB Output is correct
99 Correct 15 ms 5708 KB Output is correct
100 Correct 9 ms 5720 KB Output is correct
101 Correct 13 ms 5720 KB Output is correct
102 Correct 9 ms 4968 KB Output is correct
103 Correct 9 ms 5720 KB Output is correct
104 Correct 1 ms 4440 KB Output is correct
105 Correct 1 ms 4440 KB Output is correct
106 Correct 2 ms 4532 KB Output is correct
107 Correct 1 ms 4440 KB Output is correct
108 Correct 1 ms 4440 KB Output is correct
109 Correct 1 ms 4440 KB Output is correct
110 Correct 2 ms 4440 KB Output is correct
111 Correct 1 ms 4440 KB Output is correct
112 Correct 1 ms 4440 KB Output is correct
113 Correct 2 ms 4440 KB Output is correct
114 Execution timed out 4025 ms 267952 KB Time limit exceeded
115 Halted 0 ms 0 KB -