Submission #1054369

# Submission time Handle Problem Language Result Execution time Memory
1054369 2024-08-12T09:10:24 Z shiomusubi496 Radio Towers (IOI22_towers) C++17
23 / 100
4000 ms 5756 KB
#include "towers.h"
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep2(i, a, b) for (int i = (int)(b) - 1; i >= (int)(a); --i)

#define all(v) begin(v), end(v)
#define rall(v) rbegin(v), rend(v)

using namespace std;

using ll = long long;

template<class T, class U> bool chmin(T& a, const U& b) { return a > b ? a = b, true : false; }
template<class T, class U> bool chmax(T& a, const U& b) { return a < b ? a = b, true : false; }

constexpr ll inf = 1e18;

template<class M>
class SegmentTree {
    using T = typename M::T;
    int n;
    vector<T> dat;

public:
    SegmentTree(int n_, T x) {
        n = 1;
        while (n < n_) n *= 2;
        dat.assign(2 * n, x);
    }
    void set(int k, T x) {
        k += n;
        dat[k] = x;
        while (k > 1) {
            k /= 2;
            dat[k] = M::op(dat[2 * k], dat[2 * k + 1]);
        }
    }
    void apply(int k, T x) { set(k, M::op(dat[k + n], x)); }
    T prod(int l, int r) const {
        l += n; r += n;
        T lsm = M::id(), rsm = M::id();
        while (l < r) {
            if (l & 1) lsm = M::op(lsm, dat[l++]);
            if (r & 1) rsm = M::op(dat[--r], rsm);
            l >>= 1; r >>= 1;
        }
        return M::op(lsm, rsm);
    }
    T all_prod() const { return dat[1]; }
};

struct Max {
    using T = ll;
    static T op(T a, T b) { return max(a, b); }
    static T id() { return -inf; }
};


int N;
vector<int> H, Hs;

void init(int N_, std::vector<int> H_) {
    N = N_; H = H_;
    Hs = H;
    sort(all(Hs));
    Hs.erase(unique(all(Hs)), Hs.end());
    rep (i, N) H[i] = lower_bound(all(Hs), H[i]) - Hs.begin();
}

int max_towers(int L, int R, int D) {
    ++R;
    SegmentTree<Max> seg1(N + 1, -inf), seg2(N + 1, -inf);
    seg2.set(N, 0);
    rep2 (i, L, R) {
        ll t = seg2.prod(lower_bound(all(Hs), Hs[H[i]] + D) - Hs.begin(), N + 1) + 1;
        seg1.set(H[i], t);
        t = seg1.prod(0, upper_bound(all(Hs), Hs[H[i]] - D) - Hs.begin());
        seg2.set(H[i], t);
    }
    return seg1.all_prod();
}
# Verdict Execution time Memory Grader output
1 Execution timed out 4038 ms 3244 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 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 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 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 0 ms 344 KB Output is correct
19 Correct 0 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 344 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 344 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 0 ms 344 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 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 0 ms 344 KB Output is correct
19 Correct 0 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 344 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 344 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 0 ms 344 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
36 Correct 19 ms 3160 KB Output is correct
37 Correct 28 ms 5556 KB Output is correct
38 Correct 26 ms 5580 KB Output is correct
39 Correct 26 ms 5584 KB Output is correct
40 Correct 25 ms 5556 KB Output is correct
41 Correct 42 ms 5576 KB Output is correct
42 Correct 27 ms 5584 KB Output is correct
43 Correct 23 ms 5584 KB Output is correct
44 Correct 14 ms 5552 KB Output is correct
45 Correct 12 ms 5584 KB Output is correct
46 Correct 13 ms 5584 KB Output is correct
47 Correct 34 ms 5584 KB Output is correct
48 Correct 27 ms 5704 KB Output is correct
49 Correct 24 ms 5584 KB Output is correct
50 Correct 16 ms 5584 KB Output is correct
51 Correct 19 ms 5640 KB Output is correct
52 Correct 52 ms 5584 KB Output is correct
53 Correct 59 ms 5572 KB Output is correct
54 Correct 53 ms 5576 KB Output is correct
55 Correct 31 ms 5584 KB Output is correct
56 Correct 33 ms 5584 KB Output is correct
57 Correct 39 ms 5668 KB Output is correct
58 Correct 44 ms 5456 KB Output is correct
59 Correct 49 ms 5576 KB Output is correct
60 Correct 61 ms 5576 KB Output is correct
61 Correct 54 ms 5584 KB Output is correct
62 Correct 45 ms 5704 KB Output is correct
63 Correct 50 ms 5708 KB Output is correct
64 Correct 27 ms 5584 KB Output is correct
65 Correct 29 ms 5564 KB Output is correct
66 Correct 26 ms 5584 KB Output is correct
67 Correct 29 ms 5744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 4043 ms 5756 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4029 ms 1744 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 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 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 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 0 ms 344 KB Output is correct
19 Correct 0 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 344 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 344 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 0 ms 344 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
36 Correct 19 ms 3160 KB Output is correct
37 Correct 28 ms 5556 KB Output is correct
38 Correct 26 ms 5580 KB Output is correct
39 Correct 26 ms 5584 KB Output is correct
40 Correct 25 ms 5556 KB Output is correct
41 Correct 42 ms 5576 KB Output is correct
42 Correct 27 ms 5584 KB Output is correct
43 Correct 23 ms 5584 KB Output is correct
44 Correct 14 ms 5552 KB Output is correct
45 Correct 12 ms 5584 KB Output is correct
46 Correct 13 ms 5584 KB Output is correct
47 Correct 34 ms 5584 KB Output is correct
48 Correct 27 ms 5704 KB Output is correct
49 Correct 24 ms 5584 KB Output is correct
50 Correct 16 ms 5584 KB Output is correct
51 Correct 19 ms 5640 KB Output is correct
52 Correct 52 ms 5584 KB Output is correct
53 Correct 59 ms 5572 KB Output is correct
54 Correct 53 ms 5576 KB Output is correct
55 Correct 31 ms 5584 KB Output is correct
56 Correct 33 ms 5584 KB Output is correct
57 Correct 39 ms 5668 KB Output is correct
58 Correct 44 ms 5456 KB Output is correct
59 Correct 49 ms 5576 KB Output is correct
60 Correct 61 ms 5576 KB Output is correct
61 Correct 54 ms 5584 KB Output is correct
62 Correct 45 ms 5704 KB Output is correct
63 Correct 50 ms 5708 KB Output is correct
64 Correct 27 ms 5584 KB Output is correct
65 Correct 29 ms 5564 KB Output is correct
66 Correct 26 ms 5584 KB Output is correct
67 Correct 29 ms 5744 KB Output is correct
68 Execution timed out 4043 ms 5756 KB Time limit exceeded
69 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4038 ms 3244 KB Time limit exceeded
2 Halted 0 ms 0 KB -