QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#628389#8775. MountainCraftmaspyAC ✓558ms43080kbC++2019.5kb2024-10-10 19:56:592024-10-10 19:57:00

Judging History

你现在查看的是最新测评结果

  • [2024-10-10 19:57:00]
  • 评测
  • 测评结果:AC
  • 用时:558ms
  • 内存:43080kb
  • [2024-10-10 19:56:59]
  • 提交

answer

#line 1 "library/my_template.hpp"
#if defined(LOCAL)
#include <my_template_compiled.hpp>
#else

// https://codeforces.com/blog/entry/96344
#pragma GCC optimize("Ofast,unroll-loops")
// いまの CF だとこれ入れると動かない?
// #pragma GCC target("avx2,popcnt")

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using u32 = unsigned int;
using u64 = unsigned long long;
using i128 = __int128;
using u128 = unsigned __int128;
using f128 = __float128;

template <class T>
constexpr T infty = 0;
template <>
constexpr int infty<int> = 1'000'000'000;
template <>
constexpr ll infty<ll> = ll(infty<int>) * infty<int> * 2;
template <>
constexpr u32 infty<u32> = infty<int>;
template <>
constexpr u64 infty<u64> = infty<ll>;
template <>
constexpr i128 infty<i128> = i128(infty<ll>) * infty<ll>;
template <>
constexpr double infty<double> = infty<ll>;
template <>
constexpr long double infty<long double> = infty<ll>;

using pi = pair<ll, ll>;
using vi = vector<ll>;
template <class T>
using vc = vector<T>;
template <class T>
using vvc = vector<vc<T>>;
template <class T>
using vvvc = vector<vvc<T>>;
template <class T>
using vvvvc = vector<vvvc<T>>;
template <class T>
using vvvvvc = vector<vvvvc<T>>;
template <class T>
using pq = priority_queue<T>;
template <class T>
using pqg = priority_queue<T, vector<T>, greater<T>>;

#define vv(type, name, h, ...) \
  vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define vvv(type, name, h, w, ...)   \
  vector<vector<vector<type>>> name( \
      h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
#define vvvv(type, name, a, b, c, ...)       \
  vector<vector<vector<vector<type>>>> name( \
      a, vector<vector<vector<type>>>(       \
             b, vector<vector<type>>(c, vector<type>(__VA_ARGS__))))

// https://trap.jp/post/1224/
#define FOR1(a) for (ll _ = 0; _ < ll(a); ++_)
#define FOR2(i, a) for (ll i = 0; i < ll(a); ++i)
#define FOR3(i, a, b) for (ll i = a; i < ll(b); ++i)
#define FOR4(i, a, b, c) for (ll i = a; i < ll(b); i += (c))
#define FOR1_R(a) for (ll i = (a)-1; i >= ll(0); --i)
#define FOR2_R(i, a) for (ll i = (a)-1; i >= ll(0); --i)
#define FOR3_R(i, a, b) for (ll i = (b)-1; i >= ll(a); --i)
#define overload4(a, b, c, d, e, ...) e
#define overload3(a, b, c, d, ...) d
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FOR_R(...) overload3(__VA_ARGS__, FOR3_R, FOR2_R, FOR1_R)(__VA_ARGS__)

#define FOR_subset(t, s) \
  for (ll t = (s); t >= 0; t = (t == 0 ? -1 : (t - 1) & (s)))
#define all(x) x.begin(), x.end()
#define len(x) ll(x.size())
#define elif else if

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second

#define stoi stoll

int popcnt(int x) { return __builtin_popcount(x); }
int popcnt(u32 x) { return __builtin_popcount(x); }
int popcnt(ll x) { return __builtin_popcountll(x); }
int popcnt(u64 x) { return __builtin_popcountll(x); }
int popcnt_mod_2(int x) { return __builtin_parity(x); }
int popcnt_mod_2(u32 x) { return __builtin_parity(x); }
int popcnt_mod_2(ll x) { return __builtin_parityll(x); }
int popcnt_mod_2(u64 x) { return __builtin_parityll(x); }
// (0, 1, 2, 3, 4) -> (-1, 0, 1, 1, 2)
int topbit(int x) { return (x == 0 ? -1 : 31 - __builtin_clz(x)); }
int topbit(u32 x) { return (x == 0 ? -1 : 31 - __builtin_clz(x)); }
int topbit(ll x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
int topbit(u64 x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
// (0, 1, 2, 3, 4) -> (-1, 0, 1, 0, 2)
int lowbit(int x) { return (x == 0 ? -1 : __builtin_ctz(x)); }
int lowbit(u32 x) { return (x == 0 ? -1 : __builtin_ctz(x)); }
int lowbit(ll x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }
int lowbit(u64 x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }

template <typename T>
T floor(T a, T b) {
  return a / b - (a % b && (a ^ b) < 0);
}
template <typename T>
T ceil(T x, T y) {
  return floor(x + y - 1, y);
}
template <typename T>
T bmod(T x, T y) {
  return x - y * floor(x, y);
}
template <typename T>
pair<T, T> divmod(T x, T y) {
  T q = floor(x, y);
  return {q, x - q * y};
}

template <typename T, typename U>
T SUM(const vector<U> &A) {
  T sm = 0;
  for (auto &&a: A) sm += a;
  return sm;
}

#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define LB(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define UB(c, x) distance((c).begin(), upper_bound(all(c), (x)))
#define UNIQUE(x) \
  sort(all(x)), x.erase(unique(all(x)), x.end()), x.shrink_to_fit()

template <typename T>
T POP(deque<T> &que) {
  T a = que.front();
  que.pop_front();
  return a;
}
template <typename T>
T POP(pq<T> &que) {
  T a = que.top();
  que.pop();
  return a;
}
template <typename T>
T POP(pqg<T> &que) {
  T a = que.top();
  que.pop();
  return a;
}
template <typename T>
T POP(vc<T> &que) {
  T a = que.back();
  que.pop_back();
  return a;
}

template <typename F>
ll binary_search(F check, ll ok, ll ng, bool check_ok = true) {
  if (check_ok) assert(check(ok));
  while (abs(ok - ng) > 1) {
    auto x = (ng + ok) / 2;
    (check(x) ? ok : ng) = x;
  }
  return ok;
}
template <typename F>
double binary_search_real(F check, double ok, double ng, int iter = 100) {
  FOR(iter) {
    double x = (ok + ng) / 2;
    (check(x) ? ok : ng) = x;
  }
  return (ok + ng) / 2;
}

template <class T, class S>
inline bool chmax(T &a, const S &b) {
  return (a < b ? a = b, 1 : 0);
}
template <class T, class S>
inline bool chmin(T &a, const S &b) {
  return (a > b ? a = b, 1 : 0);
}

// ? は -1
vc<int> s_to_vi(const string &S, char first_char) {
  vc<int> A(S.size());
  FOR(i, S.size()) { A[i] = (S[i] != '?' ? S[i] - first_char : -1); }
  return A;
}

template <typename T, typename U>
vector<T> cumsum(vector<U> &A, int off = 1) {
  int N = A.size();
  vector<T> B(N + 1);
  FOR(i, N) { B[i + 1] = B[i] + A[i]; }
  if (off == 0) B.erase(B.begin());
  return B;
}

// stable sort
template <typename T>
vector<int> argsort(const vector<T> &A) {
  vector<int> ids(len(A));
  iota(all(ids), 0);
  sort(all(ids),
       [&](int i, int j) { return (A[i] == A[j] ? i < j : A[i] < A[j]); });
  return ids;
}

// A[I[0]], A[I[1]], ...
template <typename T>
vc<T> rearrange(const vc<T> &A, const vc<int> &I) {
  vc<T> B(len(I));
  FOR(i, len(I)) B[i] = A[I[i]];
  return B;
}
#endif
#line 1 "library/other/io.hpp"
#define FASTIO
#include <unistd.h>

// https://judge.yosupo.jp/submission/21623
namespace fastio {
static constexpr uint32_t SZ = 1 << 17;
char ibuf[SZ];
char obuf[SZ];
char out[100];
// pointer of ibuf, obuf
uint32_t pil = 0, pir = 0, por = 0;

struct Pre {
  char num[10000][4];
  constexpr Pre() : num() {
    for (int i = 0; i < 10000; i++) {
      int n = i;
      for (int j = 3; j >= 0; j--) {
        num[i][j] = n % 10 | '0';
        n /= 10;
      }
    }
  }
} constexpr pre;

inline void load() {
  memcpy(ibuf, ibuf + pil, pir - pil);
  pir = pir - pil + fread(ibuf + pir - pil, 1, SZ - pir + pil, stdin);
  pil = 0;
  if (pir < SZ) ibuf[pir++] = '\n';
}

inline void flush() {
  fwrite(obuf, 1, por, stdout);
  por = 0;
}

void rd(char &c) {
  do {
    if (pil + 1 > pir) load();
    c = ibuf[pil++];
  } while (isspace(c));
}

void rd(string &x) {
  x.clear();
  char c;
  do {
    if (pil + 1 > pir) load();
    c = ibuf[pil++];
  } while (isspace(c));
  do {
    x += c;
    if (pil == pir) load();
    c = ibuf[pil++];
  } while (!isspace(c));
}

template <typename T>
void rd_real(T &x) {
  string s;
  rd(s);
  x = stod(s);
}

template <typename T>
void rd_integer(T &x) {
  if (pil + 100 > pir) load();
  char c;
  do
    c = ibuf[pil++];
  while (c < '-');
  bool minus = 0;
  if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
    if (c == '-') { minus = 1, c = ibuf[pil++]; }
  }
  x = 0;
  while ('0' <= c) { x = x * 10 + (c & 15), c = ibuf[pil++]; }
  if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
    if (minus) x = -x;
  }
}

void rd(int &x) { rd_integer(x); }
void rd(ll &x) { rd_integer(x); }
void rd(i128 &x) { rd_integer(x); }
void rd(u32 &x) { rd_integer(x); }
void rd(u64 &x) { rd_integer(x); }
void rd(u128 &x) { rd_integer(x); }
void rd(double &x) { rd_real(x); }
void rd(long double &x) { rd_real(x); }
void rd(f128 &x) { rd_real(x); }

template <class T, class U>
void rd(pair<T, U> &p) {
  return rd(p.first), rd(p.second);
}
template <size_t N = 0, typename T>
void rd_tuple(T &t) {
  if constexpr (N < std::tuple_size<T>::value) {
    auto &x = std::get<N>(t);
    rd(x);
    rd_tuple<N + 1>(t);
  }
}
template <class... T>
void rd(tuple<T...> &tpl) {
  rd_tuple(tpl);
}

template <size_t N = 0, typename T>
void rd(array<T, N> &x) {
  for (auto &d: x) rd(d);
}
template <class T>
void rd(vc<T> &x) {
  for (auto &d: x) rd(d);
}

void read() {}
template <class H, class... T>
void read(H &h, T &... t) {
  rd(h), read(t...);
}

void wt(const char c) {
  if (por == SZ) flush();
  obuf[por++] = c;
}
void wt(const string s) {
  for (char c: s) wt(c);
}
void wt(const char *s) {
  size_t len = strlen(s);
  for (size_t i = 0; i < len; i++) wt(s[i]);
}

template <typename T>
void wt_integer(T x) {
  if (por > SZ - 100) flush();
  if (x < 0) { obuf[por++] = '-', x = -x; }
  int outi;
  for (outi = 96; x >= 10000; outi -= 4) {
    memcpy(out + outi, pre.num[x % 10000], 4);
    x /= 10000;
  }
  if (x >= 1000) {
    memcpy(obuf + por, pre.num[x], 4);
    por += 4;
  } else if (x >= 100) {
    memcpy(obuf + por, pre.num[x] + 1, 3);
    por += 3;
  } else if (x >= 10) {
    int q = (x * 103) >> 10;
    obuf[por] = q | '0';
    obuf[por + 1] = (x - q * 10) | '0';
    por += 2;
  } else
    obuf[por++] = x | '0';
  memcpy(obuf + por, out + outi + 4, 96 - outi);
  por += 96 - outi;
}

template <typename T>
void wt_real(T x) {
  ostringstream oss;
  oss << fixed << setprecision(15) << double(x);
  string s = oss.str();
  wt(s);
}

void wt(int x) { wt_integer(x); }
void wt(ll x) { wt_integer(x); }
void wt(i128 x) { wt_integer(x); }
void wt(u32 x) { wt_integer(x); }
void wt(u64 x) { wt_integer(x); }
void wt(u128 x) { wt_integer(x); }
void wt(double x) { wt_real(x); }
void wt(long double x) { wt_real(x); }
void wt(f128 x) { wt_real(x); }

template <class T, class U>
void wt(const pair<T, U> val) {
  wt(val.first);
  wt(' ');
  wt(val.second);
}
template <size_t N = 0, typename T>
void wt_tuple(const T t) {
  if constexpr (N < std::tuple_size<T>::value) {
    if constexpr (N > 0) { wt(' '); }
    const auto x = std::get<N>(t);
    wt(x);
    wt_tuple<N + 1>(t);
  }
}
template <class... T>
void wt(tuple<T...> tpl) {
  wt_tuple(tpl);
}
template <class T, size_t S>
void wt(const array<T, S> val) {
  auto n = val.size();
  for (size_t i = 0; i < n; i++) {
    if (i) wt(' ');
    wt(val[i]);
  }
}
template <class T>
void wt(const vector<T> val) {
  auto n = val.size();
  for (size_t i = 0; i < n; i++) {
    if (i) wt(' ');
    wt(val[i]);
  }
}

void print() { wt('\n'); }
template <class Head, class... Tail>
void print(Head &&head, Tail &&... tail) {
  wt(head);
  if (sizeof...(Tail)) wt(' ');
  print(forward<Tail>(tail)...);
}

// gcc expansion. called automaticall after main.
void __attribute__((destructor)) _d() { flush(); }
} // namespace fastio
using fastio::read;
using fastio::print;
using fastio::flush;

#if defined(LOCAL)
#define SHOW(...) \
  SHOW_IMPL(__VA_ARGS__, SHOW4, SHOW3, SHOW2, SHOW1)(__VA_ARGS__)
#define SHOW_IMPL(_1, _2, _3, _4, NAME, ...) NAME
#define SHOW1(x) print(#x, "=", (x)), flush()
#define SHOW2(x, y) print(#x, "=", (x), #y, "=", (y)), flush()
#define SHOW3(x, y, z) print(#x, "=", (x), #y, "=", (y), #z, "=", (z)), flush()
#define SHOW4(x, y, z, w) \
  print(#x, "=", (x), #y, "=", (y), #z, "=", (z), #w, "=", (w)), flush()
#else
#define SHOW(...)
#endif

#define INT(...)   \
  int __VA_ARGS__; \
  read(__VA_ARGS__)
#define LL(...)   \
  ll __VA_ARGS__; \
  read(__VA_ARGS__)
#define U32(...)   \
  u32 __VA_ARGS__; \
  read(__VA_ARGS__)
#define U64(...)   \
  u64 __VA_ARGS__; \
  read(__VA_ARGS__)
#define STR(...)      \
  string __VA_ARGS__; \
  read(__VA_ARGS__)
#define CHAR(...)   \
  char __VA_ARGS__; \
  read(__VA_ARGS__)
#define DBL(...)      \
  double __VA_ARGS__; \
  read(__VA_ARGS__)

#define VEC(type, name, size) \
  vector<type> name(size);    \
  read(name)
#define VV(type, name, h, w)                     \
  vector<vector<type>> name(h, vector<type>(w)); \
  read(name)

void YES(bool t = 1) { print(t ? "YES" : "NO"); }
void NO(bool t = 1) { YES(!t); }
void Yes(bool t = 1) { print(t ? "Yes" : "No"); }
void No(bool t = 1) { Yes(!t); }
void yes(bool t = 1) { print(t ? "yes" : "no"); }
void no(bool t = 1) { yes(!t); }
#line 3 "main.cpp"

#line 2 "library/alg/monoid/minmincnt.hpp"

// 最小値、最小値の個数
template <typename E>
struct Monoid_MinMincnt {
  using value_type = pair<E, E>;
  using X = value_type;
  static X op(X x, X y) {
    auto [xmin, xmincnt] = x;
    auto [ymin, ymincnt] = y;
    if (xmin > ymin) return y;
    if (xmin < ymin) return x;
    return {xmin, xmincnt + ymincnt};
  }
  static constexpr X unit() { return {infty<E>, 0}; }
  static constexpr bool commute = true;
};
#line 2 "library/alg/monoid/add.hpp"

template <typename E>
struct Monoid_Add {
  using X = E;
  using value_type = X;
  static constexpr X op(const X &x, const X &y) noexcept { return x + y; }
  static constexpr X inverse(const X &x) noexcept { return -x; }
  static constexpr X power(const X &x, ll n) noexcept { return X(n) * x; }
  static constexpr X unit() { return X(0); }
  static constexpr bool commute = true;
};
#line 3 "library/alg/acted_monoid/minmincnt_add.hpp"

template <typename E>
struct ActedMonoid_MinMincnt_Add {
  using Monoid_X = Monoid_MinMincnt<E>;
  using Monoid_A = Monoid_Add<E>;
  using X = typename Monoid_X::value_type;
  using A = typename Monoid_A::value_type;
  static constexpr X act(const X &x, const A &a, const ll &size) {
    auto [xmin, xmincnt] = x;
    if (xmin == infty<E>) return x;
    return {xmin + a, xmincnt};
  }
};
#line 2 "library/ds/segtree/lazy_segtree.hpp"

template <typename ActedMonoid>
struct Lazy_SegTree {
  using AM = ActedMonoid;
  using MX = typename AM::Monoid_X;
  using MA = typename AM::Monoid_A;
  using X = typename MX::value_type;
  using A = typename MA::value_type;
  int n, log, size;
  vc<X> dat;
  vc<A> laz;

  Lazy_SegTree() {}
  Lazy_SegTree(int n) { build(n); }
  template <typename F>
  Lazy_SegTree(int n, F f) {
    build(n, f);
  }
  Lazy_SegTree(const vc<X>& v) { build(v); }

  void build(int m) {
    build(m, [](int i) -> X { return MX::unit(); });
  }
  void build(const vc<X>& v) {
    build(len(v), [&](int i) -> X { return v[i]; });
  }
  template <typename F>
  void build(int m, F f) {
    n = m, log = 1;
    while ((1 << log) < n) ++log;
    size = 1 << log;
    dat.assign(size << 1, MX::unit());
    laz.assign(size, MA::unit());
    FOR(i, n) dat[size + i] = f(i);
    FOR_R(i, 1, size) update(i);
  }

  void update(int k) { dat[k] = MX::op(dat[2 * k], dat[2 * k + 1]); }
  void set(int p, X x) {
    assert(0 <= p && p < n);
    p += size;
    for (int i = log; i >= 1; i--) push(p >> i);
    dat[p] = x;
    for (int i = 1; i <= log; i++) update(p >> i);
  }
  void multiply(int p, const X& x) {
    assert(0 <= p && p < n);
    p += size;
    for (int i = log; i >= 1; i--) push(p >> i);
    dat[p] = MX::op(dat[p], x);
    for (int i = 1; i <= log; i++) update(p >> i);
  }

  X get(int p) {
    assert(0 <= p && p < n);
    p += size;
    for (int i = log; i >= 1; i--) push(p >> i);
    return dat[p];
  }

  vc<X> get_all() {
    FOR(k, 1, size) { push(k); }
    return {dat.begin() + size, dat.begin() + size + n};
  }

  X prod(int l, int r) {
    assert(0 <= l && l <= r && r <= n);
    if (l == r) return MX::unit();
    l += size, r += size;
    for (int i = log; i >= 1; i--) {
      if (((l >> i) << i) != l) push(l >> i);
      if (((r >> i) << i) != r) push((r - 1) >> i);
    }
    X xl = MX::unit(), xr = MX::unit();
    while (l < r) {
      if (l & 1) xl = MX::op(xl, dat[l++]);
      if (r & 1) xr = MX::op(dat[--r], xr);
      l >>= 1, r >>= 1;
    }
    return MX::op(xl, xr);
  }

  X prod_all() { return dat[1]; }

  void apply(int l, int r, A a) {
    assert(0 <= l && l <= r && r <= n);
    if (l == r) return;
    l += size, r += size;
    for (int i = log; i >= 1; i--) {
      if (((l >> i) << i) != l) push(l >> i);
      if (((r >> i) << i) != r) push((r - 1) >> i);
    }
    int l2 = l, r2 = r;
    while (l < r) {
      if (l & 1) apply_at(l++, a);
      if (r & 1) apply_at(--r, a);
      l >>= 1, r >>= 1;
    }
    l = l2, r = r2;
    for (int i = 1; i <= log; i++) {
      if (((l >> i) << i) != l) update(l >> i);
      if (((r >> i) << i) != r) update((r - 1) >> i);
    }
  }

  template <typename F>
  int max_right(const F check, int l) {
    assert(0 <= l && l <= n);
    assert(check(MX::unit()));
    if (l == n) return n;
    l += size;
    for (int i = log; i >= 1; i--) push(l >> i);
    X sm = MX::unit();
    do {
      while (l % 2 == 0) l >>= 1;
      if (!check(MX::op(sm, dat[l]))) {
        while (l < size) {
          push(l);
          l = (2 * l);
          if (check(MX::op(sm, dat[l]))) { sm = MX::op(sm, dat[l++]); }
        }
        return l - size;
      }
      sm = MX::op(sm, dat[l++]);
    } while ((l & -l) != l);
    return n;
  }

  template <typename F>
  int min_left(const F check, int r) {
    assert(0 <= r && r <= n);
    assert(check(MX::unit()));
    if (r == 0) return 0;
    r += size;
    for (int i = log; i >= 1; i--) push((r - 1) >> i);
    X sm = MX::unit();
    do {
      r--;
      while (r > 1 && (r % 2)) r >>= 1;
      if (!check(MX::op(dat[r], sm))) {
        while (r < size) {
          push(r);
          r = (2 * r + 1);
          if (check(MX::op(dat[r], sm))) { sm = MX::op(dat[r--], sm); }
        }
        return r + 1 - size;
      }
      sm = MX::op(dat[r], sm);
    } while ((r & -r) != r);
    return 0;
  }

private:
  void apply_at(int k, A a) {
    ll sz = 1 << (log - topbit(k));
    dat[k] = AM::act(dat[k], a, sz);
    if (k < size) laz[k] = MA::op(laz[k], a);
  }
  void push(int k) {
    if (laz[k] == MA::unit()) return;
    apply_at(2 * k, laz[k]), apply_at(2 * k + 1, laz[k]);
    laz[k] = MA::unit();
  }
};
#line 6 "main.cpp"

void solve() {
  LL(N, LIM);
  VEC(pi, LR, N);
  for (auto& [a, b]: LR) { tie(a, b) = mp(a - b, a + b); }

  vi X = {0, LIM};
  for (auto& [a, b]: LR) X.eb(a), X.eb(b);
  UNIQUE(X);
  ll LLIM = LB(X, 0), RLIM = LB(X, LIM);

  ll n = len(X) - 1;

  Lazy_SegTree<ActedMonoid_MinMincnt_Add<ll>> seg(n,
                                                  [&](int i) -> pair<ll, ll> {
                                                    return {0, X[i + 1] - X[i]};
                                                  });
  set<pi> st;

  for (auto& [a, b]: LR) {
    pi p = {a, b};
    int L = LB(X, a), R = LB(X, b);
    if (st.count(p)) {
      seg.apply(L, R, -1);
      st.erase(p);
    } else {
      seg.apply(L, R, 1);
      st.insert(p);
    }
    using Re = double;
    auto X = seg.prod(LLIM, RLIM);
    Re ANS = LIM;
    if (X.fi == 0) ANS -= X.se;
    ANS *= sqrtl(2);
    print(ANS);
  }
}

signed main() {
  solve();
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 4140kb

input:

3 10
3 2
7 3
9 6

output:

5.656854249492381
12.727922061357855
12.727922061357855

result:

ok 3 numbers

Test #2:

score: 0
Accepted
time: 0ms
memory: 3896kb

input:

5 100
31 41
59 26
31 41
59 26
31 41

output:

101.823376490862842
120.208152801713084
73.539105243400940
0.000000000000000
101.823376490862842

result:

ok 5 numbers

Test #3:

score: 0
Accepted
time: 1ms
memory: 3876kb

input:

100 10
6 4
2 3
7 6
5 5
3 6
7 5
5 8
10 4
9 8
0 9
9 10
9 3
2 3
10 10
8 4
10 9
0 1
1 7
0 2
3 4
10 3
3 10
7 4
7 5
1 4
0 7
1 9
5 6
8 8
7 4
8 1
3 9
2 1
5 5
2 1
10 9
8 4
0 9
10 7
4 1
9 10
8 6
5 4
1 4
0 9
9 3
4 8
5 10
7 2
8 10
7 10
3 4
2 2
8 5
0 9
5 3
1 4
6 4
0 3
8 1
1 6
3 8
8 4
6 5
10 2
2 2
8 4
6 1
2 4
6 4...

output:

11.313708498984761
14.142135623730951
14.142135623730951
14.142135623730951
14.142135623730951
14.142135623730951
14.142135623730951
14.142135623730951
14.142135623730951
14.142135623730951
14.142135623730951
14.142135623730951
14.142135623730951
14.142135623730951
14.142135623730951
14.142135623730...

result:

ok 100 numbers

Test #4:

score: 0
Accepted
time: 2ms
memory: 4048kb

input:

1000 100
95 8
54 8
64 96
47 34
77 47
99 91
45 70
8 6
64 84
48 42
53 14
73 66
38 27
6 52
19 75
33 39
6 24
37 80
27 45
96 48
55 95
67 1
23 78
40 4
76 7
77 22
4 47
41 31
60 54
96 37
79 52
63 40
7 92
17 7
74 12
93 16
87 5
67 43
60 29
71 58
52 41
53 84
38 2
46 87
13 54
54 14
16 93
57 7
91 98
31 23
70 3
9...

output:

18.384776310850235
41.012193308819754
141.421356237309510
141.421356237309510
141.421356237309510
141.421356237309510
141.421356237309510
141.421356237309510
141.421356237309510
141.421356237309510
141.421356237309510
141.421356237309510
141.421356237309510
141.421356237309510
141.421356237309510
14...

result:

ok 1000 numbers

Test #5:

score: 0
Accepted
time: 2ms
memory: 4120kb

input:

1000 1000
942 407
513 739
329 437
605 318
847 416
128 543
588 237
903 365
703 556
313 928
621 344
974 444
780 265
993 889
103 427
94 977
897 586
566 326
785 938
224 952
150 441
716 802
729 584
954 347
640 4
91 633
738 970
823 253
158 890
115 734
327 391
554 258
373 67
396 995
788 73
609 703
627 801
...

output:

657.609306503489165
1414.213562373095101
1414.213562373095101
1414.213562373095101
1414.213562373095101
1414.213562373095101
1414.213562373095101
1414.213562373095101
1414.213562373095101
1414.213562373095101
1414.213562373095101
1414.213562373095101
1414.213562373095101
1414.213562373095101
1414.21...

result:

ok 1000 numbers

Test #6:

score: 0
Accepted
time: 185ms
memory: 12568kb

input:

200000 10
6 4
4 9
7 9
6 2
0 7
6 7
4 8
10 5
7 8
5 4
3 6
5 9
0 9
7 3
8 2
8 6
5 9
5 10
4 9
0 3
10 5
3 9
7 2
2 3
9 7
5 6
1 7
0 4
9 6
4 7
3 8
6 4
2 7
0 6
8 3
6 2
8 10
1 6
0 4
6 1
3 3
5 8
9 7
8 7
1 10
6 2
1 8
8 6
6 1
6 3
0 6
6 1
5 6
1 1
6 4
7 9
3 5
10 6
2 8
6 7
7 3
6 8
8 5
9 7
4 5
6 4
5 10
8 6
8 5
4 6
4 6...

output:

11.313708498984761
14.142135623730951
14.142135623730951
14.142135623730951
14.142135623730951
14.142135623730951
14.142135623730951
14.142135623730951
14.142135623730951
14.142135623730951
14.142135623730951
14.142135623730951
14.142135623730951
14.142135623730951
14.142135623730951
14.142135623730...

result:

ok 200000 numbers

Test #7:

score: 0
Accepted
time: 257ms
memory: 12408kb

input:

200000 100
96 9
26 82
73 33
12 92
13 77
87 2
23 79
41 91
75 28
6 45
42 81
27 51
7 64
80 90
27 65
77 72
54 60
79 8
10 61
46 15
65 16
75 95
65 4
89 38
42 74
96 63
48 87
39 78
2 59
36 48
36 66
12 75
44 45
80 86
79 99
26 30
29 54
39 44
7 27
99 23
41 76
23 71
76 51
90 76
59 22
45 70
73 98
24 94
70 54
76 ...

output:

18.384776310850235
141.421356237309510
141.421356237309510
141.421356237309510
141.421356237309510
141.421356237309510
141.421356237309510
141.421356237309510
141.421356237309510
141.421356237309510
141.421356237309510
141.421356237309510
141.421356237309510
141.421356237309510
141.421356237309510
1...

result:

ok 200000 numbers

Test #8:

score: 0
Accepted
time: 442ms
memory: 20868kb

input:

200000 10000
8596 2507
1107 4452
8591 3460
3584 2911
8817 9663
1604 2760
6281 8431
5271 4811
2193 1874
5329 3970
2679 8672
8426 8447
117 4849
3471 6286
177 4806
9726 7217
6743 3882
573 4295
5291 7358
1356 6269
7882 8426
8750 985
5365 8276
7420 6372
8234 6329
7723 9014
3369 1097
7140 8329
3475 447
37...

output:

5530.989242441174611
13392.602435673210493
14142.135623730950101
14142.135623730950101
14142.135623730950101
14142.135623730950101
14142.135623730950101
14142.135623730950101
14142.135623730950101
14142.135623730950101
14142.135623730950101
14142.135623730950101
14142.135623730950101
14142.135623730...

result:

ok 200000 numbers

Test #9:

score: 0
Accepted
time: 558ms
memory: 43080kb

input:

200000 1000000000
979065421 937279323
384811311 879649222
673927841 883688174
47686221 518846247
805783947 475892423
94359891 104324315
116498230 496486640
155617000 261326127
423462080 949904263
758478482 824824842
594993542 173897699
495194886 158960628
409812195 339201236
958417812 891558399
7055...

output:

1355119095.862843751907349
1414213562.373095035552979
1414213562.373095035552979
1414213562.373095035552979
1414213562.373095035552979
1414213562.373095035552979
1414213562.373095035552979
1414213562.373095035552979
1414213562.373095035552979
1414213562.373095035552979
1414213562.373095035552979
141...

result:

ok 200000 numbers

Test #10:

score: 0
Accepted
time: 0ms
memory: 3848kb

input:

3 100
82 61
46 1
82 61

output:

111.722871427474516
111.722871427474516
2.828427124746190

result:

ok 3 numbers

Test #11:

score: 0
Accepted
time: 293ms
memory: 31196kb

input:

200000 200005
199999 1
199998 2
199997 3
199996 4
199995 5
199994 6
199993 7
199992 8
199991 9
199990 10
199989 11
199988 12
199987 13
199986 14
199985 15
199984 16
199983 17
199982 18
199981 19
199980 20
199979 21
199978 22
199977 23
199976 24
199975 25
199974 26
199973 27
199972 28
199971 29
19997...

output:

2.828427124746190
5.656854249492381
8.485281374238570
11.313708498984761
14.142135623730951
16.970562748477139
19.798989873223331
22.627416997969522
25.455844122715710
28.284271247461902
31.112698372208090
33.941125496954278
36.769552621700470
39.597979746446661
42.426406871192853
45.254833995939045...

result:

ok 200000 numbers

Test #12:

score: 0
Accepted
time: 275ms
memory: 31192kb

input:

200000 200005
0 200000
1 199999
2 199998
3 199997
4 199996
5 199995
6 199994
7 199993
8 199992
9 199991
10 199990
11 199989
12 199988
13 199987
14 199986
15 199985
16 199984
17 199983
18 199982
19 199981
20 199980
21 199979
22 199978
23 199977
24 199976
25 199975
26 199974
27 199973
28 199972
29 199...

output:

282842.712474619038403
282842.712474619038403
282842.712474619038403
282842.712474619038403
282842.712474619038403
282842.712474619038403
282842.712474619038403
282842.712474619038403
282842.712474619038403
282842.712474619038403
282842.712474619038403
282842.712474619038403
282842.712474619038403
2...

result:

ok 200000 numbers

Test #13:

score: 0
Accepted
time: 418ms
memory: 31152kb

input:

200000 200005
188054 11946
25503 174497
5164 194836
199742 258
65650 134350
93448 106552
165510 34490
33001 166999
54081 145919
123066 76934
50244 149756
46561 153439
66523 133477
8593 191407
173633 26367
105494 94506
198495 1505
75564 124436
83182 116818
123337 76663
186899 13101
110487 89513
10858...

output:

33788.390432217987836
282842.712474619038403
282842.712474619038403
282842.712474619038403
282842.712474619038403
282842.712474619038403
282842.712474619038403
282842.712474619038403
282842.712474619038403
282842.712474619038403
282842.712474619038403
282842.712474619038403
282842.712474619038403
28...

result:

ok 200000 numbers

Test #14:

score: 0
Accepted
time: 286ms
memory: 31200kb

input:

200000 200005
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10 10
11 11
12 12
13 13
14 14
15 15
16 16
17 17
18 18
19 19
20 20
21 21
22 22
23 23
24 24
25 25
26 26
27 27
28 28
29 29
30 30
31 31
32 32
33 33
34 34
35 35
36 36
37 37
38 38
39 39
40 40
41 41
42 42
43 43
44 44
45 45
46 46
47 47
48 48
49 49
50 50
51 5...

output:

2.828427124746190
5.656854249492381
8.485281374238570
11.313708498984761
14.142135623730951
16.970562748477139
19.798989873223331
22.627416997969522
25.455844122715710
28.284271247461902
31.112698372208090
33.941125496954278
36.769552621700470
39.597979746446661
42.426406871192853
45.254833995939045...

result:

ok 200000 numbers

Test #15:

score: 0
Accepted
time: 267ms
memory: 31180kb

input:

200000 200005
200000 200000
199999 199999
199998 199998
199997 199997
199996 199996
199995 199995
199994 199994
199993 199993
199992 199992
199991 199991
199990 199990
199989 199989
199988 199988
199987 199987
199986 199986
199985 199985
199984 199984
199983 199983
199982 199982
199981 199981
199980...

output:

282849.783542430901434
282849.783542430901434
282849.783542430901434
282849.783542430901434
282849.783542430901434
282849.783542430901434
282849.783542430901434
282849.783542430901434
282849.783542430901434
282849.783542430901434
282849.783542430901434
282849.783542430901434
282849.783542430901434
2...

result:

ok 200000 numbers

Test #16:

score: 0
Accepted
time: 406ms
memory: 31136kb

input:

200000 200005
99686 99686
193692 193692
142065 142065
56279 56279
120521 120521
147618 147618
148660 148660
1328 1328
69007 69007
5297 5297
136306 136306
136195 136195
101372 101372
66966 66966
110843 110843
170697 170697
23097 23097
146157 146157
118098 118098
11530 11530
42300 42300
74535 74535
17...

output:

281954.586357448715717
282849.783542430901434
282849.783542430901434
282849.783542430901434
282849.783542430901434
282849.783542430901434
282849.783542430901434
282849.783542430901434
282849.783542430901434
282849.783542430901434
282849.783542430901434
282849.783542430901434
282849.783542430901434
2...

result:

ok 200000 numbers

Test #17:

score: 0
Accepted
time: 136ms
memory: 11904kb

input:

200000 1000000000
227478108 704821317
227478108 704821317
227478108 704821317
227478108 704821317
227478108 704821317
227478108 704821317
227478108 704821317
227478108 704821317
227478108 704821317
227478108 704821317
227478108 704821317
227478108 704821317
227478108 704821317
227478108 704821317
22...

output:

1318470491.027638196945190
0.000000000000000
1318470491.027638196945190
0.000000000000000
1318470491.027638196945190
0.000000000000000
1318470491.027638196945190
0.000000000000000
1318470491.027638196945190
0.000000000000000
1318470491.027638196945190
0.000000000000000
1318470491.027638196945190
0.0...

result:

ok 200000 numbers

Test #18:

score: 0
Accepted
time: 192ms
memory: 11356kb

input:

200000 1000000000
517510913 200230004
39507125 601409920
30526823 972694998
176712 534697072
789676092 648567171
967127462 822743807
176712 534697072
176712 534697072
117560602 867751869
967127462 822743807
227002346 310628813
789676092 648567171
800983841 618498638
39507125 601409920
517510913 2002...

output:

566335974.501638174057007
1015038939.091501951217651
1414213562.373095035552979
1414213562.373095035552979
1414213562.373095035552979
1414213562.373095035552979
1414213562.373095035552979
1414213562.373095035552979
1414213562.373095035552979
1414213562.373095035552979
1414213562.373095035552979
1414...

result:

ok 200000 numbers

Test #19:

score: 0
Accepted
time: 232ms
memory: 11196kb

input:

200000 1000000000
351451808 649636951
49985291 500589827
661773922 164694264
186065541 226295124
497991267 744030929
574182692 439989249
853617452 979655888
308109763 216029731
66584658 40643821
855305206 820425533
740812379 441059394
151159173 495945962
214589103 777995590
957581330 407536966
88513...

output:

1414213562.373095035552979
1414213562.373095035552979
1414213562.373095035552979
1414213562.373095035552979
1414213562.373095035552979
1414213562.373095035552979
1414213562.373095035552979
1414213562.373095035552979
1414213562.373095035552979
1414213562.373095035552979
1414213562.373095035552979
141...

result:

ok 200000 numbers

Test #20:

score: 0
Accepted
time: 146ms
memory: 10748kb

input:

200000 1000000000
821475126 617812186
464369722 134670005
821475126 617812186
464369722 134670005
464369722 134670005
821475126 617812186
464369722 134670005
464369722 134670005
464369722 134670005
464369722 134670005
821475126 617812186
464369722 134670005
464369722 134670005
464369722 134670005
46...

output:

1126190670.472317218780518
1126190670.472317218780518
380904295.031705021858215
0.000000000000000
380904295.031705021858215
1126190670.472317218780518
1126190670.472317218780518
1126190670.472317218780518
1126190670.472317218780518
1126190670.472317218780518
380904295.031705021858215
0.0000000000000...

result:

ok 200000 numbers

Test #21:

score: 0
Accepted
time: 185ms
memory: 11440kb

input:

200000 11
1 1
2 1
3 1
4 1
5 1
6 1
7 1
8 1
9 1
10 1
8 1
10 10
3 1
1 2
9 10
1 4
5 1
1 5
1 6
7 7
2 1
4 1
5 3
7 9
6 4
3 7
6 1
1 8
2 5
2 9
10 9
6 10
9 8
1 2
7 3
6 6
6 6
7 5
1 9
7 9
3 5
9 5
3 3
6 8
10 9
7 5
5 1
2 1
3 2
5 5
8 1
4 9
9 8
1 3
4 8
8 9
2 10
1 4
7 3
4 1
1 2
1 2
5 1
5 4
1 3
2 1
6 2
6 8
5 9
10 7
5...

output:

2.828427124746190
4.242640687119285
5.656854249492381
7.071067811865476
8.485281374238570
9.899494936611665
11.313708498984761
12.727922061357855
14.142135623730951
15.556349186104045
15.556349186104045
15.556349186104045
15.556349186104045
15.556349186104045
15.556349186104045
15.556349186104045
15...

result:

ok 200000 numbers

Test #22:

score: 0
Accepted
time: 128ms
memory: 12236kb

input:

200000 4
1 1
2 1
3 1
1 1
3 2
3 3
2 1
3 3
2 1
2 2
2 2
3 1
2 2
3 3
1 2
2 3
1 2
2 1
2 2
1 2
3 1
2 2
2 1
2 1
3 3
2 2
1 2
1 3
2 1
3 3
2 3
3 1
2 1
1 2
1 3
3 1
2 3
2 1
1 2
3 3
1 3
3 3
2 3
2 3
2 1
3 1
3 3
1 2
2 1
2 1
1 1
1 3
1 1
1 1
2 3
2 2
1 2
1 1
1 3
1 1
1 2
1 1
2 3
1 1
2 2
2 2
2 1
2 1
3 2
1 1
3 1
1 2
1 1...

output:

2.828427124746190
4.242640687119285
5.656854249492381
4.242640687119285
4.242640687119285
5.656854249492381
5.656854249492381
4.242640687119285
4.242640687119285
5.656854249492381
4.242640687119285
4.242640687119285
5.656854249492381
5.656854249492381
5.656854249492381
5.656854249492381
5.6568542494...

result:

ok 200000 numbers

Test #23:

score: 0
Accepted
time: 239ms
memory: 12032kb

input:

200000 51
1 1
2 1
3 1
4 1
5 1
6 1
7 1
8 1
9 1
10 1
11 1
12 1
13 1
14 1
15 1
16 1
17 1
18 1
19 1
20 1
21 1
22 1
23 1
24 1
25 1
26 1
27 1
28 1
29 1
30 1
31 1
32 1
33 1
34 1
35 1
36 1
37 1
38 1
39 1
40 1
41 1
42 1
43 1
44 1
45 1
46 1
47 1
48 1
49 1
50 1
2 47
25 41
44 8
35 38
37 24
42 32
40 48
19 4
26 4...

output:

2.828427124746190
4.242640687119285
5.656854249492381
7.071067811865476
8.485281374238570
9.899494936611665
11.313708498984761
12.727922061357855
14.142135623730951
15.556349186104045
16.970562748477139
18.384776310850235
19.798989873223331
21.213203435596427
22.627416997969522
24.041630560342615
25...

result:

ok 200000 numbers