QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#795079#9809. The Grand Contestucup-team087#AC ✓666ms106296kbC++2321.6kb2024-11-30 17:48:472024-11-30 17:48:50

Judging History

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

  • [2024-11-30 17:48:50]
  • 评测
  • 测评结果:AC
  • 用时:666ms
  • 内存:106296kb
  • [2024-11-30 17:48:47]
  • 提交

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 u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i128 = __int128;
using u128 = unsigned __int128;
using f128 = __float128;

template <class T>
constexpr T infty = 0;
template <>
constexpr int infty<int> = 1'010'000'000;
template <>
constexpr ll infty<ll> = 2'020'000'000'000'000'000;
template <>
constexpr u32 infty<u32> = infty<int>;
template <>
constexpr u64 infty<u64> = infty<ll>;
template <>
constexpr i128 infty<i128> = i128(infty<ll>) * 2'000'000'000'000'000'000;
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_sgn(int x) { return (__builtin_parity(x) & 1 ? -1 : 1); }
int popcnt_sgn(u32 x) { return (__builtin_parity(x) & 1 ? -1 : 1); }
int popcnt_sgn(ll x) { return (__builtin_parity(x) & 1 ? -1 : 1); }
int popcnt_sgn(u64 x) { return (__builtin_parity(x) & 1 ? -1 : 1); }
// (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 kth_bit(int k) {
  return T(1) << k;
}
template <typename T>
bool has_kth_bit(T x, int k) {
  return x >> k & 1;
}

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;
}

template <typename T, typename... Vectors>
void concat(vc<T> &first, const Vectors &... others) {
  vc<T> &res = first;
  (res.insert(res.end(), others.begin(), others.end()), ...);
}
#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__, SHOW6, SHOW5, SHOW4, SHOW3, SHOW2, SHOW1)(__VA_ARGS__)
#define SHOW_IMPL(_1, _2, _3, _4, _5, _6, 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()
#define SHOW5(x, y, z, w, v) print(#x, "=", (x), #y, "=", (y), #z, "=", (z), #w, "=", (w), #v, "=", (v)), flush()
#define SHOW6(x, y, z, w, v, u) print(#x, "=", (x), #y, "=", (y), #z, "=", (z), #w, "=", (w), #v, "=", (v), #u, "=", (u)), 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); }
void YA(bool t = 1) { print(t ? "YA" : "TIDAK"); }
void TIDAK(bool t = 1) { YES(!t); }
#line 2 "library/ds/segtree/segtree.hpp"

template <class Monoid>
struct SegTree {
  using MX = Monoid;
  using X = typename MX::value_type;
  using value_type = X;
  vc<X> dat;
  int n, log, size;

  SegTree() {}
  SegTree(int n) { build(n); }
  template <typename F>
  SegTree(int n, F f) {
    build(n, f);
  }
  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());
    FOR(i, n) dat[size + i] = f(i);
    FOR_R(i, 1, size) update(i);
  }

  X get(int i) { return dat[size + i]; }
  vc<X> get_all() { return {dat.begin() + size, dat.begin() + size + n}; }

  void update(int i) { dat[i] = Monoid::op(dat[2 * i], dat[2 * i + 1]); }
  void set(int i, const X& x) {
    assert(i < n);
    dat[i += size] = x;
    while (i >>= 1) update(i);
  }

  void multiply(int i, const X& x) {
    assert(i < n);
    i += size;
    dat[i] = Monoid::op(dat[i], x);
    while (i >>= 1) update(i);
  }

  X prod(int L, int R) {
    assert(0 <= L && L <= R && R <= n);
    X vl = Monoid::unit(), vr = Monoid::unit();
    L += size, R += size;
    while (L < R) {
      if (L & 1) vl = Monoid::op(vl, dat[L++]);
      if (R & 1) vr = Monoid::op(dat[--R], vr);
      L >>= 1, R >>= 1;
    }
    return Monoid::op(vl, vr);
  }

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

  template <class F>
  int max_right(F check, int L) {
    assert(0 <= L && L <= n && check(Monoid::unit()));
    if (L == n) return n;
    L += size;
    X sm = Monoid::unit();
    do {
      while (L % 2 == 0) L >>= 1;
      if (!check(Monoid::op(sm, dat[L]))) {
        while (L < size) {
          L = 2 * L;
          if (check(Monoid::op(sm, dat[L]))) { sm = Monoid::op(sm, dat[L++]); }
        }
        return L - size;
      }
      sm = Monoid::op(sm, dat[L++]);
    } while ((L & -L) != L);
    return n;
  }

  template <class F>
  int min_left(F check, int R) {
    assert(0 <= R && R <= n && check(Monoid::unit()));
    if (R == 0) return 0;
    R += size;
    X sm = Monoid::unit();
    do {
      --R;
      while (R > 1 && (R % 2)) R >>= 1;
      if (!check(Monoid::op(dat[R], sm))) {
        while (R < size) {
          R = 2 * R + 1;
          if (check(Monoid::op(dat[R], sm))) { sm = Monoid::op(dat[R--], sm); }
        }
        return R + 1 - size;
      }
      sm = Monoid::op(dat[R], sm);
    } while ((R & -R) != R);
    return 0;
  }

  // prod_{l<=i<r} A[i xor x]
  X xor_prod(int l, int r, int xor_val) {
    static_assert(Monoid::commute);
    X x = Monoid::unit();
    for (int k = 0; k < log + 1; ++k) {
      if (l >= r) break;
      if (l & 1) { x = Monoid::op(x, dat[(size >> k) + ((l++) ^ xor_val)]); }
      if (r & 1) { x = Monoid::op(x, dat[(size >> k) + ((--r) ^ xor_val)]); }
      l /= 2, r /= 2, xor_val /= 2;
    }
    return x;
  }
};
#line 2 "library/alg/monoid/max.hpp"

template <typename E>
struct Monoid_Max {
  using X = E;
  using value_type = X;
  static constexpr X op(const X &x, const X &y) noexcept { return max(x, y); }
  static constexpr X unit() { return -infty<E>; }
  static constexpr bool commute = true;
};
#line 5 "main.cpp"

pi sub(ll K, vc<pi> dat) {
  SHOW(K, dat);
  pi ANS = {-infty<ll>, infty<ll>};
  auto upd = [&](ll L, ll R) -> void {
    if (ANS.se - ANS.fi > R - L) ANS = {L, R};
    if (ANS.se - ANS.fi == R - L && ANS.fi > L) ANS = {L, R};
  };

  vi X;
  auto add_x = [&](ll x) -> void {
    // FOR(d, -1, 2) {
    //   ll a = x + d;
    //   if (a >= 0) X.eb(a);
    // }
    X.eb(x);
  };
  add_x(0);
  for (auto& [x, c]: dat) add_x(x);
  UNIQUE(X);

  ll N = len(X);
  vi W(N);
  for (auto& [x, c]: dat) W[LB(X, x)] += c;

  vi LEFT(N);
  FOR(i, N) LEFT[i] = X[i] * W[i];
  auto LEFTc = cumsum<ll>(LEFT);

  /*
  penalty
  (1) L 以上はすべて L として計算する
  (2) R 以上 : x-R を加算する

  (2) は R について折線であるから、その折線のグラフ F を求めておく
  */

  auto Wc = cumsum<ll>(W);
  vi F(N);
  {
    ll w = 0;
    FOR_R(i, N) {
      if (i < N - 1) {
        ll dx = X[i + 1] - X[i];
        F[i] = F[i + 1] + w * dx;
      }
      w += W[i];
    }
  }

  SegTree<Monoid_Max<ll>> seg(F);

  FOR(i, N - 1) {
    ll L = X[i];
    ll val = 0;
    val += L * (Wc[N] - Wc[i + 1]);
    val += LEFTc[i + 1];
    // val + F[j] >= K となる最小の j>=i+1
    int j = seg.max_right([&](ll x) -> bool { return val + x < K; }, i + 1);
    if (j == N) continue;

    // R==X[j] : ok
    upd(L, X[j]);
    // 線分 X[j-1], X[j] のところも見る
    ll s = (F[j] - F[j - 1]) / (X[j] - X[j - 1]);
    // val + F[j-1] + s(x-X[j-1]) >= K
    if (s <= 0) continue;
    ll R = ceil<ll>(K - val - F[j - 1], s) + X[j - 1];
    SHOW(L, R);
    if (X[j - 1] <= R && R <= X[j] && val + F[j - 1] + s * (R - X[j - 1]) >= K) upd(L, R);
  }

  // R が大事な点
  // f(R),R
  deque<pi> st;
  FOR_R(i, 1, N) {
    while (len(st)) {
      auto [x1, y1] = st.back();
      if (x1 > F[i]) break;
      st.pop_back();
    }
    st.eb(F[i], X[i]);
    // X[i-1]<=L<=X[i] にとる
    ll b = LEFTc[i];
    ll a = Wc[N] - Wc[i];
    // aL+b>=K
    ll ma = max(a * X[i - 1] + b, a * X[i] + b);
    while (len(st)) {
      auto [FR, R] = st.front();
      if (FR + ma < K) break;
      st.pop_front();
      if (a == 0) { upd(X[i], R); }
      elif (a > 0) { upd(X[i], R); }
      elif (a < 0) {
        ll x = floor<ll>(b + FR - K, -a);
        chmax(x, X[i - 1]), chmin(x, X[i]);
        upd(x, R);
      }
    }
  }

  if (ANS.fi == -infty<ll>) return ANS;

  auto [L, R] = ANS;
  if (L == 0) return {L, R};
  ll A = LB(X, L) - 1;
  ll B = LB(X, R) - 1;
  assert(X[A] < L && L <= X[A + 1]);
  assert(X[B] < R && R <= X[B + 1]);
  ll s = (F[B + 1] - F[B]) / (X[B + 1] - X[B]);
  auto f = [&](ll x) -> ll {
    ll val = 0;
    val += (L - x) * (Wc[N] - Wc[A + 1]);
    val += LEFTc[A + 1];
    x = R - x;
    val += F[B] + s * (x - X[B]);
    SHOW(x, val, K);
    return val;
  };

  ll LIM = min<ll>(L - X[A], R - X[B]);
  SHOW(L, R, LIM);
  ll a = binary_search([&](ll x) -> bool { return f(x) >= K; }, 0, LIM + 1);
  L -= a, R -= a;
  return {L, R};
}

void solve() {
  LL(N, P);
  vc<tuple<ll, ll, ll, ll>> inp;
  FOR(N) {
    LL(a, b, c, d);
    --a;
    inp.eb(a, b, c, d);
  }

  // problem -> First AC time
  vc<map<ll, ll>> AC_time(2);
  for (auto& [team, prob, x, ac]: inp) {
    if (ac == 0) continue;
    if (AC_time[team].count(prob)) continue;
    AC_time[team][prob] = x;
  }
  if (len(AC_time[0]) != len(AC_time[1])) return print(-1);

  vi penalty(2);
  vc<set<ll>> done(2);
  for (auto& [team, prob, x, ac]: inp) {
    if (ac) {
      done[team].insert(prob);
      continue;
    }
    // 最終的に AC します
    if (!AC_time[team].count(prob)) continue;
    // まだ AC していません
    if (done[team].count(prob)) continue;
    penalty[team] += P;
  }

  // penalty[0] - penalty[1] に足す[係数, 時刻]
  vc<pi> dat;
  for (auto& [a, b]: AC_time[0]) dat.eb(b, 1);
  for (auto& [a, b]: AC_time[1]) dat.eb(b, -1);

  ll result = penalty[0] - penalty[1];
  for (auto& [x, c]: dat) result += c * x;

  // now + sum(cx)<=0 を目指す
  ll now = 0;
  if (result > 0) {
    now = penalty[0] - penalty[1];
  } else {
    // pena[0]-pena[1]+sum(cx) > 0 を目指す
    // pena[1]-pena[0]-sum(cx) < 0 を目指す
    // 1+pena[1]-pena[0]-sum(cx) <= 0 を目指す
    now = 1 + penalty[1] - penalty[0];
    for (auto& [x, c]: dat) c = -c;
  }

  // 非負を目指すことにする
  now = -now;
  for (auto& [x, c]: dat) c = -c;

  sort(all(dat));

  // 前処理できた
  pi ANS = sub(-now, dat);
  if (ANS.fi < 0) return print(-1);
  print(ANS);
  // print(ANS.se - ANS.fi);
}

signed main() {
  INT(T);
  FOR(T) solve();
  return 0;
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
6 20
1 1 60 0
2 2 60 0
2 2 120 1
1 2 180 1
1 2 180 0
2 2 300 1
2 20
1 1 300 1
2 2 300 1

output:

120 160
-1

result:

ok 3 number(s): "120 160 -1"

Test #2:

score: 0
Accepted
time: 81ms
memory: 3976kb

input:

400000
1 1
1 1000000000 1000000000000 1
1 1
2 1000000000 1 0
1 1
2 1 1000000000000 1
1 1
1 1 1000000000000 1
1 1
2 1000000000 1000000000000 0
1 1
2 1 1 0
1 1000000000000
2 1000000000 1 0
1 1000000000000
1 1 1 0
1 1000000000000
1 1 1 1
1 1000000000000
2 1000000000 1000000000000 0
1 1
1 1000000000 1 0...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

ok 400000 numbers

Test #3:

score: 0
Accepted
time: 37ms
memory: 3972kb

input:

10000
4 542575683220
2 101300788 7308006925 1
1 604560531 257884671293 0
1 46911674 422781533607 0
2 10550533 771273976896 1
116 793781361888
1 819065134 15224463201 1
2 552573547 15992997563 1
2 424217 27032314690 0
2 70252887 41541882886 0
2 274093456 46129251985 0
1 458919850 46344406806 1
1 8416...

output:

-1
-1
-1
-1
-1
66660446969 904724933033
-1
-1
-1
-1
-1
-1
37226106549 311799565893
-1
-1
-1
-1
-1
-1
48301734080 375528816957
-1
-1
-1
459021288402 632610827258
-1
-1
-1
-1
-1
-1
-1
688320095661 898231263806
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
21800224424...

result:

ok 10846 numbers

Test #4:

score: 0
Accepted
time: 44ms
memory: 4168kb

input:

1000
41 699991536758
1 846433454 45030190307 1
2 882516075 48235731920 1
1 488580715 68600854082 1
2 467682948 92731902940 1
1 218024396 138543808852 1
2 124969525 150196554430 0
2 989301314 181283691649 1
2 752581868 202920989593 0
2 164838619 269703109427 0
1 696316428 295229433897 0
2 711333918 3...

output:

329739379675 908226682656
-1
-1
-1
-1
-1
424620801981 831021050071
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
6963797897 888755778656
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
568768655870 677350535270
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

ok 1042 numbers

Test #5:

score: 0
Accepted
time: 42ms
memory: 5092kb

input:

100
5622 365182448552
2 639763453 293138584 0
1 150269480 461335412 1
1 215320018 935778069 1
2 455090474 986867198 1
2 137209887 1025838937 1
1 639542200 1323284104 0
2 975624632 1331236944 1
1 419729668 1535875032 0
1 754484749 1638561677 1
2 718600604 2047704086 0
2 793817561 2082808091 1
2 89416...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1

result:

ok 100 numbers

Test #6:

score: 0
Accepted
time: 71ms
memory: 11876kb

input:

10
17647 497735816936
2 674642608 86555331 1
1 362561577 201254993 1
2 311798376 317505931 0
1 997152835 354905086 0
1 501042015 406191428 1
2 346791377 498440233 0
2 883536093 569248570 0
1 242082992 714310537 1
1 149897006 726750432 1
2 951017299 800159980 0
2 258554143 816615965 0
1 681430878 825...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1

result:

ok 10 numbers

Test #7:

score: 0
Accepted
time: 115ms
memory: 29996kb

input:

1
400000 263629556026
2 954826535 1576313 1
1 970048058 1644473 1
1 100070583 1779363 0
1 862973854 2602197 0
1 544583759 6163089 1
1 292939527 13244435 1
1 818324382 16877678 1
1 255969879 32429661 0
1 578761398 33091132 1
2 337038014 34601245 0
1 46604309 39135309 0
2 501363911 40833345 1
1 210491...

output:

-1

result:

ok 1 number(s): "-1"

Test #8:

score: 0
Accepted
time: 478ms
memory: 100256kb

input:

1
399863 925298013757
2 100628989 1 0
2 879908544 1 0
2 835150000 1 0
2 965097317 1 0
2 806475166 1 0
2 883153545 1 0
2 537871549 1 0
2 666240466 1 0
2 772690810 1 0
2 468000116 1 0
2 57197741 1 0
2 752910244 1 0
2 34579873 1 0
2 764798890 1 0
2 385606621 1 0
2 359331506 1 0
2 280339733 1 0
2 485810...

output:

93600917303 93601131398

result:

ok 2 number(s): "93600917303 93601131398"

Test #9:

score: 0
Accepted
time: 477ms
memory: 101568kb

input:

1
399494 961261170252
1 500382911 1 0
1 343020544 1 0
1 754347645 1 0
1 333064084 1 0
1 478385269 1 0
1 622968098 1 0
1 980169601 1 0
1 352209103 1 0
1 402748538 1 0
1 218430474 1 0
1 288936411 1 0
1 5773706 1 0
1 698161932 1 0
1 366209929 1 0
1 73511871 1 0
1 725720796 1 0
1 888663191 1 0
1 3011404...

output:

93601000787 93601218921

result:

ok 2 number(s): "93601000787 93601218921"

Test #10:

score: 0
Accepted
time: 21ms
memory: 21104kb

input:

1
400000 663010
1 680238422 483214 0
1 680238422 521442 0
1 680238422 609593 0
1 680238422 1476058 0
1 680238422 2424603 0
1 680238422 2483379 0
1 680238422 2777054 0
1 680238422 3992033 0
1 680238422 4038346 0
1 680238422 4500144 0
1 680238422 4613302 0
1 680238422 4698260 0
1 680238422 4860707 0
1...

output:

-1

result:

ok 1 number(s): "-1"

Test #11:

score: 0
Accepted
time: 10ms
memory: 21640kb

input:

1
400000 79784
1 110051200 202567778970 0
1 110051200 202567778970 0
1 110051200 202567778970 0
1 110051200 202567778970 0
1 110051200 202567778970 0
1 110051200 202567778970 0
1 110051200 202567778970 0
1 110051200 202567778970 0
1 110051200 202567778970 0
1 110051200 202567778970 0
1 110051200 202...

output:

202567778970 879492417995

result:

ok 2 number(s): "202567778970 879492417995"

Test #12:

score: 0
Accepted
time: 21ms
memory: 20420kb

input:

1
400000 48790
1 554756625 480690 0
1 554756625 3230620 0
1 554756625 3409127 0
1 514075804 3753536 0
1 554756625 4724772 0
2 188054527 5311431 0
1 100903989 5807895 0
1 933163205 7291004 0
2 382472190 8139517 0
1 239315307 8310712 0
1 554756625 8348744 0
1 14438382 8939856 0
1 554756625 11989642 0
...

output:

13251717318 599133935039

result:

ok 2 number(s): "13251717318 599133935039"

Test #13:

score: 0
Accepted
time: 14ms
memory: 20280kb

input:

1
400000 255041
2 181766528 25787236213 0
2 181766528 25787236213 0
2 181766528 25787236213 0
2 181766528 25787236213 0
2 181766528 25787236213 0
2 181766528 25787236213 0
2 181766528 25787236213 0
2 181766528 25787236213 0
2 181766528 25787236213 0
2 181766528 25787236213 0
2 181766528 25787236213 ...

output:

306238410801 624516496355

result:

ok 2 number(s): "306238410801 624516496355"

Test #14:

score: 0
Accepted
time: 34ms
memory: 20244kb

input:

1
400000 952892
1 669079782 5249 0
1 669079782 1051034 0
1 669079782 1478798 0
1 643031526 2194715 0
1 669079782 2318113 0
2 195012273 3054972 0
2 608030266 3674227 0
1 927916867 3904831 0
1 669079782 4349111 0
2 214184786 6595409 0
1 669079782 6663358 0
2 403805672 6933063 0
1 669079782 7146955 0
2...

output:

13932447919 987373706861

result:

ok 2 number(s): "13932447919 987373706861"

Test #15:

score: 0
Accepted
time: 21ms
memory: 21420kb

input:

1
400000 445351
2 43725609 629636445 0
2 43725609 629636445 0
2 43725609 629636445 0
2 43725609 629636445 0
2 43725609 629636445 0
2 43725609 629636445 0
2 43725609 629636445 0
2 43725609 629636445 0
2 43725609 629636445 0
2 43725609 629636445 0
2 43725609 629636445 0
2 43725609 629636445 0
2 437256...

output:

-1

result:

ok 1 number(s): "-1"

Test #16:

score: 0
Accepted
time: 67ms
memory: 20584kb

input:

1
400000 737917
2 104548428 355151 0
2 798447330 563764 0
2 807313778 726293 0
1 225967449 777825 0
1 76979820 830949 0
2 798447330 1204358 0
1 152843063 1242227 0
1 147816717 1604061 0
2 884732354 2045708 0
1 899307173 2280899 0
1 923713510 2447044 0
2 807313778 2651301 0
2 148086652 2704087 0
2 79...

output:

294972586721 744194775850

result:

ok 2 number(s): "294972586721 744194775850"

Test #17:

score: 0
Accepted
time: 27ms
memory: 21224kb

input:

1
400000 797979
1 698025121 76252326 0
1 698025121 76252326 0
1 698025121 76252326 0
1 698025121 76252326 0
1 698025121 76252326 0
1 698025121 76252326 0
1 698025121 76252326 0
1 698025121 76252326 0
1 698025121 76252326 0
1 698025121 76252326 0
1 698025121 76252326 0
1 698025121 76252326 0
1 698025...

output:

297321818946 857889105465

result:

ok 2 number(s): "297321818946 857889105465"

Test #18:

score: 0
Accepted
time: 156ms
memory: 24736kb

input:

1
400000 559759
1 334035078 470519 0
1 768140446 2967944 0
1 77040897 3088991 0
2 493261355 4283608 0
2 914055376 4561618 0
1 249929265 5223548 0
1 471764388 5364482 0
1 438202587 6820774 0
1 548072976 7173586 0
1 152064110 7904320 0
2 187798068 9277616 0
2 554380228 11571775 0
2 999624048 11848525 ...

output:

368607061812 459867556579

result:

ok 2 number(s): "368607061812 459867556579"

Test #19:

score: 0
Accepted
time: 80ms
memory: 26676kb

input:

1
400000 923129
1 830682125 6777784 0
1 830682125 6777784 0
1 830682125 6777784 0
1 830682125 6777784 1
1 830682125 6777784 0
1 830682125 6777784 0
1 830682125 6777784 0
2 502376403 98306211 0
2 502376403 98306211 0
2 502376403 98306211 0
2 502376403 98306211 0
2 502376403 98306211 0
2 502376403 983...

output:

603264713406 904051411073

result:

ok 2 number(s): "603264713406 904051411073"

Test #20:

score: 0
Accepted
time: 151ms
memory: 4144kb

input:

10000
34 713414155711
1 353899840 4470478880 1
1 101300788 14617874162 1
2 224463201 46129251985 1
2 997067155 53850132914 1
1 493411629 67237771644 1
2 60685412 153612550178 1
2 932182989 159471048139 1
2 821881991 174028196456 1
2 887385900 188331357182 1
2 819065134 200111294061 1
2 348545253 247...

output:

483871970490 840598269617
196200037892 970964066001
283567194848 914830957817
-1
-1
224079150450 800412473197
100330184885 227585151128
50506210564 783882723066
406628103960 924434625801
634770465011 738356832148
16323343084 723566375795
28913275304 938587397050
-1
461193028837 931629993981
36470471...

result:

ok 18515 numbers

Test #21:

score: 0
Accepted
time: 182ms
memory: 4708kb

input:

1000
60 171285665612
1 202084572 21122606424 1
2 658066585 35408059059 1
1 23311972 51059588296 1
1 555006790 53867325184 1
2 668895851 61404100899 1
2 439334198 66467682948 1
2 814813731 75505419882 1
2 563694648 84052137524 1
1 863531125 84160720592 1
2 666879230 92731902940 1
1 310726910 12688787...

output:

200468370512 983989301314
105910501928 853497904904
928492782007 939126373321
342619682920 456502006066
282459092744 713342359655
99203627100 110822178667
496813497898 828241040007
5149945202 998323717204
20989066921 948454205300
353986139415 989439227450
134191973984 722450971884
64821218433 932293...

result:

ok 1942 numbers

Test #22:

score: 0
Accepted
time: 224ms
memory: 8316kb

input:

100
302 495480207413
1 157557196 5191700656 1
2 688131848 7822346081 1
2 302959585 11342249961 1
2 667487485 12602857386 1
1 981368818 14235797064 1
2 862638974 15778895657 1
2 938801239 16033062185 1
2 141565804 18783237506 1
2 600109241 21882439145 1
1 866713826 23983150467 1
2 17855262 2555711801...

output:

12878839367 465356894994
98670299607 984006430918
659460612429 921298289091
261717617158 758562225078
16656906317 946242259897
604865303455 742610447485
65635714807 979156099520
414255260549 900331635889
86571338038 510051964019
302298934987 885584590000
15514653060 928519135170
11536475812 99954734...

result:

ok 197 numbers

Test #23:

score: 0
Accepted
time: 340ms
memory: 32740kb

input:

10
69720 312974804124
1 375110834 3284756 1
2 958035607 5372989 1
1 96816917 5896324 1
1 659349114 23601583 1
1 123026525 45334114 1
2 810136368 59250875 1
2 382704738 59429789 1
1 397855561 69769833 1
2 194473720 85533928 1
1 41349414 87337444 1
1 854195287 89285949 1
2 208588652 102226384 1
2 8322...

output:

192359142508 690359228247
4301019212 770771226671
59321270708 972659014596
34895107242 342872704017
43369717825 828295749790
281202583338 607302423053
105982895679 805855161263
12072175115 993484291384
114227155230 666678426833
136839246084 981181564986

result:

ok 20 numbers

Test #24:

score: 0
Accepted
time: 649ms
memory: 103644kb

input:

1
400000 862246722332
1 879284128 1644473 1
1 566310427 2602197 1
1 305759998 3635844 1
2 306032716 11995694 1
2 389513871 14509476 1
2 761692038 14593427 1
2 924522024 17673793 1
1 604735028 18750462 1
2 312343123 19169330 1
1 37783135 19583722 1
2 765576144 19935364 1
1 508498315 23251498 1
2 3123...

output:

511340089351 555367600772

result:

ok 2 number(s): "511340089351 555367600772"

Test #25:

score: 0
Accepted
time: 609ms
memory: 106116kb

input:

1
400000 601546500618
1 193617644 437488 1
1 687635851 1161220 1
1 867854270 3644275 1
2 75321946 7668994 1
2 19512874 8264014 1
2 2373384 11375302 1
2 167691473 17921764 1
1 837478720 23661825 1
1 319362132 27535622 1
2 9492126 28282384 1
2 21937131 28442718 1
1 284421469 28539626 1
1 313762592 307...

output:

212927310768 944532983806

result:

ok 2 number(s): "212927310768 944532983806"

Test #26:

score: 0
Accepted
time: 140ms
memory: 4280kb

input:

10000
59 10000000000
2 38224116 294735 0
1 791184194 294735 1
2 38224116 1963991 1
1 46743924 2052699 1
1 555377382 3945603 1
2 686459062 3952976 1
2 905596132 7512134 1
2 420873888 8587106 1
1 586803310 8596700 1
1 755231195 12584511 1
1 403524468 17231015 1
1 460174100 23414884 1
2 115239866 25206...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

ok 13652 numbers

Test #27:

score: 0
Accepted
time: 175ms
memory: 4504kb

input:

1000
99 10000000000
2 307832277 78148 0
2 307832277 78148 1
1 275518058 2292869 1
2 318752188 3421425 1
1 538132005 4313972 1
2 559436916 4729882 1
2 97509167 4815124 1
2 154178279 4851744 1
2 567062651 6312029 1
2 665106524 7115329 1
2 715927148 8744720 1
1 502131755 9331956 1
2 809734156 9420053 1...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

ok 1468 numbers

Test #28:

score: 0
Accepted
time: 205ms
memory: 8356kb

input:

100
10051 10000000000
2 139050006 1151 0
2 139050006 1151 1
1 500313852 6700 1
2 681995605 9186 1
1 270810606 22090 1
1 995827512 24954 1
1 53631098 30759 1
1 399843074 46446 1
2 126028509 48532 1
1 981492639 53805 1
2 702955098 123192 1
1 795346040 129998 1
2 556795597 151390 1
1 989719151 160084 1...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
182168532 694021729
-1
-1
-1
-1
577259203 783733321
-1
-1
-1
671704640 925928203
-1
-1
-1
-1
-1
138312166 436590105
-1
130000444 166930180
1796852385 5828587855
3700769434 7831971589
5341012067 6770347121
-1
924292593 5310349577
11307...

result:

ok 154 numbers

Test #29:

score: 0
Accepted
time: 359ms
memory: 40572kb

input:

10
128435 10000000000
2 650210546 297 0
2 650210546 297 1
1 614257067 1396 1
2 303092138 3047 1
1 571581225 3700 1
2 385229129 4100 1
1 445435100 4835 1
2 193655129 6197 1
2 153784571 7701 1
1 104200814 10218 1
1 60272333 10546 1
1 633189238 11303 1
1 100743505 11632 1
1 402614614 11726 1
2 6587875 ...

output:

-1
-1
-1
-1
5027602745 7828469284
809575451 2243952975
50008876934 92680594103
68404371711 98198887855
599544816032 676768101584
32564552152 866063397702

result:

ok 16 numbers

Test #30:

score: 0
Accepted
time: 602ms
memory: 104028kb

input:

1
399999 10000000000
2 233850926 90 0
1 748456332 90 1
1 213487336 626 1
1 157311336 716 1
1 28947387 765 1
1 424478786 1436 1
1 548164753 1638 1
1 431903000 1949 1
2 233850926 2028 1
2 716019297 2086 1
2 275417128 2176 1
2 289866313 2231 1
2 275427198 2822 1
2 749995741 2921 1
1 874030515 3547 1
2 ...

output:

-1

result:

ok 1 number(s): "-1"

Test #31:

score: 0
Accepted
time: 600ms
memory: 106012kb

input:

1
399999 10000000000
1 326385488 311 0
1 326385488 311 1
1 203877106 1099 1
2 644432124 1199 1
2 127852006 1290 1
2 407011871 1404 1
1 167030010 1854 1
1 704974376 2001 1
2 176461067 2510 1
2 528064718 2688 1
2 558130105 2947 1
2 472257639 3212 1
1 17497002 3607 1
1 887225470 3609 1
1 885238663 3997...

output:

47241340 63768254

result:

ok 2 number(s): "47241340 63768254"

Test #32:

score: 0
Accepted
time: 617ms
memory: 105096kb

input:

1
399999 10000000000
2 720746168 2538 0
1 389889266 2538 1
1 846649225 3346 1
2 720746168 6867 1
2 220578380 8319 1
2 478006698 14785 1
1 543403305 15269 1
1 994117268 17197 1
1 244609566 17573 1
1 186393243 18023 1
1 429534436 19900 1
1 831875453 21942 1
2 708904325 22934 1
2 674347985 25188 1
1 89...

output:

63929246 848919318

result:

ok 2 number(s): "63929246 848919318"

Test #33:

score: 0
Accepted
time: 613ms
memory: 105148kb

input:

1
399999 10000000000
1 708135129 3777 0
1 708135129 3777 1
2 378842907 12099 1
2 491334572 15760 1
2 57000817 22432 1
2 107356454 24206 1
1 355006013 25808 1
1 215578462 26957 1
1 915491561 27307 1
2 955971633 39399 1
2 609588029 44169 1
2 842497351 48865 1
1 617427596 53607 1
2 398484603 54969 1
2 ...

output:

27037798 925795917

result:

ok 2 number(s): "27037798 925795917"

Test #34:

score: 0
Accepted
time: 637ms
memory: 106296kb

input:

1
399999 10000000000
2 85635799 55054 0
2 85635799 55054 1
1 280335848 174979 1
2 939318300 209001 1
2 894465429 284645 1
2 618497444 297291 1
2 965916461 360005 1
1 974758958 400989 1
1 764253644 422154 1
2 15313245 481707 1
2 663242137 493111 1
1 798251629 520714 1
1 578532763 538498 1
2 468635252...

output:

996300115 8421496745

result:

ok 2 number(s): "996300115 8421496745"

Test #35:

score: 0
Accepted
time: 645ms
memory: 103248kb

input:

1
399999 10000000000
1 419779110 42873 0
2 809879504 42873 1
2 969885028 63945 1
1 419779110 78559 1
2 833465970 114507 1
1 575954552 137275 1
2 845350982 144299 1
1 829415866 177492 1
2 377975311 191331 1
2 543827092 388125 1
2 954840061 429840 1
1 234193563 430657 1
2 814992278 519061 1
2 13492113...

output:

3348662196 5187741015

result:

ok 2 number(s): "3348662196 5187741015"

Test #36:

score: 0
Accepted
time: 666ms
memory: 103580kb

input:

1
399999 10000000000
2 53438133 376125 0
2 53438133 376125 1
2 987743109 395850 1
1 166707936 441017 1
2 740702438 626572 1
2 254475979 650308 1
2 327881470 975326 1
1 519757004 1146648 1
1 745882219 1449930 1
1 704933732 1504462 1
1 567410879 1660559 1
1 501447393 2155145 1
1 217253545 2205303 1
2 ...

output:

75248596220 96080897908

result:

ok 2 number(s): "75248596220 96080897908"

Test #37:

score: 0
Accepted
time: 625ms
memory: 106232kb

input:

1
399999 10000000000
1 490359113 409073 0
2 635603234 409073 1
1 490359113 582604 1
1 466100352 1806496 1
1 851462909 2072668 1
2 835324462 2096985 1
1 306968106 2569687 1
2 843905600 2624494 1
1 421262349 2841982 1
2 566061630 3227185 1
1 840367098 3398146 1
1 755106699 3440275 1
1 893965367 398535...

output:

-1

result:

ok 1 number(s): "-1"

Test #38:

score: 0
Accepted
time: 607ms
memory: 103660kb

input:

1
399999 10000000000
2 108713408 355367 0
1 495440048 355367 1
2 108713408 5246476 1
1 829460048 18527254 1
2 643329162 19258328 1
2 889222716 22102287 1
2 408057726 26361813 1
2 793626956 26469500 1
2 138076520 29441704 1
1 91238764 31551010 1
2 871893174 31820730 1
1 668770819 34779933 1
1 8155239...

output:

326517728008 374248053587

result:

ok 2 number(s): "326517728008 374248053587"

Test #39:

score: 0
Accepted
time: 620ms
memory: 106144kb

input:

1
399999 10000000000
1 107735064 1466866 0
2 435376868 1466866 1
1 107735064 4168250 1
1 514024463 6140405 1
2 743983631 11245466 1
1 806314530 15082970 1
1 785572414 15407736 1
1 210419929 17442417 1
2 614548459 17450482 1
1 82717421 17736378 1
2 747895352 19709129 1
2 512995307 20474608 1
1 917777...

output:

24033093497 889551871011

result:

ok 2 number(s): "24033093497 889551871011"

Extra Test:

score: 0
Extra Test Passed