結果

問題 No.2009 Drunkers' Contest
ユーザー NyaanNyaanNyaanNyaan
提出日時 2022-07-15 23:11:59
言語 Text
(cat 8.3)
結果
WA  
実行時間 -
コード長 2,751 bytes
コンパイル時間 225 ms
コンパイル使用メモリ 5,332 KB
実行使用メモリ 4,512 KB
最終ジャッジ日時 2023-09-10 04:49:11
合計ジャッジ時間 4,165 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
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 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

// 嘘を実装してました 逃亡

#include "template/template.hpp"
//
#include "segment-tree/lazy-segment-tree.hpp"
using namespace Nyaan;

struct D {
  double a, b, c;
  D() : a(0), b(0), c(0) {}
  D(double _a, double _b, double _c) : a(_a), b(_b), c(_c) {}
  double eval(double x) { return a / x + b * x + c; }
};
struct E {
  int f;
  double a, b, c;
  E() : f(-1), a(0), b(0), c(0) {}
  E(int _f, double _a, double _b, double _c) : f(_f), a(_a), b(_b), c(_c) {}
  bool operator==(const E& rhs) { return f == rhs.f; }
};

// range add range update
// 二分探索は手元でやる
void q() {
  auto f = [&](D a, D) -> D { return a; };
  auto g = [&](D a, E b) -> D {
    if (b.f == -1) return a;
    if (b.f == 1) {
      a.a += b.a, a.b += b.b, a.c += b.c;
      return a;
    }
    if (b.f == 2) {
      a.a = b.a, a.b = b.b, a.c = b.c;
      return a;
    }
    exit(1);
  };
  auto h = [&](E a, E b) -> E {
    if (b.f == -1) return a;
    if (b.f == 1) {
      if (a.f == -1) return b;
      a.a += b.a, a.b += b.b, a.c += b.c;
      return a;
    }
    if (b.f == 2) {
      return b;
    }
    exit(1);
  };
  D ti{};
  E ei{};

  inl(N);
  vl A(N), B(N);
  in(A, B);

  V<pair<double, int>> p;
  p.emplace_back(1, -1);
  rep(i, N) p.emplace_back(sqrt(A[i] / B[i]), i);
  sort(all(p));
  vi inv(N, -1);
  int th = -1;
  rep(i, sz(p)) {
    if (p[i].se != -1) inv[p[i].se] = i;
    if (p[i].se == -1) th = p[i].se;
  }
  trc(p);

  V<D> init(sz(p));
  LazySegmentTree seg(init, f, g, h, ti, ei);

  repr(i, N) {
    {
      int f = 1;
      double a = A[i];
      double b = B[i];
      double c = 0;
      seg.update(0, sz(p), E{f, a, b, c});
    }
    int L = -1, R = sz(p);
    while (L + 2 < R) {
      int i1 = (L + L + R) / 3;
      int i2 = (L + R + R) / 3;
      double x1 = p[i1].fi;
      double x2 = p[i2].fi;
      double y1 = seg.get_val(i1).eval(x1);
      double y2 = seg.get_val(i2).eval(x2);
      if (y1 < y2) {
        R = i2;
      } else {
        L = i1;
      }
    }
    int key = (L + R) / 2;
    double x = p[key].fi;
    D data = seg.get_val(key);
    double val = data.eval(x);
    seg.update(0, key + 1, E{2, 0., 0., val});
  }

  {
    int L = th - 1, R = sz(p);
    while (L + 2 < R) {
      int i1 = (L + L + R) / 3;
      int i2 = (L + R + R) / 3;
      double x1 = p[i1].fi;
      double x2 = p[i2].fi;
      double y1 = seg.get_val(i1).eval(x1);
      double y2 = seg.get_val(i2).eval(x2);
      if (y1 < y2) {
        R = i2;
      } else {
        L = i1;
      }
    }
    int key = (L + R) / 2;
    double x = p[key].fi;
    D data = seg.get_val(key);
    double val = data.eval(x);
    trc(key, x, val);
    out(val);
  }
}

void Nyaan::solve() {
  int T = 1;
  // in(T);
  while (T--) q();
}
0