Submission #763539

# Submission time Handle Problem Language Result Execution time Memory
763539 2023-06-22T12:32:56 Z drdilyor Radio Towers (IOI22_towers) C++17
23 / 100
4000 ms 15580 KB
#include <bits/stdc++.h>
#include "towers.h"
using namespace std;
using ll = long long;

template<typename T, typename Op>
struct SparseTable {
    vector<vector<T>> sparse;
    Op accum_func;

    SparseTable() = default;

    SparseTable(const vector<T>& arr, const Op func) : accum_func(func) {
        int n = arr.size();
        int logn = 32 - __builtin_clz(n);
        sparse.resize(logn, vector<T>(n));
        sparse[0] = arr;
        for (int lg = 1; lg < logn; lg++) {
            for (int i = 0; i + (1 << lg) <= n; i++) {
                sparse[lg][i] = accum_func(sparse[lg - 1][i], sparse[lg - 1][i + (1 << (lg - 1))]);
            }
        }
    }

    T find(int l, int r) { // [l, r]
        r++;
        int cur_log = 31 - __builtin_clz(r - l);
        return accum_func(sparse[cur_log][l], sparse[cur_log][r - (1 << cur_log)]);
    }
};

int st_min(int a, int b) { return min(a, b); }
int st_max(int a, int b) { return max(a, b); }

int n;
vector<int> h, ix;
SparseTable<int, decltype(&st_min)> hmax;
SparseTable<int, decltype(&st_max)> hmin;
void init(int N, std::vector<int> H) {
    n = N, h = H;
    ix.resize(n);
    iota(ix.begin(), ix.end(), 0);
    sort(ix.begin(), ix.end(), [&](int i, int j) {
            return h[i] < h[j];
            });
    hmax = SparseTable(h, st_max);
    hmin = SparseTable(h, st_min);
}

int max_towers(int L, int R, int D) {
    int res = 0;
    for (int i_ = 0; i_ < n; i_++) {
        int i = ix[i_];
        if (i < L || i > R) continue;
        bool ok = 1;
        {
            int l = L-1, r = i;
            while (l < r-1) {
                int mid = (l+r) / 2;
                if (hmax.find(mid, i) - h[i] >= D)
                    l = mid;
                else r = mid;
            }
            if (hmin.find(l+1, i) < h[i]) ok = 0;
        }
        {
            int l = i, r = R+1;
            while (l < r-1) {
                int mid = (l+r) / 2;
                if (hmax.find(i, mid) - h[i] >= D)
                    r = mid;
                else l = mid;
            }
            if (hmin.find(i, r-1) < h[i]) ok = 0;
        }
        res += ok;
    }
    return res;
}
# Verdict Execution time Memory Grader output
1 Execution timed out 4022 ms 8948 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 464 KB Output is correct
3 Correct 1 ms 464 KB Output is correct
4 Correct 1 ms 464 KB Output is correct
5 Correct 1 ms 464 KB Output is correct
6 Correct 1 ms 464 KB Output is correct
7 Correct 1 ms 464 KB Output is correct
8 Correct 1 ms 500 KB Output is correct
9 Correct 1 ms 464 KB Output is correct
10 Correct 1 ms 508 KB Output is correct
11 Correct 1 ms 464 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 1 ms 464 KB Output is correct
14 Correct 1 ms 464 KB Output is correct
15 Correct 1 ms 464 KB Output is correct
16 Correct 1 ms 464 KB Output is correct
17 Correct 1 ms 464 KB Output is correct
18 Correct 1 ms 464 KB Output is correct
19 Correct 1 ms 464 KB Output is correct
20 Correct 1 ms 464 KB Output is correct
21 Correct 1 ms 588 KB Output is correct
22 Correct 2 ms 464 KB Output is correct
23 Correct 1 ms 464 KB Output is correct
24 Correct 1 ms 464 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 464 KB Output is correct
27 Correct 1 ms 464 KB Output is correct
28 Correct 1 ms 464 KB Output is correct
29 Correct 1 ms 464 KB Output is correct
30 Correct 1 ms 464 KB Output is correct
31 Correct 1 ms 464 KB Output is correct
32 Correct 1 ms 464 KB Output is correct
33 Correct 1 ms 464 KB Output is correct
34 Correct 1 ms 464 KB Output is correct
35 Correct 1 ms 464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 464 KB Output is correct
3 Correct 1 ms 464 KB Output is correct
4 Correct 1 ms 464 KB Output is correct
5 Correct 1 ms 464 KB Output is correct
6 Correct 1 ms 464 KB Output is correct
7 Correct 1 ms 464 KB Output is correct
8 Correct 1 ms 500 KB Output is correct
9 Correct 1 ms 464 KB Output is correct
10 Correct 1 ms 508 KB Output is correct
11 Correct 1 ms 464 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 1 ms 464 KB Output is correct
14 Correct 1 ms 464 KB Output is correct
15 Correct 1 ms 464 KB Output is correct
16 Correct 1 ms 464 KB Output is correct
17 Correct 1 ms 464 KB Output is correct
18 Correct 1 ms 464 KB Output is correct
19 Correct 1 ms 464 KB Output is correct
20 Correct 1 ms 464 KB Output is correct
21 Correct 1 ms 588 KB Output is correct
22 Correct 2 ms 464 KB Output is correct
23 Correct 1 ms 464 KB Output is correct
24 Correct 1 ms 464 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 464 KB Output is correct
27 Correct 1 ms 464 KB Output is correct
28 Correct 1 ms 464 KB Output is correct
29 Correct 1 ms 464 KB Output is correct
30 Correct 1 ms 464 KB Output is correct
31 Correct 1 ms 464 KB Output is correct
32 Correct 1 ms 464 KB Output is correct
33 Correct 1 ms 464 KB Output is correct
34 Correct 1 ms 464 KB Output is correct
35 Correct 1 ms 464 KB Output is correct
36 Correct 27 ms 9640 KB Output is correct
37 Correct 51 ms 15520 KB Output is correct
38 Correct 34 ms 15552 KB Output is correct
39 Correct 40 ms 15504 KB Output is correct
40 Correct 39 ms 15448 KB Output is correct
41 Correct 72 ms 15508 KB Output is correct
42 Correct 30 ms 15552 KB Output is correct
43 Correct 42 ms 15580 KB Output is correct
44 Correct 26 ms 15532 KB Output is correct
45 Correct 22 ms 15560 KB Output is correct
46 Correct 21 ms 15552 KB Output is correct
47 Correct 49 ms 15560 KB Output is correct
48 Correct 38 ms 15556 KB Output is correct
49 Correct 31 ms 15544 KB Output is correct
50 Correct 28 ms 15516 KB Output is correct
51 Correct 33 ms 15488 KB Output is correct
52 Correct 96 ms 15548 KB Output is correct
53 Correct 101 ms 15528 KB Output is correct
54 Correct 96 ms 15528 KB Output is correct
55 Correct 56 ms 15504 KB Output is correct
56 Correct 61 ms 15528 KB Output is correct
57 Correct 76 ms 15016 KB Output is correct
58 Correct 87 ms 15552 KB Output is correct
59 Correct 91 ms 15556 KB Output is correct
60 Correct 94 ms 15508 KB Output is correct
61 Correct 90 ms 15552 KB Output is correct
62 Correct 86 ms 15512 KB Output is correct
63 Correct 90 ms 15460 KB Output is correct
64 Correct 53 ms 15504 KB Output is correct
65 Correct 53 ms 15568 KB Output is correct
66 Correct 54 ms 15560 KB Output is correct
67 Correct 59 ms 15488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 4024 ms 15404 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4027 ms 3536 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 464 KB Output is correct
3 Correct 1 ms 464 KB Output is correct
4 Correct 1 ms 464 KB Output is correct
5 Correct 1 ms 464 KB Output is correct
6 Correct 1 ms 464 KB Output is correct
7 Correct 1 ms 464 KB Output is correct
8 Correct 1 ms 500 KB Output is correct
9 Correct 1 ms 464 KB Output is correct
10 Correct 1 ms 508 KB Output is correct
11 Correct 1 ms 464 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 1 ms 464 KB Output is correct
14 Correct 1 ms 464 KB Output is correct
15 Correct 1 ms 464 KB Output is correct
16 Correct 1 ms 464 KB Output is correct
17 Correct 1 ms 464 KB Output is correct
18 Correct 1 ms 464 KB Output is correct
19 Correct 1 ms 464 KB Output is correct
20 Correct 1 ms 464 KB Output is correct
21 Correct 1 ms 588 KB Output is correct
22 Correct 2 ms 464 KB Output is correct
23 Correct 1 ms 464 KB Output is correct
24 Correct 1 ms 464 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 464 KB Output is correct
27 Correct 1 ms 464 KB Output is correct
28 Correct 1 ms 464 KB Output is correct
29 Correct 1 ms 464 KB Output is correct
30 Correct 1 ms 464 KB Output is correct
31 Correct 1 ms 464 KB Output is correct
32 Correct 1 ms 464 KB Output is correct
33 Correct 1 ms 464 KB Output is correct
34 Correct 1 ms 464 KB Output is correct
35 Correct 1 ms 464 KB Output is correct
36 Correct 27 ms 9640 KB Output is correct
37 Correct 51 ms 15520 KB Output is correct
38 Correct 34 ms 15552 KB Output is correct
39 Correct 40 ms 15504 KB Output is correct
40 Correct 39 ms 15448 KB Output is correct
41 Correct 72 ms 15508 KB Output is correct
42 Correct 30 ms 15552 KB Output is correct
43 Correct 42 ms 15580 KB Output is correct
44 Correct 26 ms 15532 KB Output is correct
45 Correct 22 ms 15560 KB Output is correct
46 Correct 21 ms 15552 KB Output is correct
47 Correct 49 ms 15560 KB Output is correct
48 Correct 38 ms 15556 KB Output is correct
49 Correct 31 ms 15544 KB Output is correct
50 Correct 28 ms 15516 KB Output is correct
51 Correct 33 ms 15488 KB Output is correct
52 Correct 96 ms 15548 KB Output is correct
53 Correct 101 ms 15528 KB Output is correct
54 Correct 96 ms 15528 KB Output is correct
55 Correct 56 ms 15504 KB Output is correct
56 Correct 61 ms 15528 KB Output is correct
57 Correct 76 ms 15016 KB Output is correct
58 Correct 87 ms 15552 KB Output is correct
59 Correct 91 ms 15556 KB Output is correct
60 Correct 94 ms 15508 KB Output is correct
61 Correct 90 ms 15552 KB Output is correct
62 Correct 86 ms 15512 KB Output is correct
63 Correct 90 ms 15460 KB Output is correct
64 Correct 53 ms 15504 KB Output is correct
65 Correct 53 ms 15568 KB Output is correct
66 Correct 54 ms 15560 KB Output is correct
67 Correct 59 ms 15488 KB Output is correct
68 Execution timed out 4024 ms 15404 KB Time limit exceeded
69 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4022 ms 8948 KB Time limit exceeded
2 Halted 0 ms 0 KB -