# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
402662 |
2021-05-12T08:16:31 Z |
KoD |
Bulldozer (JOI17_bulldozer) |
C++17 |
|
2000 ms |
167776 KB |
#include <bits/stdc++.h>
using i32 = std::int32_t;
using u32 = std::uint32_t;
using i64 = std::int64_t;
using u64 = std::uint64_t;
using i128 = __int128_t;
using u128 = __uint128_t;
using isize = std::ptrdiff_t;
using usize = std::size_t;
class rep {
struct Iter {
usize itr;
constexpr Iter(const usize pos) noexcept : itr(pos) {}
constexpr void operator++() noexcept { ++itr; }
constexpr bool operator!=(const Iter& other) const noexcept { return itr != other.itr; }
constexpr usize operator*() const noexcept { return itr; }
};
const Iter first, last;
public:
explicit constexpr rep(const usize first, const usize last) noexcept : first(first), last(std::max(first, last)) {}
constexpr Iter begin() const noexcept { return first; }
constexpr Iter end() const noexcept { return last; }
};
template <class T, T Div = 2> constexpr T INFTY = std::numeric_limits<T>::max() / Div;
template <class T> bool setmax(T& lhs, const T& rhs) {
if (lhs < rhs) {
lhs = rhs;
return true;
}
return false;
}
class revrep {
struct Iter {
usize itr;
constexpr Iter(const usize pos) noexcept : itr(pos) {}
constexpr void operator++() noexcept { --itr; }
constexpr bool operator!=(const Iter& other) const noexcept { return itr != other.itr; }
constexpr usize operator*() const noexcept { return itr; }
};
const Iter first, last;
public:
explicit constexpr revrep(const usize first, const usize last) noexcept
: first(last - 1), last(std::min(first, last) - 1) {}
constexpr Iter begin() const noexcept { return first; }
constexpr Iter end() const noexcept { return last; }
};
constexpr u64 ceil_log2(const u64 x) {
u64 e = 0;
while (((u64)1 << e) < x) ++e;
return e;
}
template <class Monoid> class SegmentTree {
using M = Monoid;
usize internal_size, seg_size;
std::vector<M> data;
void fetch(const usize k) { data[k] = data[2 * k] + data[2 * k + 1]; }
public:
explicit SegmentTree(const usize size = 0, const M& value = M::zero()) : SegmentTree(std::vector<M>(size, value)) {}
explicit SegmentTree(const std::vector<M>& vec) : internal_size(vec.size()) {
seg_size = 1 << ceil_log2(internal_size);
data = std::vector<M>(2 * seg_size, M::zero());
for (const usize i : rep(0, internal_size)) data[seg_size + i] = vec[i];
for (const usize i : revrep(1, seg_size)) fetch(i);
}
usize size() const { return internal_size; }
void assign(usize i, const M& value) {
assert(i < internal_size);
i += seg_size;
data[i] = value;
while (i > 1) {
i >>= 1;
fetch(i);
}
}
M fold() const { return data[1]; }
M fold(usize l, usize r) const {
assert(l <= r and r <= internal_size);
l += seg_size;
r += seg_size;
M ret_l = M::zero(), ret_r = M::zero();
while (l < r) {
if (l & 1) ret_l = ret_l + data[l++];
if (r & 1) ret_r = data[--r] + ret_r;
l >>= 1;
r >>= 1;
}
return ret_l + ret_r;
}
template <class F> usize max_right(usize l, const F& f) const {
assert(l <= internal_size);
assert(f(M::zero()));
if (l == internal_size) return internal_size;
l += seg_size;
M sum = M::zero();
do {
while (!(l & 1)) l >>= 1;
if (!f(sum + data[l])) {
while (l < seg_size) {
l = 2 * l;
if (f(sum + data[l])) sum = sum + data[l++];
}
return l - seg_size;
}
sum = sum + data[l++];
} while ((l & -l) != l);
return internal_size;
}
template <class F> usize min_left(usize r, const F& f) const {
assert(r <= internal_size);
assert(f(M::zero()));
if (r == 0) return 0;
r += seg_size;
M sum = M::zero();
do {
r -= 1;
while (r > 1 and (r & 1)) r >>= 1;
if (!f(data[r] + sum)) {
while (r < seg_size) {
r = 2 * r + 1;
if (f(data[r] + sum)) sum = data[r--] + sum;
}
return r + 1 - seg_size;
}
sum = data[r] + sum;
} while ((r & -r) != r);
return 0;
}
};
template <class T> using Vec = std::vector<T>;
struct Dir {
i64 x, y;
Dir(const i64 a, const i64 b) : x(a), y(b) {
const auto g = std::gcd(x, y);
x /= g;
y /= g;
}
bool operator<(const Dir& other) const { return (x * other.y) - (y * other.x) > 0; }
};
struct Monoid {
i64 min, max, dif;
Monoid(const i64 min, const i64 max, const i64 dif) : min(min), max(max), dif(dif) {}
Monoid(const i64 val = 0) : min(val), max(val), dif(0) {}
static Monoid zero() { return Monoid(INFTY<i64>, -INFTY<i64>, -INFTY<i64>); }
Monoid operator+(const Monoid& other) const {
return Monoid(std::min(min, other.min), std::max(max, other.max), std::max({dif, other.dif, other.max - min}));
}
};
void JOI17_bulldozer_main() {
usize N;
std::cin >> N;
Vec<i64> X(N), Y(N), W(N);
for (const auto i : rep(0, N)) {
std::cin >> X[i] >> Y[i] >> W[i];
}
Vec<usize> order(N);
std::iota(order.begin(), order.end(), (usize)0);
std::sort(order.begin(), order.end(),
[&](const usize i, const usize j) { return X[i] < X[j] or (X[i] == X[j] and Y[i] < Y[j]); });
std::map<Dir, Vec<std::pair<usize, usize>>> swap;
for (const auto i : order) {
for (const auto j : order) {
if (i == j) {
continue;
}
Dir dir(Y[i] - Y[j], X[j] - X[i]);
if (dir.y < 0 or (dir.x > 0 and dir.y == 0)) {
continue;
}
swap[dir].emplace_back(i, j);
}
}
Vec<i64> sum(N + 1);
Vec<Monoid> mnd(N + 1);
Vec<usize> inv(N);
for (const auto i : rep(0, N)) {
const auto k = order[i];
sum[i + 1] = sum[i] + W[k];
mnd[i + 1] = Monoid(sum[i + 1]);
inv[k] = i;
}
SegmentTree<Monoid> seg(mnd);
i64 ans = seg.fold().dif;
for (const auto& [dir, vec] : swap) {
for (auto [i, j] : vec) {
if (inv[i] > inv[j]) {
std::swap(i, j);
}
const auto l = inv[i];
const auto r = inv[j];
assert(l + 1 == r);
sum[l + 1] = sum[l] + W[j];
sum[r + 1] = sum[l + 1] + W[i];
seg.assign(l + 1, Monoid(sum[l + 1]));
seg.assign(r + 1, Monoid(sum[r + 1]));
inv[i] = r;
inv[j] = l;
}
setmax(ans, seg.fold().dif);
}
std::cout << ans << '\n';
}
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
JOI17_bulldozer_main();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
460 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
2 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
444 KB |
Output is correct |
9 |
Correct |
2 ms |
460 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
308 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
844 KB |
Output is correct |
2 |
Correct |
4 ms |
844 KB |
Output is correct |
3 |
Correct |
4 ms |
844 KB |
Output is correct |
4 |
Correct |
4 ms |
844 KB |
Output is correct |
5 |
Correct |
4 ms |
820 KB |
Output is correct |
6 |
Correct |
4 ms |
844 KB |
Output is correct |
7 |
Correct |
4 ms |
844 KB |
Output is correct |
8 |
Correct |
4 ms |
844 KB |
Output is correct |
9 |
Correct |
4 ms |
756 KB |
Output is correct |
10 |
Correct |
4 ms |
844 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
3 ms |
820 KB |
Output is correct |
22 |
Correct |
4 ms |
844 KB |
Output is correct |
23 |
Correct |
5 ms |
844 KB |
Output is correct |
24 |
Correct |
4 ms |
844 KB |
Output is correct |
25 |
Correct |
5 ms |
844 KB |
Output is correct |
26 |
Correct |
6 ms |
844 KB |
Output is correct |
27 |
Correct |
5 ms |
824 KB |
Output is correct |
28 |
Correct |
4 ms |
844 KB |
Output is correct |
29 |
Correct |
5 ms |
844 KB |
Output is correct |
30 |
Correct |
4 ms |
844 KB |
Output is correct |
31 |
Correct |
4 ms |
824 KB |
Output is correct |
32 |
Correct |
4 ms |
844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
844 KB |
Output is correct |
2 |
Correct |
4 ms |
844 KB |
Output is correct |
3 |
Correct |
4 ms |
844 KB |
Output is correct |
4 |
Correct |
4 ms |
844 KB |
Output is correct |
5 |
Correct |
4 ms |
820 KB |
Output is correct |
6 |
Correct |
4 ms |
844 KB |
Output is correct |
7 |
Correct |
4 ms |
844 KB |
Output is correct |
8 |
Correct |
4 ms |
844 KB |
Output is correct |
9 |
Correct |
4 ms |
756 KB |
Output is correct |
10 |
Correct |
4 ms |
844 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
3 ms |
820 KB |
Output is correct |
22 |
Correct |
4 ms |
844 KB |
Output is correct |
23 |
Correct |
5 ms |
844 KB |
Output is correct |
24 |
Correct |
4 ms |
844 KB |
Output is correct |
25 |
Correct |
5 ms |
844 KB |
Output is correct |
26 |
Correct |
6 ms |
844 KB |
Output is correct |
27 |
Correct |
5 ms |
824 KB |
Output is correct |
28 |
Correct |
4 ms |
844 KB |
Output is correct |
29 |
Correct |
5 ms |
844 KB |
Output is correct |
30 |
Correct |
4 ms |
844 KB |
Output is correct |
31 |
Correct |
4 ms |
824 KB |
Output is correct |
32 |
Correct |
4 ms |
844 KB |
Output is correct |
33 |
Execution timed out |
2075 ms |
167776 KB |
Time limit exceeded |
34 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
844 KB |
Output is correct |
2 |
Correct |
4 ms |
844 KB |
Output is correct |
3 |
Correct |
4 ms |
844 KB |
Output is correct |
4 |
Correct |
4 ms |
844 KB |
Output is correct |
5 |
Correct |
4 ms |
820 KB |
Output is correct |
6 |
Correct |
4 ms |
844 KB |
Output is correct |
7 |
Correct |
4 ms |
844 KB |
Output is correct |
8 |
Correct |
4 ms |
844 KB |
Output is correct |
9 |
Correct |
4 ms |
756 KB |
Output is correct |
10 |
Correct |
4 ms |
844 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
3 ms |
820 KB |
Output is correct |
22 |
Correct |
4 ms |
844 KB |
Output is correct |
23 |
Correct |
5 ms |
844 KB |
Output is correct |
24 |
Correct |
4 ms |
844 KB |
Output is correct |
25 |
Correct |
5 ms |
844 KB |
Output is correct |
26 |
Correct |
6 ms |
844 KB |
Output is correct |
27 |
Correct |
5 ms |
824 KB |
Output is correct |
28 |
Correct |
4 ms |
844 KB |
Output is correct |
29 |
Correct |
5 ms |
844 KB |
Output is correct |
30 |
Correct |
4 ms |
844 KB |
Output is correct |
31 |
Correct |
4 ms |
824 KB |
Output is correct |
32 |
Correct |
4 ms |
844 KB |
Output is correct |
33 |
Execution timed out |
2075 ms |
167776 KB |
Time limit exceeded |
34 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
460 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
2 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
444 KB |
Output is correct |
9 |
Correct |
2 ms |
460 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
308 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
4 ms |
844 KB |
Output is correct |
17 |
Correct |
4 ms |
844 KB |
Output is correct |
18 |
Correct |
4 ms |
844 KB |
Output is correct |
19 |
Correct |
4 ms |
844 KB |
Output is correct |
20 |
Correct |
4 ms |
820 KB |
Output is correct |
21 |
Correct |
4 ms |
844 KB |
Output is correct |
22 |
Correct |
4 ms |
844 KB |
Output is correct |
23 |
Correct |
4 ms |
844 KB |
Output is correct |
24 |
Correct |
4 ms |
756 KB |
Output is correct |
25 |
Correct |
4 ms |
844 KB |
Output is correct |
26 |
Correct |
1 ms |
204 KB |
Output is correct |
27 |
Correct |
1 ms |
204 KB |
Output is correct |
28 |
Correct |
1 ms |
204 KB |
Output is correct |
29 |
Correct |
1 ms |
204 KB |
Output is correct |
30 |
Correct |
1 ms |
204 KB |
Output is correct |
31 |
Correct |
1 ms |
204 KB |
Output is correct |
32 |
Correct |
1 ms |
204 KB |
Output is correct |
33 |
Correct |
1 ms |
204 KB |
Output is correct |
34 |
Correct |
1 ms |
204 KB |
Output is correct |
35 |
Correct |
1 ms |
204 KB |
Output is correct |
36 |
Correct |
3 ms |
820 KB |
Output is correct |
37 |
Correct |
4 ms |
844 KB |
Output is correct |
38 |
Correct |
5 ms |
844 KB |
Output is correct |
39 |
Correct |
4 ms |
844 KB |
Output is correct |
40 |
Correct |
5 ms |
844 KB |
Output is correct |
41 |
Correct |
6 ms |
844 KB |
Output is correct |
42 |
Correct |
5 ms |
824 KB |
Output is correct |
43 |
Correct |
4 ms |
844 KB |
Output is correct |
44 |
Correct |
5 ms |
844 KB |
Output is correct |
45 |
Correct |
4 ms |
844 KB |
Output is correct |
46 |
Correct |
4 ms |
824 KB |
Output is correct |
47 |
Correct |
4 ms |
844 KB |
Output is correct |
48 |
Execution timed out |
2075 ms |
167776 KB |
Time limit exceeded |
49 |
Halted |
0 ms |
0 KB |
- |