Submission #1054420

# Submission time Handle Problem Language Result Execution time Memory
1054420 2024-08-12T09:44:20 Z shiomusubi496 Radio Towers (IOI22_towers) C++17
4 / 100
570 ms 16336 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() = default;
    SegmentTree(int n_, T x) {
        n = 1;
        while (n < n_) n *= 2;
        dat.assign(2 * n, x);
    }
    SegmentTree(vector<T> a) {
        n = 1;
        while (n < a.size()) n *= 2;
        dat.assign(2 * n, M::id());
        rep (i, a.size()) dat[i + n] = a[i];
        rrep2 (i, 1, n) dat[i] = M::op(dat[2 * i], dat[2 * i + 1]);
    }
    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]; }
    T get(int k) const { return dat[k + n]; }
};

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

struct Sum {
    using T = ll;
    static T op(T a, T b) { return a + b; }
    static T id() { return 0; }
};

struct Monoid {
    using T = tuple<ll, ll, ll>;
    static T op(T a, T b) {
        auto [a1, a2, a3] = a;
        auto [b1, b2, b3] = b;
        return {a1 + b1, min(a2, b2), max(a3, b3)};
    }
    static T id() { return {0, inf, -inf}; }
};

int N;
vector<int> H, Hs;

SegmentTree<Monoid> seg1, seg2;
SegmentTree<Max> rmq;

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();

    rmq = SegmentTree<Max>(N, -inf);
    rep (i, N) rmq.set(i, H[i]);

    seg1 = seg2 = SegmentTree<Monoid>(N, {0, inf, -inf});
    rep (i, N) {
        if ((i == 0 || H[i - 1] > H[i]) && (i == N - 1 || H[i] < H[i + 1])) seg1.set(i, {1, i, i});
    }
    rep (i, N) {
        if ((i == 0 || H[i - 1] < H[i]) && (i == N - 1 || H[i] > H[i + 1])) seg2.set(i, {1, i, i});
    }
}

int max_towers(int L, int R, int D) {
    ++R;
    auto [s, l, r] = seg2.prod(L, R);
    if (s == 0) return 1;
    int res = s - 1;
    if (Hs[H[L]] + D <= Hs[H[l]]) ++res;
    if (Hs[H[R - 1]] + D <= Hs[H[r]]) ++res;
    return max(res, 1);
}
# Verdict Execution time Memory Grader output
1 Correct 248 ms 8536 KB Output is correct
2 Correct 473 ms 16216 KB Output is correct
3 Correct 569 ms 16216 KB Output is correct
4 Correct 502 ms 16216 KB Output is correct
5 Correct 570 ms 16272 KB Output is correct
6 Correct 558 ms 16336 KB Output is correct
7 Correct 481 ms 16216 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 600 KB Output is correct
10 Correct 0 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB 1st lines differ - on the 1st token, expected: '13', found: '16'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB 1st lines differ - on the 1st token, expected: '13', found: '16'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 358 ms 16208 KB 9th lines differ - on the 1st token, expected: '22097', found: '22096'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 166 ms 4400 KB 1st lines differ - on the 1st token, expected: '7197', found: '8004'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB 1st lines differ - on the 1st token, expected: '13', found: '16'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 248 ms 8536 KB Output is correct
2 Correct 473 ms 16216 KB Output is correct
3 Correct 569 ms 16216 KB Output is correct
4 Correct 502 ms 16216 KB Output is correct
5 Correct 570 ms 16272 KB Output is correct
6 Correct 558 ms 16336 KB Output is correct
7 Correct 481 ms 16216 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 600 KB Output is correct
10 Correct 0 ms 600 KB Output is correct
11 Incorrect 0 ms 344 KB 1st lines differ - on the 1st token, expected: '13', found: '16'
12 Halted 0 ms 0 KB -