Submission #940740

# Submission time Handle Problem Language Result Execution time Memory
940740 2024-03-07T14:39:11 Z Trisanu_Das Radio Towers (IOI22_towers) C++17
54 / 100
4000 ms 9724 KB
#include <bits/stdc++.h>
using namespace std;
 
const int MAXN = 1e5, half = 1e5+1;
int n, a[MAXN],segt[200003],psum[MAXN+1];
vector<pair<int,int>> answers;
 
int query(int l, int r){
	l += half;
	r += half;
	int ans = 0;
	while (l <= r){
		if (l&1){
			ans = max(ans,segt[l]);
			l++;
		}
		if (r%2 == 0){
			ans = max(ans,segt[r]);
			r--;
		}
		l >>= 1;
		r >>= 1;
	}
	return ans;
}
 
void modify(int node, int val){
	node += half;
	segt[node] = val;
	node >>= 1;
	while (node){
		segt[node] = max(segt[2*node],segt[2*node+1]);
		node >>= 1;
	}
}
 
void init(int N, vector<int> H){
	n = N;
	for (int i=0; i<n; ++i){
		a[i] = H[i];
		modify(i,a[i]);
	}
	for (int i=0; i<n; ++i){
		if ((i == 0 or a[i] < a[i-1]) and (i == n-1 or a[i] < a[i+1])){
			psum[i+1]++;
		}
		psum[i+1] += psum[i];
	}
	vector<pair<int,int>> v,deltas;
	for (int i=0; i<n; ++i){
		v.emplace_back(a[i],i);
	}
	sort(v.begin(),v.end());
	set<int> pos = {INT_MIN,INT_MAX};
	for (auto i:v){
		auto it = pos.upper_bound(i.second);
		int A = *it,maxi=INT_MAX;
		it--;
		int B = *it;
		bool ok = false;
		if (A != INT_MAX){
			if (i.second == A-1) ok = true;
			maxi = min(maxi,query(i.second,A));
		}
		if (B != INT_MIN){
			if (B == i.second-1) ok = true;
			maxi = min(maxi,query(B,i.second));
		}
		if (maxi != i.first and !ok){
			if (maxi == INT_MAX) deltas.emplace_back(maxi,i.second);
			else deltas.emplace_back(max(1,maxi-i.first),i.second);
		}
		pos.emplace(i.second);
	}
	sort(deltas.rbegin(),deltas.rend());
	int val = INT_MAX, occ = 0;
	for (auto i:deltas){
		if (val == i.first){
			++occ;
		}
		else{
			answers.emplace_back(val,occ);
			val = i.first;
			occ++;
		}
	}
	answers.emplace_back(val,occ);
	reverse(answers.begin(),answers.end());
}
int max_towers(int L, int R, int D){
	if (L == 0 and R == n-1){
		int idx = lower_bound(answers.begin(),answers.end(),make_pair(D,0))-answers.begin();
		return answers[idx].second;
	}
	if (D == 1){
		int ans = 0;
		if (L < R and a[L] < a[L+1]) ++ans;
		if (L < R and a[R] < a[R-1]) ++ans;
		L++; R++;
		if (L == R) return 1;
		return psum[R-1]-psum[L]+ans;
	}
	set<int> st;
	vector<pair<int,int>> v;
	for (int i=L; i<=R; ++i){
		v.emplace_back(a[i],i);
	}
	sort(v.begin(),v.end());
	int ans = 0;
	for (auto k:v){
		int i = k.second;
		if (st.empty()){
			st.emplace(i);
			++ans;
			continue;
		}
		auto it = st.upper_bound(i);
		int A = *it;
		--it;
		int B = *it;
		if ((*st.rbegin() < i or query(i,A)-D >= max(a[A],a[i])) and (*st.begin() > i or query(B,i)-D >= max(a[B],a[i]))){
			st.emplace(i);
			++ans;
		}
	}
	return ans;
}
# Verdict Execution time Memory Grader output
1 Execution timed out 4025 ms 5144 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 600 KB Output is correct
3 Correct 1 ms 600 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
6 Correct 2 ms 600 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Correct 1 ms 600 KB Output is correct
10 Correct 1 ms 600 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 600 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Correct 1 ms 600 KB Output is correct
16 Correct 1 ms 600 KB Output is correct
17 Correct 2 ms 756 KB Output is correct
18 Correct 2 ms 600 KB Output is correct
19 Correct 1 ms 600 KB Output is correct
20 Correct 1 ms 600 KB Output is correct
21 Correct 1 ms 600 KB Output is correct
22 Correct 1 ms 600 KB Output is correct
23 Correct 1 ms 600 KB Output is correct
24 Correct 1 ms 600 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 600 KB Output is correct
27 Correct 1 ms 600 KB Output is correct
28 Correct 1 ms 600 KB Output is correct
29 Correct 1 ms 600 KB Output is correct
30 Correct 1 ms 600 KB Output is correct
31 Correct 1 ms 600 KB Output is correct
32 Correct 1 ms 600 KB Output is correct
33 Correct 1 ms 600 KB Output is correct
34 Correct 1 ms 600 KB Output is correct
35 Correct 1 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 600 KB Output is correct
3 Correct 1 ms 600 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
6 Correct 2 ms 600 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Correct 1 ms 600 KB Output is correct
10 Correct 1 ms 600 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 600 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Correct 1 ms 600 KB Output is correct
16 Correct 1 ms 600 KB Output is correct
17 Correct 2 ms 756 KB Output is correct
18 Correct 2 ms 600 KB Output is correct
19 Correct 1 ms 600 KB Output is correct
20 Correct 1 ms 600 KB Output is correct
21 Correct 1 ms 600 KB Output is correct
22 Correct 1 ms 600 KB Output is correct
23 Correct 1 ms 600 KB Output is correct
24 Correct 1 ms 600 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 600 KB Output is correct
27 Correct 1 ms 600 KB Output is correct
28 Correct 1 ms 600 KB Output is correct
29 Correct 1 ms 600 KB Output is correct
30 Correct 1 ms 600 KB Output is correct
31 Correct 1 ms 600 KB Output is correct
32 Correct 1 ms 600 KB Output is correct
33 Correct 1 ms 600 KB Output is correct
34 Correct 1 ms 600 KB Output is correct
35 Correct 1 ms 600 KB Output is correct
36 Correct 41 ms 6096 KB Output is correct
37 Correct 69 ms 9248 KB Output is correct
38 Correct 61 ms 9156 KB Output is correct
39 Correct 63 ms 9396 KB Output is correct
40 Correct 59 ms 9400 KB Output is correct
41 Correct 78 ms 9464 KB Output is correct
42 Correct 60 ms 9724 KB Output is correct
43 Correct 47 ms 8116 KB Output is correct
44 Correct 40 ms 8260 KB Output is correct
45 Correct 41 ms 8132 KB Output is correct
46 Correct 40 ms 8116 KB Output is correct
47 Correct 58 ms 9156 KB Output is correct
48 Correct 64 ms 9324 KB Output is correct
49 Correct 59 ms 9420 KB Output is correct
50 Correct 37 ms 8244 KB Output is correct
51 Correct 38 ms 8116 KB Output is correct
52 Correct 63 ms 9120 KB Output is correct
53 Correct 58 ms 9328 KB Output is correct
54 Correct 57 ms 9404 KB Output is correct
55 Correct 42 ms 8104 KB Output is correct
56 Correct 42 ms 8116 KB Output is correct
57 Correct 61 ms 8528 KB Output is correct
58 Correct 65 ms 9136 KB Output is correct
59 Correct 59 ms 9276 KB Output is correct
60 Correct 56 ms 9316 KB Output is correct
61 Correct 60 ms 9636 KB Output is correct
62 Correct 57 ms 9380 KB Output is correct
63 Correct 63 ms 9396 KB Output is correct
64 Correct 38 ms 8124 KB Output is correct
65 Correct 37 ms 8116 KB Output is correct
66 Correct 48 ms 8428 KB Output is correct
67 Correct 38 ms 8236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 458 ms 9136 KB Output is correct
2 Correct 551 ms 9124 KB Output is correct
3 Correct 590 ms 9140 KB Output is correct
4 Correct 544 ms 9412 KB Output is correct
5 Correct 586 ms 9332 KB Output is correct
6 Correct 601 ms 9380 KB Output is correct
7 Correct 576 ms 9380 KB Output is correct
8 Correct 562 ms 8140 KB Output is correct
9 Correct 579 ms 8116 KB Output is correct
10 Correct 593 ms 8100 KB Output is correct
11 Correct 582 ms 8120 KB Output is correct
12 Correct 512 ms 8052 KB Output is correct
13 Correct 563 ms 8436 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 600 KB Output is correct
16 Correct 1 ms 600 KB Output is correct
17 Correct 60 ms 9156 KB Output is correct
18 Correct 57 ms 9380 KB Output is correct
19 Correct 65 ms 9492 KB Output is correct
20 Correct 40 ms 8096 KB Output is correct
21 Correct 38 ms 8092 KB Output is correct
22 Correct 61 ms 9124 KB Output is correct
23 Correct 58 ms 9412 KB Output is correct
24 Correct 59 ms 9384 KB Output is correct
25 Correct 37 ms 8104 KB Output is correct
26 Correct 45 ms 8112 KB Output is correct
27 Correct 1 ms 600 KB Output is correct
28 Correct 1 ms 600 KB Output is correct
29 Correct 1 ms 600 KB Output is correct
30 Correct 1 ms 600 KB Output is correct
31 Correct 1 ms 760 KB Output is correct
32 Correct 1 ms 600 KB Output is correct
33 Correct 1 ms 600 KB Output is correct
34 Correct 1 ms 600 KB Output is correct
35 Correct 1 ms 596 KB Output is correct
36 Correct 1 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 186 ms 2444 KB Output is correct
2 Correct 612 ms 9520 KB Output is correct
3 Correct 612 ms 9288 KB Output is correct
4 Correct 626 ms 9392 KB Output is correct
5 Correct 570 ms 9380 KB Output is correct
6 Correct 607 ms 9380 KB Output is correct
7 Correct 562 ms 9380 KB Output is correct
8 Correct 536 ms 8112 KB Output is correct
9 Correct 533 ms 8120 KB Output is correct
10 Correct 528 ms 8232 KB Output is correct
11 Correct 500 ms 8244 KB Output is correct
12 Correct 69 ms 9228 KB Output is correct
13 Correct 65 ms 9332 KB Output is correct
14 Correct 60 ms 9376 KB Output is correct
15 Correct 42 ms 8084 KB Output is correct
16 Correct 45 ms 8200 KB Output is correct
17 Correct 62 ms 8696 KB Output is correct
18 Correct 62 ms 9128 KB Output is correct
19 Correct 62 ms 9260 KB Output is correct
20 Correct 61 ms 9544 KB Output is correct
21 Correct 80 ms 9520 KB Output is correct
22 Correct 66 ms 9488 KB Output is correct
23 Correct 80 ms 9484 KB Output is correct
24 Correct 40 ms 8120 KB Output is correct
25 Correct 40 ms 8132 KB Output is correct
26 Correct 44 ms 8116 KB Output is correct
27 Correct 40 ms 8052 KB Output is correct
28 Correct 1 ms 600 KB Output is correct
29 Correct 1 ms 600 KB Output is correct
30 Correct 1 ms 600 KB Output is correct
31 Correct 1 ms 756 KB Output is correct
32 Correct 1 ms 600 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
34 Correct 1 ms 600 KB Output is correct
35 Correct 1 ms 600 KB Output is correct
36 Correct 1 ms 600 KB Output is correct
37 Correct 1 ms 600 KB Output is correct
38 Correct 1 ms 600 KB Output is correct
39 Correct 1 ms 600 KB Output is correct
40 Correct 1 ms 600 KB Output is correct
41 Correct 1 ms 600 KB Output is correct
42 Correct 1 ms 600 KB Output is correct
43 Correct 1 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 600 KB Output is correct
3 Correct 1 ms 600 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
6 Correct 2 ms 600 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Correct 1 ms 600 KB Output is correct
10 Correct 1 ms 600 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 600 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Correct 1 ms 600 KB Output is correct
16 Correct 1 ms 600 KB Output is correct
17 Correct 2 ms 756 KB Output is correct
18 Correct 2 ms 600 KB Output is correct
19 Correct 1 ms 600 KB Output is correct
20 Correct 1 ms 600 KB Output is correct
21 Correct 1 ms 600 KB Output is correct
22 Correct 1 ms 600 KB Output is correct
23 Correct 1 ms 600 KB Output is correct
24 Correct 1 ms 600 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 600 KB Output is correct
27 Correct 1 ms 600 KB Output is correct
28 Correct 1 ms 600 KB Output is correct
29 Correct 1 ms 600 KB Output is correct
30 Correct 1 ms 600 KB Output is correct
31 Correct 1 ms 600 KB Output is correct
32 Correct 1 ms 600 KB Output is correct
33 Correct 1 ms 600 KB Output is correct
34 Correct 1 ms 600 KB Output is correct
35 Correct 1 ms 600 KB Output is correct
36 Correct 41 ms 6096 KB Output is correct
37 Correct 69 ms 9248 KB Output is correct
38 Correct 61 ms 9156 KB Output is correct
39 Correct 63 ms 9396 KB Output is correct
40 Correct 59 ms 9400 KB Output is correct
41 Correct 78 ms 9464 KB Output is correct
42 Correct 60 ms 9724 KB Output is correct
43 Correct 47 ms 8116 KB Output is correct
44 Correct 40 ms 8260 KB Output is correct
45 Correct 41 ms 8132 KB Output is correct
46 Correct 40 ms 8116 KB Output is correct
47 Correct 58 ms 9156 KB Output is correct
48 Correct 64 ms 9324 KB Output is correct
49 Correct 59 ms 9420 KB Output is correct
50 Correct 37 ms 8244 KB Output is correct
51 Correct 38 ms 8116 KB Output is correct
52 Correct 63 ms 9120 KB Output is correct
53 Correct 58 ms 9328 KB Output is correct
54 Correct 57 ms 9404 KB Output is correct
55 Correct 42 ms 8104 KB Output is correct
56 Correct 42 ms 8116 KB Output is correct
57 Correct 61 ms 8528 KB Output is correct
58 Correct 65 ms 9136 KB Output is correct
59 Correct 59 ms 9276 KB Output is correct
60 Correct 56 ms 9316 KB Output is correct
61 Correct 60 ms 9636 KB Output is correct
62 Correct 57 ms 9380 KB Output is correct
63 Correct 63 ms 9396 KB Output is correct
64 Correct 38 ms 8124 KB Output is correct
65 Correct 37 ms 8116 KB Output is correct
66 Correct 48 ms 8428 KB Output is correct
67 Correct 38 ms 8236 KB Output is correct
68 Correct 458 ms 9136 KB Output is correct
69 Correct 551 ms 9124 KB Output is correct
70 Correct 590 ms 9140 KB Output is correct
71 Correct 544 ms 9412 KB Output is correct
72 Correct 586 ms 9332 KB Output is correct
73 Correct 601 ms 9380 KB Output is correct
74 Correct 576 ms 9380 KB Output is correct
75 Correct 562 ms 8140 KB Output is correct
76 Correct 579 ms 8116 KB Output is correct
77 Correct 593 ms 8100 KB Output is correct
78 Correct 582 ms 8120 KB Output is correct
79 Correct 512 ms 8052 KB Output is correct
80 Correct 563 ms 8436 KB Output is correct
81 Correct 0 ms 344 KB Output is correct
82 Correct 1 ms 600 KB Output is correct
83 Correct 1 ms 600 KB Output is correct
84 Correct 60 ms 9156 KB Output is correct
85 Correct 57 ms 9380 KB Output is correct
86 Correct 65 ms 9492 KB Output is correct
87 Correct 40 ms 8096 KB Output is correct
88 Correct 38 ms 8092 KB Output is correct
89 Correct 61 ms 9124 KB Output is correct
90 Correct 58 ms 9412 KB Output is correct
91 Correct 59 ms 9384 KB Output is correct
92 Correct 37 ms 8104 KB Output is correct
93 Correct 45 ms 8112 KB Output is correct
94 Correct 1 ms 600 KB Output is correct
95 Correct 1 ms 600 KB Output is correct
96 Correct 1 ms 600 KB Output is correct
97 Correct 1 ms 600 KB Output is correct
98 Correct 1 ms 760 KB Output is correct
99 Correct 1 ms 600 KB Output is correct
100 Correct 1 ms 600 KB Output is correct
101 Correct 1 ms 600 KB Output is correct
102 Correct 1 ms 596 KB Output is correct
103 Correct 1 ms 600 KB Output is correct
104 Execution timed out 4008 ms 8024 KB Time limit exceeded
105 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4025 ms 5144 KB Time limit exceeded
2 Halted 0 ms 0 KB -