Submission #625464

# Submission time Handle Problem Language Result Execution time Memory
625464 2022-08-10T12:05:48 Z model_code Radio Towers (IOI22_towers) C++17
56 / 100
4000 ms 158580 KB
// time_limit/solution-constant-d.cpp
#ifndef ATCODER_INTERNAL_BITOP_HPP
#define ATCODER_INTERNAL_BITOP_HPP 1

#ifdef _MSC_VER
#include <intrin.h>
#endif

namespace atcoder {

namespace internal {

// @param n `0 <= n`
// @return minimum non-negative `x` s.t. `n <= 2**x`
int ceil_pow2(int n) {
    int x = 0;
    while ((1U << x) < (unsigned int)(n)) x++;
    return x;
}

// @param n `1 <= n`
// @return minimum non-negative `x` s.t. `(n & (1 << x)) != 0`
constexpr int bsf_constexpr(unsigned int n) {
    int x = 0;
    while (!(n & (1 << x))) x++;
    return x;
}

// @param n `1 <= n`
// @return minimum non-negative `x` s.t. `(n & (1 << x)) != 0`
int bsf(unsigned int n) {
#ifdef _MSC_VER
    unsigned long index;
    _BitScanForward(&index, n);
    return index;
#else
    return __builtin_ctz(n);
#endif
}

}  // namespace internal

}  // namespace atcoder

#endif  // ATCODER_INTERNAL_BITOP_HPP

#ifndef ATCODER_SEGTREE_HPP
#define ATCODER_SEGTREE_HPP 1

#include <algorithm>
#include <cassert>
#include <vector>

namespace atcoder {

template <class S, S (*op)(S, S), S (*e)()> struct segtree {
  public:
    segtree() : segtree(0) {}
    explicit segtree(int n) : segtree(std::vector<S>(n, e())) {}
    explicit segtree(const std::vector<S>& v) : _n(int(v.size())) {
        log = internal::ceil_pow2(_n);
        size = 1 << log;
        d = std::vector<S>(2 * size, e());
        for (int i = 0; i < _n; i++) d[size + i] = v[i];
        for (int i = size - 1; i >= 1; i--) {
            update(i);
        }
    }

    void set(int p, S x) {
        assert(0 <= p && p < _n);
        p += size;
        d[p] = x;
        for (int i = 1; i <= log; i++) update(p >> i);
    }

    S get(int p) const {
        assert(0 <= p && p < _n);
        return d[p + size];
    }

    S prod(int l, int r) const {
        assert(0 <= l && l <= r && r <= _n);
        S sml = e(), smr = e();
        l += size;
        r += size;

        while (l < r) {
            if (l & 1) sml = op(sml, d[l++]);
            if (r & 1) smr = op(d[--r], smr);
            l >>= 1;
            r >>= 1;
        }
        return op(sml, smr);
    }

    S all_prod() const { return d[1]; }

    template <bool (*f)(S)> int max_right(int l) const {
        return max_right(l, [](S x) { return f(x); });
    }
    template <class F> int max_right(int l, F f) const {
        assert(0 <= l && l <= _n);
        assert(f(e()));
        if (l == _n) return _n;
        l += size;
        S sm = e();
        do {
            while (l % 2 == 0) l >>= 1;
            if (!f(op(sm, d[l]))) {
                while (l < size) {
                    l = (2 * l);
                    if (f(op(sm, d[l]))) {
                        sm = op(sm, d[l]);
                        l++;
                    }
                }
                return l - size;
            }
            sm = op(sm, d[l]);
            l++;
        } while ((l & -l) != l);
        return _n;
    }

    template <bool (*f)(S)> int min_left(int r) const {
        return min_left(r, [](S x) { return f(x); });
    }
    template <class F> int min_left(int r, F f) const {
        assert(0 <= r && r <= _n);
        assert(f(e()));
        if (r == 0) return 0;
        r += size;
        S sm = e();
        do {
            r--;
            while (r > 1 && (r % 2)) r >>= 1;
            if (!f(op(d[r], sm))) {
                while (r < size) {
                    r = (2 * r + 1);
                    if (f(op(d[r], sm))) {
                        sm = op(d[r], sm);
                        r--;
                    }
                }
                return r + 1 - size;
            }
            sm = op(d[r], sm);
        } while ((r & -r) != r);
        return 0;
    }

  private:
    int _n, size, log;
    std::vector<S> d;

    void update(int k) { d[k] = op(d[2 * k], d[2 * k + 1]); }
};

}  // namespace atcoder

#endif  // ATCODER_SEGTREE_HPP

#include "towers.h"

#include <bits/stdc++.h>
using namespace std;

int Max(int a, int b) {
  return max(a, b);
}

int Min(int a, int b) {
  return min(a, b);
}

int Large() {
  return INT_MAX >> 1;
}

int Small() {
  return -Large();
}

typedef atcoder::segtree<int, Max, Small> MaxSegtree;
typedef atcoder::segtree<int, Min, Large> MinSegtree;

int N;
vector<int> H;
MaxSegtree max_st;
MinSegtree min_st;

namespace bit {

vector<unordered_map<int, int>> bit;

void update(int x, int y, int val) {
  for (int i = x; i <= N; i += (i & -i)) {
    for (int j = y; j <= N; j += (j & -j)) {
      bit[i][j] += val;
    }
  }
}

int query(int x, int y) {
  int res = 0;
  for (int i = x; i > 0; i -= (i & -i)) {
    for (int j = y; j > 0; j -= (j & -j)) {
      if (bit[i].count(j)) {
        res += bit[i][j];
      }
    }
  }
  return res;
}

}  // namespace bit

void reset() {
  bit::bit = vector<unordered_map<int, int>>(N + 1);
}

void update(int xl, int yl, int xr, int yr, int val) {
  ++xl; ++yl; ++xr; ++yr;
  bit::update(xl, yl, val);
  bit::update(xl, yr + 1, -val);
  bit::update(xr + 1, yl, -val);
  bit::update(xr + 1, yr + 1, val);
}

int query(int x, int y) {
  ++x; ++y;
  return bit::query(x, y);
}

int lastValD = -1;

void init(int _N, std::vector<int> _H) {
  N = _N;
  H = _H;
  max_st = MaxSegtree(H);
  min_st = MinSegtree(H);
}

int max_towers(int L, int R, int D) {
  if (D != lastValD) {
    reset();
    for (int i = 0; i < N; ++i) {
      int lower_height_left = min_st.min_left(
          i, [&] (int h) { return h >= H[i]; }) - 1;
      bool ok_left =
          lower_height_left < 0 ||
          H[i] <= max_st.prod(lower_height_left, i) - D;
      int lower_height_right = min_st.max_right(
          i + 1, [&] (int h) { return h >= H[i]; });
      bool ok_right =
          lower_height_right >= N ||
          H[i] <= max_st.prod(i + 1, lower_height_right + 1) - D;
      update(ok_left ? 0 : (lower_height_left + 1), i,
            i, ok_right ? N - 1 : (lower_height_right - 1), 1);
    }
    lastValD = D;
  }
  return query(L, R);
}
# Verdict Execution time Memory Grader output
1 Execution timed out 4100 ms 68780 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 592 KB Output is correct
2 Correct 11 ms 2000 KB Output is correct
3 Correct 11 ms 1752 KB Output is correct
4 Correct 9 ms 2312 KB Output is correct
5 Correct 11 ms 2104 KB Output is correct
6 Correct 11 ms 2216 KB Output is correct
7 Correct 20 ms 1792 KB Output is correct
8 Correct 7 ms 1372 KB Output is correct
9 Correct 12 ms 2260 KB Output is correct
10 Correct 8 ms 1572 KB Output is correct
11 Correct 13 ms 2144 KB Output is correct
12 Correct 0 ms 220 KB Output is correct
13 Correct 11 ms 2168 KB Output is correct
14 Correct 12 ms 2140 KB Output is correct
15 Correct 10 ms 2032 KB Output is correct
16 Correct 11 ms 2332 KB Output is correct
17 Correct 9 ms 2256 KB Output is correct
18 Correct 12 ms 2304 KB Output is correct
19 Correct 6 ms 1408 KB Output is correct
20 Correct 10 ms 2036 KB Output is correct
21 Correct 11 ms 2264 KB Output is correct
22 Correct 10 ms 2256 KB Output is correct
23 Correct 12 ms 2256 KB Output is correct
24 Correct 7 ms 1360 KB Output is correct
25 Correct 4 ms 848 KB Output is correct
26 Correct 10 ms 1700 KB Output is correct
27 Correct 11 ms 1916 KB Output is correct
28 Correct 12 ms 2000 KB Output is correct
29 Correct 10 ms 2104 KB Output is correct
30 Correct 11 ms 1888 KB Output is correct
31 Correct 11 ms 1996 KB Output is correct
32 Correct 7 ms 1432 KB Output is correct
33 Correct 13 ms 2248 KB Output is correct
34 Correct 7 ms 1500 KB Output is correct
35 Correct 11 ms 2140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 592 KB Output is correct
2 Correct 11 ms 2000 KB Output is correct
3 Correct 11 ms 1752 KB Output is correct
4 Correct 9 ms 2312 KB Output is correct
5 Correct 11 ms 2104 KB Output is correct
6 Correct 11 ms 2216 KB Output is correct
7 Correct 20 ms 1792 KB Output is correct
8 Correct 7 ms 1372 KB Output is correct
9 Correct 12 ms 2260 KB Output is correct
10 Correct 8 ms 1572 KB Output is correct
11 Correct 13 ms 2144 KB Output is correct
12 Correct 0 ms 220 KB Output is correct
13 Correct 11 ms 2168 KB Output is correct
14 Correct 12 ms 2140 KB Output is correct
15 Correct 10 ms 2032 KB Output is correct
16 Correct 11 ms 2332 KB Output is correct
17 Correct 9 ms 2256 KB Output is correct
18 Correct 12 ms 2304 KB Output is correct
19 Correct 6 ms 1408 KB Output is correct
20 Correct 10 ms 2036 KB Output is correct
21 Correct 11 ms 2264 KB Output is correct
22 Correct 10 ms 2256 KB Output is correct
23 Correct 12 ms 2256 KB Output is correct
24 Correct 7 ms 1360 KB Output is correct
25 Correct 4 ms 848 KB Output is correct
26 Correct 10 ms 1700 KB Output is correct
27 Correct 11 ms 1916 KB Output is correct
28 Correct 12 ms 2000 KB Output is correct
29 Correct 10 ms 2104 KB Output is correct
30 Correct 11 ms 1888 KB Output is correct
31 Correct 11 ms 1996 KB Output is correct
32 Correct 7 ms 1432 KB Output is correct
33 Correct 13 ms 2248 KB Output is correct
34 Correct 7 ms 1500 KB Output is correct
35 Correct 11 ms 2140 KB Output is correct
36 Correct 699 ms 81904 KB Output is correct
37 Correct 1035 ms 109244 KB Output is correct
38 Correct 1169 ms 123556 KB Output is correct
39 Correct 934 ms 102500 KB Output is correct
40 Correct 1279 ms 154716 KB Output is correct
41 Correct 1092 ms 133000 KB Output is correct
42 Correct 1379 ms 158412 KB Output is correct
43 Correct 582 ms 83432 KB Output is correct
44 Correct 1663 ms 154172 KB Output is correct
45 Correct 841 ms 99152 KB Output is correct
46 Correct 1389 ms 137476 KB Output is correct
47 Correct 1203 ms 130356 KB Output is correct
48 Correct 1272 ms 158416 KB Output is correct
49 Correct 1267 ms 158508 KB Output is correct
50 Correct 1587 ms 154256 KB Output is correct
51 Correct 569 ms 83596 KB Output is correct
52 Correct 1148 ms 130312 KB Output is correct
53 Correct 1287 ms 158520 KB Output is correct
54 Correct 1248 ms 158476 KB Output is correct
55 Correct 1608 ms 154252 KB Output is correct
56 Correct 597 ms 83392 KB Output is correct
57 Correct 947 ms 107080 KB Output is correct
58 Correct 1131 ms 121488 KB Output is correct
59 Correct 1176 ms 125968 KB Output is correct
60 Correct 1342 ms 158488 KB Output is correct
61 Correct 1291 ms 155016 KB Output is correct
62 Correct 1215 ms 137344 KB Output is correct
63 Correct 1292 ms 155656 KB Output is correct
64 Correct 596 ms 83416 KB Output is correct
65 Correct 1628 ms 154252 KB Output is correct
66 Correct 846 ms 101200 KB Output is correct
67 Correct 1570 ms 153124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2450 ms 129604 KB Output is correct
2 Correct 2964 ms 130312 KB Output is correct
3 Correct 2911 ms 130400 KB Output is correct
4 Correct 2691 ms 158420 KB Output is correct
5 Correct 2961 ms 158420 KB Output is correct
6 Correct 2663 ms 158444 KB Output is correct
7 Correct 2962 ms 158480 KB Output is correct
8 Correct 1817 ms 83360 KB Output is correct
9 Correct 3059 ms 154252 KB Output is correct
10 Correct 2098 ms 83444 KB Output is correct
11 Correct 3200 ms 154264 KB Output is correct
12 Correct 1927 ms 83940 KB Output is correct
13 Correct 2928 ms 154252 KB Output is correct
14 Correct 0 ms 208 KB Output is correct
15 Correct 11 ms 2128 KB Output is correct
16 Correct 10 ms 2128 KB Output is correct
17 Correct 1115 ms 130428 KB Output is correct
18 Correct 1228 ms 158580 KB Output is correct
19 Correct 1358 ms 158468 KB Output is correct
20 Correct 1587 ms 154204 KB Output is correct
21 Correct 560 ms 83404 KB Output is correct
22 Correct 1168 ms 130392 KB Output is correct
23 Correct 1349 ms 158512 KB Output is correct
24 Correct 1320 ms 158460 KB Output is correct
25 Correct 1581 ms 154228 KB Output is correct
26 Correct 575 ms 83420 KB Output is correct
27 Correct 8 ms 2004 KB Output is correct
28 Correct 11 ms 2256 KB Output is correct
29 Correct 9 ms 2256 KB Output is correct
30 Correct 11 ms 2168 KB Output is correct
31 Correct 6 ms 1360 KB Output is correct
32 Correct 8 ms 2000 KB Output is correct
33 Correct 9 ms 2256 KB Output is correct
34 Correct 10 ms 2300 KB Output is correct
35 Correct 12 ms 2136 KB Output is correct
36 Correct 6 ms 1360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 4103 ms 28784 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 592 KB Output is correct
2 Correct 11 ms 2000 KB Output is correct
3 Correct 11 ms 1752 KB Output is correct
4 Correct 9 ms 2312 KB Output is correct
5 Correct 11 ms 2104 KB Output is correct
6 Correct 11 ms 2216 KB Output is correct
7 Correct 20 ms 1792 KB Output is correct
8 Correct 7 ms 1372 KB Output is correct
9 Correct 12 ms 2260 KB Output is correct
10 Correct 8 ms 1572 KB Output is correct
11 Correct 13 ms 2144 KB Output is correct
12 Correct 0 ms 220 KB Output is correct
13 Correct 11 ms 2168 KB Output is correct
14 Correct 12 ms 2140 KB Output is correct
15 Correct 10 ms 2032 KB Output is correct
16 Correct 11 ms 2332 KB Output is correct
17 Correct 9 ms 2256 KB Output is correct
18 Correct 12 ms 2304 KB Output is correct
19 Correct 6 ms 1408 KB Output is correct
20 Correct 10 ms 2036 KB Output is correct
21 Correct 11 ms 2264 KB Output is correct
22 Correct 10 ms 2256 KB Output is correct
23 Correct 12 ms 2256 KB Output is correct
24 Correct 7 ms 1360 KB Output is correct
25 Correct 4 ms 848 KB Output is correct
26 Correct 10 ms 1700 KB Output is correct
27 Correct 11 ms 1916 KB Output is correct
28 Correct 12 ms 2000 KB Output is correct
29 Correct 10 ms 2104 KB Output is correct
30 Correct 11 ms 1888 KB Output is correct
31 Correct 11 ms 1996 KB Output is correct
32 Correct 7 ms 1432 KB Output is correct
33 Correct 13 ms 2248 KB Output is correct
34 Correct 7 ms 1500 KB Output is correct
35 Correct 11 ms 2140 KB Output is correct
36 Correct 699 ms 81904 KB Output is correct
37 Correct 1035 ms 109244 KB Output is correct
38 Correct 1169 ms 123556 KB Output is correct
39 Correct 934 ms 102500 KB Output is correct
40 Correct 1279 ms 154716 KB Output is correct
41 Correct 1092 ms 133000 KB Output is correct
42 Correct 1379 ms 158412 KB Output is correct
43 Correct 582 ms 83432 KB Output is correct
44 Correct 1663 ms 154172 KB Output is correct
45 Correct 841 ms 99152 KB Output is correct
46 Correct 1389 ms 137476 KB Output is correct
47 Correct 1203 ms 130356 KB Output is correct
48 Correct 1272 ms 158416 KB Output is correct
49 Correct 1267 ms 158508 KB Output is correct
50 Correct 1587 ms 154256 KB Output is correct
51 Correct 569 ms 83596 KB Output is correct
52 Correct 1148 ms 130312 KB Output is correct
53 Correct 1287 ms 158520 KB Output is correct
54 Correct 1248 ms 158476 KB Output is correct
55 Correct 1608 ms 154252 KB Output is correct
56 Correct 597 ms 83392 KB Output is correct
57 Correct 947 ms 107080 KB Output is correct
58 Correct 1131 ms 121488 KB Output is correct
59 Correct 1176 ms 125968 KB Output is correct
60 Correct 1342 ms 158488 KB Output is correct
61 Correct 1291 ms 155016 KB Output is correct
62 Correct 1215 ms 137344 KB Output is correct
63 Correct 1292 ms 155656 KB Output is correct
64 Correct 596 ms 83416 KB Output is correct
65 Correct 1628 ms 154252 KB Output is correct
66 Correct 846 ms 101200 KB Output is correct
67 Correct 1570 ms 153124 KB Output is correct
68 Correct 2450 ms 129604 KB Output is correct
69 Correct 2964 ms 130312 KB Output is correct
70 Correct 2911 ms 130400 KB Output is correct
71 Correct 2691 ms 158420 KB Output is correct
72 Correct 2961 ms 158420 KB Output is correct
73 Correct 2663 ms 158444 KB Output is correct
74 Correct 2962 ms 158480 KB Output is correct
75 Correct 1817 ms 83360 KB Output is correct
76 Correct 3059 ms 154252 KB Output is correct
77 Correct 2098 ms 83444 KB Output is correct
78 Correct 3200 ms 154264 KB Output is correct
79 Correct 1927 ms 83940 KB Output is correct
80 Correct 2928 ms 154252 KB Output is correct
81 Correct 0 ms 208 KB Output is correct
82 Correct 11 ms 2128 KB Output is correct
83 Correct 10 ms 2128 KB Output is correct
84 Correct 1115 ms 130428 KB Output is correct
85 Correct 1228 ms 158580 KB Output is correct
86 Correct 1358 ms 158468 KB Output is correct
87 Correct 1587 ms 154204 KB Output is correct
88 Correct 560 ms 83404 KB Output is correct
89 Correct 1168 ms 130392 KB Output is correct
90 Correct 1349 ms 158512 KB Output is correct
91 Correct 1320 ms 158460 KB Output is correct
92 Correct 1581 ms 154228 KB Output is correct
93 Correct 575 ms 83420 KB Output is correct
94 Correct 8 ms 2004 KB Output is correct
95 Correct 11 ms 2256 KB Output is correct
96 Correct 9 ms 2256 KB Output is correct
97 Correct 11 ms 2168 KB Output is correct
98 Correct 6 ms 1360 KB Output is correct
99 Correct 8 ms 2000 KB Output is correct
100 Correct 9 ms 2256 KB Output is correct
101 Correct 10 ms 2300 KB Output is correct
102 Correct 12 ms 2136 KB Output is correct
103 Correct 6 ms 1360 KB Output is correct
104 Correct 2057 ms 113276 KB Output is correct
105 Correct 2467 ms 125636 KB Output is correct
106 Correct 2424 ms 115132 KB Output is correct
107 Correct 2271 ms 139532 KB Output is correct
108 Correct 1962 ms 105812 KB Output is correct
109 Correct 2490 ms 137384 KB Output is correct
110 Correct 2413 ms 158348 KB Output is correct
111 Correct 1900 ms 83392 KB Output is correct
112 Correct 2652 ms 154324 KB Output is correct
113 Correct 1929 ms 102468 KB Output is correct
114 Correct 2625 ms 145636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 4100 ms 68780 KB Time limit exceeded
2 Halted 0 ms 0 KB -