Submission #817073

# Submission time Handle Problem Language Result Execution time Memory
817073 2023-08-09T09:06:27 Z finn__ Radio Towers (IOI22_towers) C++17
27 / 100
4000 ms 11744 KB
#include "towers.h"
#include <bits/stdc++.h>
using namespace std;

template <typename T, size_t L>
struct segtree_max
{
    T t[L << 1];

    void update(size_t i, T x)
    {
        i += L;
        t[i] = max(t[i], x);
        while (i >>= 1)
            t[i] = max(t[i << 1], t[i << 1 | 1]);
    }

    T range_max(size_t i, size_t j)
    {
        i += L, j += L;
        T x = numeric_limits<T>::min();

        while (i <= j)
        {
            if (i & 1)
                x = max(x, t[i++]);
            if (!(j & 1))
                x = max(x, t[j--]);
            i >>= 1;
            j >>= 1;
        }

        return x;
    }

    void reset() { memset(t, 0, sizeof t); }
};

constexpr size_t N = 100000;

int subtask, h[N], coords[3 * N];
size_t n, peak_pos;

segtree_max<int64_t, 3 * N> towers, intermediate;

void init(int n_, vector<int> h_)
{
    n = n_;
    copy(h_.begin(), h_.end(), h);
    bool increasing = 1;
    subtask = 1;
    for (size_t i = 0; i + 1 < n; ++i)
    {
        if (h[i] < h[i + 1] && !increasing)
        {
            subtask = 2;
            break;
        }
        if (h[i] > h[i + 1])
            increasing = 0;
    }

    if (subtask == 1)
    {
        while (peak_pos + 1 < n && h[peak_pos + 1] > h[peak_pos])
            ++peak_pos;
        return;
    }
    else
    {
        subtask = 3;
    }
}

size_t ind(int64_t coord) { return lower_bound(coords, coords + 3 * n, coord) - coords; }

int max_towers(int l, int r, int d)
{
    if (subtask == 1)
    {
        if (l >= peak_pos || r <= peak_pos)
            return 1;
        return (h[peak_pos] >= h[l] + d && h[peak_pos] >= h[r] + d) + 1;
    }
    else
    {
        memcpy(coords, h, sizeof h);
        for (size_t i = 0; i < n; ++i)
            coords[n + i] = coords[i] + d, coords[2 * n + i] = coords[i] - d;
        sort(coords, coords + 3 * n);

        towers.reset();
        intermediate.reset();

        towers.update(ind(h[l]), 1);
        int ans = 1;
        for (size_t i = l + 1; i <= r; ++i)
        {
            // as intermediate
            int64_t v = towers.range_max(0, ind(h[i] - d));
            intermediate.update(ind(h[i]), v);

            // as tower
            v = intermediate.range_max(ind(h[i] + d), 3 * n - 1) + 1;
            towers.update(ind(h[i]), v);
            ans = max<int>(ans, v);
        }

        return ans;
    }
}

Compilation message

towers.cpp: In function 'int max_towers(int, int, int)':
towers.cpp:81:15: warning: comparison of integer expressions of different signedness: 'int' and 'size_t' {aka 'long unsigned int'} [-Wsign-compare]
   81 |         if (l >= peak_pos || r <= peak_pos)
      |             ~~^~~~~~~~~~~
towers.cpp:81:32: warning: comparison of integer expressions of different signedness: 'int' and 'size_t' {aka 'long unsigned int'} [-Wsign-compare]
   81 |         if (l >= peak_pos || r <= peak_pos)
      |                              ~~^~~~~~~~~~~
towers.cpp:97:34: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   97 |         for (size_t i = l + 1; i <= r; ++i)
      |                                ~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 239 ms 972 KB Output is correct
2 Correct 685 ms 1360 KB Output is correct
3 Correct 561 ms 1388 KB Output is correct
4 Correct 515 ms 1488 KB Output is correct
5 Correct 758 ms 1460 KB Output is correct
6 Correct 561 ms 1500 KB Output is correct
7 Correct 478 ms 1460 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 10000 KB Output is correct
2 Correct 7 ms 10064 KB Output is correct
3 Correct 5 ms 10064 KB Output is correct
4 Correct 5 ms 10064 KB Output is correct
5 Correct 5 ms 10064 KB Output is correct
6 Correct 4 ms 10064 KB Output is correct
7 Correct 5 ms 10064 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 6 ms 10088 KB Output is correct
11 Correct 5 ms 10064 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 5 ms 10064 KB Output is correct
16 Correct 6 ms 10048 KB Output is correct
17 Correct 6 ms 10192 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 5 ms 10064 KB Output is correct
20 Correct 5 ms 10064 KB Output is correct
21 Correct 5 ms 10064 KB Output is correct
22 Correct 5 ms 10064 KB Output is correct
23 Correct 0 ms 336 KB Output is correct
24 Correct 5 ms 10028 KB Output is correct
25 Correct 5 ms 10096 KB Output is correct
26 Correct 5 ms 10064 KB Output is correct
27 Correct 5 ms 10020 KB Output is correct
28 Correct 5 ms 10064 KB Output is correct
29 Correct 5 ms 10008 KB Output is correct
30 Correct 5 ms 10064 KB Output is correct
31 Correct 5 ms 10012 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 6 ms 10000 KB Output is correct
35 Correct 5 ms 10016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 10000 KB Output is correct
2 Correct 7 ms 10064 KB Output is correct
3 Correct 5 ms 10064 KB Output is correct
4 Correct 5 ms 10064 KB Output is correct
5 Correct 5 ms 10064 KB Output is correct
6 Correct 4 ms 10064 KB Output is correct
7 Correct 5 ms 10064 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 6 ms 10088 KB Output is correct
11 Correct 5 ms 10064 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 5 ms 10064 KB Output is correct
16 Correct 6 ms 10048 KB Output is correct
17 Correct 6 ms 10192 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 5 ms 10064 KB Output is correct
20 Correct 5 ms 10064 KB Output is correct
21 Correct 5 ms 10064 KB Output is correct
22 Correct 5 ms 10064 KB Output is correct
23 Correct 0 ms 336 KB Output is correct
24 Correct 5 ms 10028 KB Output is correct
25 Correct 5 ms 10096 KB Output is correct
26 Correct 5 ms 10064 KB Output is correct
27 Correct 5 ms 10020 KB Output is correct
28 Correct 5 ms 10064 KB Output is correct
29 Correct 5 ms 10008 KB Output is correct
30 Correct 5 ms 10064 KB Output is correct
31 Correct 5 ms 10012 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 6 ms 10000 KB Output is correct
35 Correct 5 ms 10016 KB Output is correct
36 Correct 36 ms 10960 KB Output is correct
37 Correct 59 ms 11644 KB Output is correct
38 Correct 43 ms 11552 KB Output is correct
39 Correct 59 ms 11640 KB Output is correct
40 Correct 46 ms 11700 KB Output is correct
41 Correct 100 ms 11624 KB Output is correct
42 Correct 39 ms 11572 KB Output is correct
43 Correct 9 ms 1452 KB Output is correct
44 Correct 9 ms 1452 KB Output is correct
45 Correct 21 ms 11588 KB Output is correct
46 Correct 22 ms 11584 KB Output is correct
47 Correct 64 ms 11536 KB Output is correct
48 Correct 53 ms 11612 KB Output is correct
49 Correct 39 ms 11596 KB Output is correct
50 Correct 8 ms 1352 KB Output is correct
51 Correct 42 ms 11552 KB Output is correct
52 Correct 102 ms 11640 KB Output is correct
53 Correct 109 ms 11744 KB Output is correct
54 Correct 114 ms 11576 KB Output is correct
55 Correct 8 ms 1464 KB Output is correct
56 Correct 60 ms 11644 KB Output is correct
57 Correct 104 ms 11540 KB Output is correct
58 Correct 109 ms 11640 KB Output is correct
59 Correct 107 ms 11584 KB Output is correct
60 Correct 131 ms 11624 KB Output is correct
61 Correct 118 ms 11644 KB Output is correct
62 Correct 111 ms 11556 KB Output is correct
63 Correct 108 ms 11712 KB Output is correct
64 Correct 10 ms 1456 KB Output is correct
65 Correct 10 ms 1452 KB Output is correct
66 Correct 72 ms 11664 KB Output is correct
67 Correct 71 ms 11576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 4022 ms 11596 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4030 ms 10320 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 10000 KB Output is correct
2 Correct 7 ms 10064 KB Output is correct
3 Correct 5 ms 10064 KB Output is correct
4 Correct 5 ms 10064 KB Output is correct
5 Correct 5 ms 10064 KB Output is correct
6 Correct 4 ms 10064 KB Output is correct
7 Correct 5 ms 10064 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 6 ms 10088 KB Output is correct
11 Correct 5 ms 10064 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 5 ms 10064 KB Output is correct
16 Correct 6 ms 10048 KB Output is correct
17 Correct 6 ms 10192 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 5 ms 10064 KB Output is correct
20 Correct 5 ms 10064 KB Output is correct
21 Correct 5 ms 10064 KB Output is correct
22 Correct 5 ms 10064 KB Output is correct
23 Correct 0 ms 336 KB Output is correct
24 Correct 5 ms 10028 KB Output is correct
25 Correct 5 ms 10096 KB Output is correct
26 Correct 5 ms 10064 KB Output is correct
27 Correct 5 ms 10020 KB Output is correct
28 Correct 5 ms 10064 KB Output is correct
29 Correct 5 ms 10008 KB Output is correct
30 Correct 5 ms 10064 KB Output is correct
31 Correct 5 ms 10012 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 6 ms 10000 KB Output is correct
35 Correct 5 ms 10016 KB Output is correct
36 Correct 36 ms 10960 KB Output is correct
37 Correct 59 ms 11644 KB Output is correct
38 Correct 43 ms 11552 KB Output is correct
39 Correct 59 ms 11640 KB Output is correct
40 Correct 46 ms 11700 KB Output is correct
41 Correct 100 ms 11624 KB Output is correct
42 Correct 39 ms 11572 KB Output is correct
43 Correct 9 ms 1452 KB Output is correct
44 Correct 9 ms 1452 KB Output is correct
45 Correct 21 ms 11588 KB Output is correct
46 Correct 22 ms 11584 KB Output is correct
47 Correct 64 ms 11536 KB Output is correct
48 Correct 53 ms 11612 KB Output is correct
49 Correct 39 ms 11596 KB Output is correct
50 Correct 8 ms 1352 KB Output is correct
51 Correct 42 ms 11552 KB Output is correct
52 Correct 102 ms 11640 KB Output is correct
53 Correct 109 ms 11744 KB Output is correct
54 Correct 114 ms 11576 KB Output is correct
55 Correct 8 ms 1464 KB Output is correct
56 Correct 60 ms 11644 KB Output is correct
57 Correct 104 ms 11540 KB Output is correct
58 Correct 109 ms 11640 KB Output is correct
59 Correct 107 ms 11584 KB Output is correct
60 Correct 131 ms 11624 KB Output is correct
61 Correct 118 ms 11644 KB Output is correct
62 Correct 111 ms 11556 KB Output is correct
63 Correct 108 ms 11712 KB Output is correct
64 Correct 10 ms 1456 KB Output is correct
65 Correct 10 ms 1452 KB Output is correct
66 Correct 72 ms 11664 KB Output is correct
67 Correct 71 ms 11576 KB Output is correct
68 Execution timed out 4022 ms 11596 KB Time limit exceeded
69 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 239 ms 972 KB Output is correct
2 Correct 685 ms 1360 KB Output is correct
3 Correct 561 ms 1388 KB Output is correct
4 Correct 515 ms 1488 KB Output is correct
5 Correct 758 ms 1460 KB Output is correct
6 Correct 561 ms 1500 KB Output is correct
7 Correct 478 ms 1460 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 4 ms 10000 KB Output is correct
12 Correct 7 ms 10064 KB Output is correct
13 Correct 5 ms 10064 KB Output is correct
14 Correct 5 ms 10064 KB Output is correct
15 Correct 5 ms 10064 KB Output is correct
16 Correct 4 ms 10064 KB Output is correct
17 Correct 5 ms 10064 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 6 ms 10088 KB Output is correct
21 Correct 5 ms 10064 KB Output is correct
22 Correct 0 ms 208 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 5 ms 10064 KB Output is correct
26 Correct 6 ms 10048 KB Output is correct
27 Correct 6 ms 10192 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 5 ms 10064 KB Output is correct
30 Correct 5 ms 10064 KB Output is correct
31 Correct 5 ms 10064 KB Output is correct
32 Correct 5 ms 10064 KB Output is correct
33 Correct 0 ms 336 KB Output is correct
34 Correct 5 ms 10028 KB Output is correct
35 Correct 5 ms 10096 KB Output is correct
36 Correct 5 ms 10064 KB Output is correct
37 Correct 5 ms 10020 KB Output is correct
38 Correct 5 ms 10064 KB Output is correct
39 Correct 5 ms 10008 KB Output is correct
40 Correct 5 ms 10064 KB Output is correct
41 Correct 5 ms 10012 KB Output is correct
42 Correct 1 ms 336 KB Output is correct
43 Correct 1 ms 336 KB Output is correct
44 Correct 6 ms 10000 KB Output is correct
45 Correct 5 ms 10016 KB Output is correct
46 Correct 36 ms 10960 KB Output is correct
47 Correct 59 ms 11644 KB Output is correct
48 Correct 43 ms 11552 KB Output is correct
49 Correct 59 ms 11640 KB Output is correct
50 Correct 46 ms 11700 KB Output is correct
51 Correct 100 ms 11624 KB Output is correct
52 Correct 39 ms 11572 KB Output is correct
53 Correct 9 ms 1452 KB Output is correct
54 Correct 9 ms 1452 KB Output is correct
55 Correct 21 ms 11588 KB Output is correct
56 Correct 22 ms 11584 KB Output is correct
57 Correct 64 ms 11536 KB Output is correct
58 Correct 53 ms 11612 KB Output is correct
59 Correct 39 ms 11596 KB Output is correct
60 Correct 8 ms 1352 KB Output is correct
61 Correct 42 ms 11552 KB Output is correct
62 Correct 102 ms 11640 KB Output is correct
63 Correct 109 ms 11744 KB Output is correct
64 Correct 114 ms 11576 KB Output is correct
65 Correct 8 ms 1464 KB Output is correct
66 Correct 60 ms 11644 KB Output is correct
67 Correct 104 ms 11540 KB Output is correct
68 Correct 109 ms 11640 KB Output is correct
69 Correct 107 ms 11584 KB Output is correct
70 Correct 131 ms 11624 KB Output is correct
71 Correct 118 ms 11644 KB Output is correct
72 Correct 111 ms 11556 KB Output is correct
73 Correct 108 ms 11712 KB Output is correct
74 Correct 10 ms 1456 KB Output is correct
75 Correct 10 ms 1452 KB Output is correct
76 Correct 72 ms 11664 KB Output is correct
77 Correct 71 ms 11576 KB Output is correct
78 Execution timed out 4022 ms 11596 KB Time limit exceeded
79 Halted 0 ms 0 KB -