結果
問題 | No.2248 max(C)-min(C) |
ユーザー | ruthen71 |
提出日時 | 2023-03-17 23:35:48 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,497 bytes |
コンパイル時間 | 2,458 ms |
コンパイル使用メモリ | 213,948 KB |
実行使用メモリ | 18,204 KB |
最終ジャッジ日時 | 2024-09-18 12:34:47 |
合計ジャッジ時間 | 9,194 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
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 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | WA | - |
testcase_41 | WA | - |
testcase_42 | WA | - |
testcase_43 | WA | - |
testcase_44 | WA | - |
testcase_45 | WA | - |
testcase_46 | WA | - |
testcase_47 | WA | - |
testcase_48 | AC | 136 ms
17,944 KB |
testcase_49 | WA | - |
testcase_50 | WA | - |
testcase_51 | WA | - |
testcase_52 | WA | - |
testcase_53 | WA | - |
ソースコード
#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<int> A(N), B(N); rep(i, N) cin >> A[i]; rep(i, N) cin >> B[i]; V<int> C(N); rep(i, N) { if (A[i] > B[i]) swap(A[i], B[i]); C[i] = (A[i] + B[i]) / 2; } V<tuple<int, 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<int>> seg(N); rep(i, N) seg.set(i, A[i]); sort(G.begin(), G.end()); constexpr int INF = 1 << 30; int 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; }