結果
問題 | No.2248 max(C)-min(C) |
ユーザー | ruthen |
提出日時 | 2023-03-17 23:38:49 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 197 ms / 3,000 ms |
コード長 | 4,535 bytes |
コンパイル時間 | 2,383 ms |
コンパイル使用メモリ | 214,252 KB |
実行使用メモリ | 24,512 KB |
最終ジャッジ日時 | 2024-09-18 12:36:05 |
合計ジャッジ時間 | 9,524 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 3 ms
5,376 KB |
testcase_07 | AC | 3 ms
5,376 KB |
testcase_08 | AC | 3 ms
5,376 KB |
testcase_09 | AC | 3 ms
5,376 KB |
testcase_10 | AC | 2 ms
5,376 KB |
testcase_11 | AC | 3 ms
5,376 KB |
testcase_12 | AC | 3 ms
5,376 KB |
testcase_13 | AC | 3 ms
5,376 KB |
testcase_14 | AC | 4 ms
5,376 KB |
testcase_15 | AC | 4 ms
5,376 KB |
testcase_16 | AC | 2 ms
5,376 KB |
testcase_17 | AC | 3 ms
5,376 KB |
testcase_18 | AC | 156 ms
20,952 KB |
testcase_19 | AC | 19 ms
5,896 KB |
testcase_20 | AC | 197 ms
24,380 KB |
testcase_21 | AC | 182 ms
24,144 KB |
testcase_22 | AC | 121 ms
17,548 KB |
testcase_23 | AC | 74 ms
11,928 KB |
testcase_24 | AC | 28 ms
6,784 KB |
testcase_25 | AC | 181 ms
24,080 KB |
testcase_26 | AC | 146 ms
19,752 KB |
testcase_27 | AC | 175 ms
23,792 KB |
testcase_28 | AC | 15 ms
5,376 KB |
testcase_29 | AC | 150 ms
20,400 KB |
testcase_30 | AC | 58 ms
10,536 KB |
testcase_31 | AC | 189 ms
24,504 KB |
testcase_32 | AC | 31 ms
7,144 KB |
testcase_33 | AC | 51 ms
9,120 KB |
testcase_34 | AC | 191 ms
24,512 KB |
testcase_35 | AC | 188 ms
24,508 KB |
testcase_36 | AC | 187 ms
24,376 KB |
testcase_37 | AC | 92 ms
13,948 KB |
testcase_38 | AC | 184 ms
24,504 KB |
testcase_39 | AC | 185 ms
24,380 KB |
testcase_40 | AC | 187 ms
24,380 KB |
testcase_41 | AC | 151 ms
20,628 KB |
testcase_42 | AC | 183 ms
24,384 KB |
testcase_43 | AC | 165 ms
23,972 KB |
testcase_44 | AC | 182 ms
24,376 KB |
testcase_45 | AC | 136 ms
19,372 KB |
testcase_46 | AC | 68 ms
11,620 KB |
testcase_47 | AC | 185 ms
24,376 KB |
testcase_48 | AC | 135 ms
24,508 KB |
testcase_49 | AC | 179 ms
24,380 KB |
testcase_50 | AC | 179 ms
24,372 KB |
testcase_51 | AC | 179 ms
24,452 KB |
testcase_52 | AC | 179 ms
24,384 KB |
testcase_53 | AC | 27 ms
6,772 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; #ifdef _RUTHEN #include <debug.hpp> #else #define show(...) true #endif using ll = long long; #define rep(i, n) for (int i = 0; i < (n); i++) template <class T> using V = vector<T>; template <class Monoid> struct SegmentTree { public: using S = typename Monoid::value_type; SegmentTree() : SegmentTree(0) {} SegmentTree(int n) : SegmentTree(std::vector<S>(n, Monoid::e())) {} SegmentTree(const std::vector<S>& v) : _n((int)v.size()) { log = 0; while ((1U << log) < (unsigned int)(_n)) log++; size = 1 << log; d = std::vector<S>(size << 1, Monoid::e()); for (int i = 0; i < _n; i++) d[i + size] = v[i]; for (int i = size - 1; i >= 1; i--) { update(i); } } void set(int p, const S& x) { assert(0 <= p and p < _n); p += size; d[p] = x; for (int i = 1; i <= log; i++) update(p >> i); } void chset(int p, const S& x) { assert(0 <= p and p < _n); p += size; d[p] = Monoid::op(d[p], x); for (int i = 1; i <= log; i++) update(p >> i); } S operator[](int p) const { assert(0 <= p and p < _n); return d[p + size]; } S get(int p) const { assert(0 <= p && p < _n); return d[p + size]; } S prod(int l, int r) const { assert(0 <= l and l <= r and r <= _n); S sml = Monoid::e(), smr = Monoid::e(); l += size; r += size; while (l < r) { if (l & 1) sml = Monoid::op(sml, d[l++]); if (r & 1) smr = Monoid::op(d[--r], smr); l >>= 1; r >>= 1; } return Monoid::op(sml, smr); } S all_prod() const { return d[1]; } template <class F> int max_right(int l, F& f) const { assert(0 <= l and l <= _n); assert(f(Monoid::e())); if (l == _n) return _n; l += size; S sm = Monoid::e(); do { while ((l & 1) == 0) l >>= 1; if (!f(Monoid::op(sm, d[l]))) { while (l < size) { l <<= 1; if (f(Monoid::op(sm, d[l]))) { sm = Monoid::op(sm, d[l]); l++; } } return l - size; } sm = Monoid::op(sm, d[l]); l++; } while ((l & -l) != l); // 2べきまたは0のときfalse return _n; } template <class F> int min_left(int r, F& f) const { assert(0 <= r and r <= _n); assert(f(Monoid::e())); if (r == 0) return 0; r += size; S sm = Monoid::e(); do { r--; while (r > 1 and (r & 1)) r >>= 1; if (!f(Monoid::op(d[r], sm))) { while (r < size) { r = (r << 1) | 1; if (f(Monoid::op(d[r], sm))) { sm = Monoid::op(d[r], sm); r--; } } return r + 1 - size; } sm = Monoid::op(d[r], sm); } while ((r & -r) != r); // 2べきまたは0のときfalse return 0; } private: int _n, log, size; std::vector<S> d; inline void update(int k) { d[k] = Monoid::op(d[k << 1], d[(k << 1) | 1]); } }; template <class S> struct MonoidMax { using value_type = S; static constexpr S op(S a, S b) { return std::max(a, b); } static constexpr S e() { return std::numeric_limits<S>::lowest(); } }; int main() { ios::sync_with_stdio(false); cin.tie(0); int N; cin >> N; V<long long> A(N), B(N); rep(i, N) cin >> A[i]; rep(i, N) cin >> B[i]; V<long long> C(N); rep(i, N) { if (A[i] > B[i]) swap(A[i], B[i]); C[i] = (A[i] + B[i]) / 2; } V<tuple<long long, int, int>> G; rep(i, N) { G.push_back({A[i], 0, i}); G.push_back({C[i], 1, i}); G.push_back({B[i], 2, i}); } SegmentTree<MonoidMax<long long>> seg(N); rep(i, N) seg.set(i, A[i]); sort(G.begin(), G.end()); constexpr long long INF = 1LL << 60; long long ans = INF; for (auto [v, t, i] : G) { ans = min(ans, seg.all_prod() - v); if (t == 0) { seg.set(i, C[i]); } else if (t == 1) { seg.set(i, B[i]); } else { seg.set(i, INF); } } cout << ans << '\n'; return 0; }