# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1073646 |
2024-08-24T17:00:34 Z |
fv3 |
Radio Towers (IOI22_towers) |
C++17 |
|
544 ms |
6600 KB |
#include "towers.h"
#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
int N;
vector<int> H;
struct node
{
int mn;
int index;
};
node merge(const node a, const node b)
{
return a.mn < b.mn ? a : b;
}
const node empty_node = {INF, 0};
int nt;
vector<int> st_mx;
vector<node> st_mn;
node get_min_range(int l, int r, int k, int tl, int tr)
{
if (tr < l || tl > r) return empty_node;
if (tl >= l && tr <= r) return st_mn[k];
int c = (tl + tr) / 2;
return merge(get_min_range(l, r, k*2, tl, c), get_min_range(l, r, k*2|1, c+1, tr));
}
void set_min(int i)
{
i += nt;
st_mn[i] = empty_node;
for (i /= 2; i >= 1; i /= 2)
st_mn[i] = merge(st_mn[i*2], st_mn[i*2|1]);
}
int get_max_range(int l, int r, int k, int tl, int tr)
{
if (tr < l || tl > r) return 0;
if (tl >= l && tr <= r) return st_mx[k];
int c = (tl + tr) / 2;
return max(get_max_range(l, r, k*2, tl, c), get_max_range(l, r, k*2|1, c+1, tr));
}
void init(int N_, vector<int> H_)
{
N = N_;
H = H_;
nt = 1;
while (nt < N) nt <<= 1;
st_mx = vector<int>(nt*2);
st_mn = vector<node>(nt*2, empty_node);
for (int i = 0; i < N; i++)
{
st_mx[nt + i] = H[i];
st_mn[nt + i] = {H[i], i};
}
for (int i = nt - 1; i >= 1; i--)
{
st_mx[i] = max(st_mx[i*2], st_mx[i*2|1]);
st_mn[i] = merge(st_mn[i*2], st_mn[i*2|1]);
}
}
int max_towers(int L, int R, int D)
{
// You should always lease the smallest tower
// No two adjacent towers can be leased
int res = 0;
set<int> leased;
while (true)
{
node cnd = get_min_range(L, R, 1, 0, nt - 1);
if (cnd.mn == INF) break;
if (!leased.size())
{
res++;
leased.insert(cnd.index);
for (int i = max(L, cnd.index-1); i <= min(R, cnd.index + 1); i++)
set_min(i);
continue;
}
if (*leased.begin() < cnd.index)
{
int l = *--leased.lower_bound(cnd.index);
int mx = get_max_range(l, cnd.index, 1, 0, nt - 1);
if (mx - cnd.mn < D)
{
set_min(cnd.index);
continue;
}
}
if (*--leased.end() > cnd.index)
{
int r = *leased.lower_bound(cnd.index);
int mx = get_max_range(cnd.index, r, 1, 0, nt - 1);
if (mx - cnd.mn < D)
{
set_min(cnd.index);
continue;
}
}
res++;
leased.insert(cnd.index);
for (int i = max(L, cnd.index-1); i <= min(R, cnd.index + 1); i++)
set_min(i);
}
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
340 ms |
2648 KB |
6th lines differ - on the 1st token, expected: '1', found: '0' |
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 |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
344 KB |
Output is correct |
30 |
Correct |
1 ms |
344 KB |
Output is correct |
31 |
Correct |
1 ms |
500 KB |
Output is correct |
32 |
Correct |
1 ms |
344 KB |
Output is correct |
33 |
Correct |
1 ms |
344 KB |
Output is correct |
34 |
Correct |
1 ms |
344 KB |
Output is correct |
35 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
344 KB |
Output is correct |
30 |
Correct |
1 ms |
344 KB |
Output is correct |
31 |
Correct |
1 ms |
500 KB |
Output is correct |
32 |
Correct |
1 ms |
344 KB |
Output is correct |
33 |
Correct |
1 ms |
344 KB |
Output is correct |
34 |
Correct |
1 ms |
344 KB |
Output is correct |
35 |
Correct |
1 ms |
344 KB |
Output is correct |
36 |
Correct |
16 ms |
2648 KB |
Output is correct |
37 |
Correct |
33 ms |
4696 KB |
Output is correct |
38 |
Correct |
19 ms |
4696 KB |
Output is correct |
39 |
Correct |
30 ms |
4696 KB |
Output is correct |
40 |
Correct |
18 ms |
4696 KB |
Output is correct |
41 |
Correct |
65 ms |
5104 KB |
Output is correct |
42 |
Correct |
11 ms |
4696 KB |
Output is correct |
43 |
Correct |
36 ms |
4696 KB |
Output is correct |
44 |
Correct |
16 ms |
4696 KB |
Output is correct |
45 |
Correct |
11 ms |
4696 KB |
Output is correct |
46 |
Correct |
10 ms |
4516 KB |
Output is correct |
47 |
Correct |
39 ms |
4688 KB |
Output is correct |
48 |
Correct |
25 ms |
4696 KB |
Output is correct |
49 |
Correct |
16 ms |
4672 KB |
Output is correct |
50 |
Correct |
23 ms |
4524 KB |
Output is correct |
51 |
Correct |
37 ms |
4696 KB |
Output is correct |
52 |
Correct |
65 ms |
5832 KB |
Output is correct |
53 |
Correct |
81 ms |
6600 KB |
Output is correct |
54 |
Correct |
74 ms |
6596 KB |
Output is correct |
55 |
Correct |
44 ms |
4696 KB |
Output is correct |
56 |
Correct |
52 ms |
4672 KB |
Output is correct |
57 |
Correct |
68 ms |
4564 KB |
Output is correct |
58 |
Correct |
63 ms |
5064 KB |
Output is correct |
59 |
Correct |
75 ms |
5320 KB |
Output is correct |
60 |
Correct |
77 ms |
6576 KB |
Output is correct |
61 |
Correct |
74 ms |
6092 KB |
Output is correct |
62 |
Correct |
70 ms |
5576 KB |
Output is correct |
63 |
Correct |
76 ms |
6268 KB |
Output is correct |
64 |
Correct |
40 ms |
4696 KB |
Output is correct |
65 |
Correct |
51 ms |
4524 KB |
Output is correct |
66 |
Correct |
56 ms |
4672 KB |
Output is correct |
67 |
Correct |
45 ms |
4692 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
544 ms |
4824 KB |
3rd lines differ - on the 1st token, expected: '14278', found: '3520' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
207 ms |
1896 KB |
2nd lines differ - on the 1st token, expected: '7063', found: '0' |
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 |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
344 KB |
Output is correct |
30 |
Correct |
1 ms |
344 KB |
Output is correct |
31 |
Correct |
1 ms |
500 KB |
Output is correct |
32 |
Correct |
1 ms |
344 KB |
Output is correct |
33 |
Correct |
1 ms |
344 KB |
Output is correct |
34 |
Correct |
1 ms |
344 KB |
Output is correct |
35 |
Correct |
1 ms |
344 KB |
Output is correct |
36 |
Correct |
16 ms |
2648 KB |
Output is correct |
37 |
Correct |
33 ms |
4696 KB |
Output is correct |
38 |
Correct |
19 ms |
4696 KB |
Output is correct |
39 |
Correct |
30 ms |
4696 KB |
Output is correct |
40 |
Correct |
18 ms |
4696 KB |
Output is correct |
41 |
Correct |
65 ms |
5104 KB |
Output is correct |
42 |
Correct |
11 ms |
4696 KB |
Output is correct |
43 |
Correct |
36 ms |
4696 KB |
Output is correct |
44 |
Correct |
16 ms |
4696 KB |
Output is correct |
45 |
Correct |
11 ms |
4696 KB |
Output is correct |
46 |
Correct |
10 ms |
4516 KB |
Output is correct |
47 |
Correct |
39 ms |
4688 KB |
Output is correct |
48 |
Correct |
25 ms |
4696 KB |
Output is correct |
49 |
Correct |
16 ms |
4672 KB |
Output is correct |
50 |
Correct |
23 ms |
4524 KB |
Output is correct |
51 |
Correct |
37 ms |
4696 KB |
Output is correct |
52 |
Correct |
65 ms |
5832 KB |
Output is correct |
53 |
Correct |
81 ms |
6600 KB |
Output is correct |
54 |
Correct |
74 ms |
6596 KB |
Output is correct |
55 |
Correct |
44 ms |
4696 KB |
Output is correct |
56 |
Correct |
52 ms |
4672 KB |
Output is correct |
57 |
Correct |
68 ms |
4564 KB |
Output is correct |
58 |
Correct |
63 ms |
5064 KB |
Output is correct |
59 |
Correct |
75 ms |
5320 KB |
Output is correct |
60 |
Correct |
77 ms |
6576 KB |
Output is correct |
61 |
Correct |
74 ms |
6092 KB |
Output is correct |
62 |
Correct |
70 ms |
5576 KB |
Output is correct |
63 |
Correct |
76 ms |
6268 KB |
Output is correct |
64 |
Correct |
40 ms |
4696 KB |
Output is correct |
65 |
Correct |
51 ms |
4524 KB |
Output is correct |
66 |
Correct |
56 ms |
4672 KB |
Output is correct |
67 |
Correct |
45 ms |
4692 KB |
Output is correct |
68 |
Incorrect |
544 ms |
4824 KB |
3rd lines differ - on the 1st token, expected: '14278', found: '3520' |
69 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
340 ms |
2648 KB |
6th lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |