QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#700146#9524. 1D GalaxyTheZoneAC ✓109ms22392kbC++2339.5kb2024-11-02 12:08:132024-11-02 12:08:14

Judging History

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

  • [2024-11-02 12:08:14]
  • 评测
  • 测评结果:AC
  • 用时:109ms
  • 内存:22392kb
  • [2024-11-02 12:08:13]
  • 提交

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

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); }
#line 3 "main.cpp"

#line 2 "library/ds/unionfind/unionfind.hpp"

struct UnionFind {
  int n, n_comp;
  vc<int> dat; // par or (-size)
  UnionFind(int n = 0) { build(n); }

  void build(int m) {
    n = m, n_comp = m;
    dat.assign(n, -1);
  }

  void reset() { build(n); }

  int operator[](int x) {
    while (dat[x] >= 0) {
      int pp = dat[dat[x]];
      if (pp < 0) { return dat[x]; }
      x = dat[x] = pp;
    }
    return x;
  }

  ll size(int x) {
    x = (*this)[x];
    return -dat[x];
  }

  bool merge(int x, int y) {
    x = (*this)[x], y = (*this)[y];
    if (x == y) return false;
    if (-dat[x] < -dat[y]) swap(x, y);
    dat[x] += dat[y], dat[y] = x, n_comp--;
    return true;
  }

  vc<int> get_all() {
    vc<int> A(n);
    FOR(i, n) A[i] = (*this)[i];
    return A;
  }
};
#line 2 "library/ds/fastset.hpp"

// 64-ary tree
// space: (N/63) * u64
struct FastSet {
  static constexpr u32 B = 64;
  int n, log;
  vvc<u64> seg;

  FastSet() {}
  FastSet(int n) { build(n); }

  int size() { return n; }

  template <typename F>
  FastSet(int n, F f) {
    build(n, f);
  }

  void build(int m) {
    seg.clear();
    n = m;
    do {
      seg.push_back(vc<u64>((m + B - 1) / B));
      m = (m + B - 1) / B;
    } while (m > 1);
    log = len(seg);
  }
  template <typename F>
  void build(int n, F f) {
    build(n);
    FOR(i, n) { seg[0][i / B] |= u64(f(i)) << (i % B); }
    FOR(h, log - 1) {
      FOR(i, len(seg[h])) {
        seg[h + 1][i / B] |= u64(bool(seg[h][i])) << (i % B);
      }
    }
  }

  bool operator[](int i) const { return seg[0][i / B] >> (i % B) & 1; }
  void insert(int i) {
    for (int h = 0; h < log; h++) {
      seg[h][i / B] |= u64(1) << (i % B), i /= B;
    }
  }
  void add(int i) { insert(i); }
  void erase(int i) {
    u64 x = 0;
    for (int h = 0; h < log; h++) {
      seg[h][i / B] &= ~(u64(1) << (i % B));
      seg[h][i / B] |= x << (i % B);
      x = bool(seg[h][i / B]);
      i /= B;
    }
  }
  void remove(int i) { erase(i); }

  // min[x,n) or n
  int next(int i) {
    assert(i <= n);
    chmax(i, 0);
    for (int h = 0; h < log; h++) {
      if (i / B == seg[h].size()) break;
      u64 d = seg[h][i / B] >> (i % B);
      if (!d) {
        i = i / B + 1;
        continue;
      }
      i += lowbit(d);
      for (int g = h - 1; g >= 0; g--) {
        i *= B;
        i += lowbit(seg[g][i / B]);
      }
      return i;
    }
    return n;
  }

  // max [0,x], or -1
  int prev(int i) {
    assert(i >= -1);
    if (i >= n) i = n - 1;
    for (int h = 0; h < log; h++) {
      if (i == -1) break;
      u64 d = seg[h][i / B] << (63 - i % B);
      if (!d) {
        i = i / B - 1;
        continue;
      }
      i -= __builtin_clzll(d);
      for (int g = h - 1; g >= 0; g--) {
        i *= B;
        i += topbit(seg[g][i / B]);
      }
      return i;
    }
    return -1;
  }

  bool any(int l, int r) { return next(l) < r; }

  // [l, r)
  template <typename F>
  void enumerate(int l, int r, F f) {
    for (int x = next(l); x < r; x = next(x + 1)) f(x);
  }

  string to_string() {
    string s(n, '?');
    for (int i = 0; i < n; ++i) s[i] = ((*this)[i] ? '1' : '0');
    return s;
  }
};
#line 6 "main.cpp"

/*
type 0 : 通常
type 1 : ペアの左側
type 2 : ペアの右側

ペアの who:偶数時刻のものを持たせることにする
L,R も偶数時刻ときのやつを持っている
*/

struct Data {
  int tp;
  ll who;  // union find で代表元のひとつ
  ll a, b; // 座標が a+bt です
  ll W, L, R;
  Data() {}
  Data(ll i, ll x, ll L, ll R, ll W) : W(W), L(L), R(R) {
    tp = 0;
    who = i;
    if (L > R) b = -1;
    if (L == R) b = 0;
    if (L < R) b = 1;
    a = x;
  }

  ll pos(ll t) { return a + b * t; }
};

void solve() {
  LL(N, Q);
  vi X(N), W(N);
  FOR(i, N) read(X[i], W[i]);
  vc<pi> query(Q);
  FOR(q, Q) read(query[q]);
  for (auto& [t, i]: query) { --i; }

  {
    UnionFind uf(N);
    map<ll, int> MP;
    FOR(i, N) {
      ll x = X[i];
      if (MP.count(x))
        uf.merge(i, MP[x]);
      else
        MP[x] = i;
    }
    FOR(i, N) if (i != uf[i]) W[uf[i]] += W[i];
    vc<int> new_idx(N, -1);
    int p = 0;
    FOR(i, N) if (uf[i] == i) new_idx[i] = p++;
    vi XX, WW;
    FOR(i, N) if (uf[i] == i) XX.eb(X[i]), WW.eb(W[i]);
    swap(X, XX);
    swap(W, WW);
    for (auto& [t, i]: query) i = new_idx[uf[i]];
  }
  {
    auto I = argsort(X);
    vc<int> new_idx = argsort(I);
    X = rearrange(X, I);
    W = rearrange(W, I);
    for (auto& [t, i]: query) i = new_idx[i];
  }
  N = len(X);
  ll W_ALL = SUM<ll>(W);

  UnionFind uf(N);
  FastSet FS(N);
  FOR(i, N) FS.insert(i);
  vc<Data> dat(N);

  {
    ll left = 0;
    FOR(i, N) {
      dat[i] = Data(i, X[i], left, W_ALL - left - W[i], W[i]);
      left += W[i];
    }
  }

  // t,-1,q,0: 求値
  // t,dist(i,j),i,j: 時刻, 関係者の左の index
  pqg<tuple<ll, ll, ll, ll>> que;
  FOR(q, Q) {
    auto [t, i] = query[q];
    que.emplace(t, -1, q, 0);
  }

  // いま誰がどこにいるか
  vc<int> where(N);
  FOR(i, N) where[i] = i;

  auto upd_que = [&](ll time, int i) -> void {
    // i とその右の人に発生するイベントを追加する
    if (!(0 <= i && i < N)) return;
    if (!FS[i]) return;
    assert(FS[i]);
    int j = FS.next(i + 1);
    if (j == N) return;
    Data &A = dat[i], &B = dat[j];
    ll dst = B.pos(time) - A.pos(time);
    ll d = A.b - B.b; // ちかづく速度
    if (dst == 0) que.emplace(time, 0, i, j);
    SHOW(i, j, A.b, B.b, d);
    if (d <= 0) return;
    ll k = floor<ll>(dst, d);
    SHOW("upd_que", time + k, dst - d * k, i, j);
    que.emplace(time + k, dst - d * k, i, j);
    return;
  };

  auto unlink = [&](ll time, int i, int j) -> void {
    ll xi = dat[i].pos(time);
    ll xj = dat[j].pos(time);
    // tp==1,2のやつを解体
    assert(dat[i].tp == 1 && dat[j].tp == 2);
    dat[i].tp = 0;
    dat[j].tp = 0;
    if (time % 2 == 1) {
      ll L = dat[i].L, R = dat[j].R; // 両方をむししたの左右
      dat[i].L = L, dat[i].R = R + dat[i].W;
      dat[j].L = L + dat[j].W, dat[j].R = R;
      swap(dat[i].who, dat[j].who);
      swap(dat[i].W, dat[j].W);
      where[uf[dat[i].who]] = i;
      where[uf[dat[j].who]] = j;
    }
    for (auto& k: {i, j}) {
      ll x = (k == i ? xi : xj);
      ll L = dat[k].L, R = dat[k].R;
      ll b = 0;
      if (L > R) b = -1;
      if (L < R) b = 1;
      // a+b*time=x
      ll a = x - b * time;
      dat[k].a = a, dat[k].b = b;
    }
  };

  /*
  int tp;
  ll who;  // union find で代表元のひとつ
  ll a, b; // 座標が a+bt です
  ll W, L, R;
  */
  auto link = [&](ll time, int i, int j) -> void {
    assert(dat[i].tp == 0);
    assert(dat[j].tp == 0);
    ll xi = dat[i].pos(time);
    ll xj = dat[j].pos(time);
    ll who_i = dat[i].who, who_j = dat[j].who;
    ll L = dat[i].L, R = dat[j].R; // 両方をむししたの左右
    ll wi = dat[i].W, wj = dat[j].W;
    // tp==0,0のやつを結合
    dat[i].tp = 1;
    dat[j].tp = 2;
    if (time % 2 == 0) {
      dat[i].who = who_i, dat[j].who = who_j;

      dat[i].a = xi, dat[j].a = xj;
      dat[i].b = 0, dat[j].b = 0;
      dat[i].W = wi, dat[j].W = wj;
      dat[i].L = L, dat[j].L = L + wi;
      dat[i].R = R + wj, dat[j].R = R;
    }
    if (time % 2 == 1) {
      dat[i].who = who_j, dat[j].who = who_i;
      dat[i].a = xi, dat[j].a = xj;
      dat[i].b = 0, dat[j].b = 0;
      dat[i].W = wj, dat[j].W = wi;
      dat[i].L = L, dat[j].L = L + wj;
      dat[i].R = R + wi, dat[j].R = R;
    }
    where[uf[dat[i].who]] = i;
    where[uf[dat[j].who]] = j;
  };

  auto unlink_l = [&](ll time, int i) -> void {
    int j = FS.next(i + 1);
    unlink(time, i, j);
  };
  auto unlink_r = [&](ll time, int i) -> void {
    int j = FS.prev(i - 1);
    unlink(time, j, i);
  };

  FOR(i, N - 1) upd_que(0, i);

  vi ANS(Q);

  auto get_b = [&](ll L, ll R) -> ll {
    if (L == R) return 0;
    return (L < R ? 1 : -1);
  };

  FOR(q, Q) SHOW(query[q]);

  // type 0 : 通常
  // type 1 : ペアの左側
  // type 2 : ペアの右側
  while (len(que)) {
    auto [time, qt, i, j] = POP(que);
    if (qt == -1) {
      // i の場所を答える
      int qid = i;
      // if (qid == 0) {
      //   SHOW(FS.to_string());
      //   FOR(i, N) {
      //     auto& X = dat[i];
      //     SHOW(X.who, X.tp, X.L, X.R, X.W, X.pos(time));
      //   }
      // }
      i = query[qid].se;
      i = where[uf[i]];
      SHOW(qid, i);
      ll ANS1 = dat[i].pos(time);
      if (dat[i].tp == 1 && time % 2 == 1) { ++ANS1; }
      if (dat[i].tp == 2 && time % 2 == 1) { --ANS1; }
      ANS[qid] = ANS1;
      continue;
    }
    if (!(0 <= i && i < N)) continue;
    if (!(0 <= j && j < N)) continue;
    if (!FS[i]) continue;
    if (j != FS.next(i + 1)) continue;
    // FOR(v, N) assert(FS[where[uf[v]]]);
    SHOW(uf.get_all());
    // 更新
    Data& A = dat[i];
    Data& B = dat[j];
    ll dst = B.pos(time) - A.pos(time);
    if (dst != qt) continue;
    SHOW(time, qt, i, j, dst);
    if (dst == 0) {
      // なにかのマージが起こる
      if (dat[i].tp == 2) unlink_r(time, i);
      if (dat[j].tp == 1) unlink_l(time, j);
      assert(i < j);
      SHOW(time, i, j, A.pos(time), B.pos(time));
      SHOW("merge", dat[i].who, dat[j].who);
      SHOW(uf.get_all());
      SHOW(where);
      uf.merge(dat[i].who, dat[j].who);

      where[uf[dat[i].who]] = i;
      where[uf[dat[j].who]] = i;

      SHOW(uf.get_all());
      SHOW(where);
      FS.erase(j);
      // FOR(v, N) assert(FS[where[uf[v]]]);

      dat[i].R = dat[j].R;
      dat[i].W += dat[j].W;
      ll x = dat[i].pos(time);
      dat[i].b = get_b(dat[i].L, dat[i].R);
      dat[i].a = x - dat[i].b * time;
      // 前後と何かする
      upd_que(time, FS.prev(i - 1));
      upd_que(time, i);
    }
    if (dst == 1) {
      // 速度ベクトル
      ll b = A.b - B.b;
      if (b <= 1) continue;
      assert(b == 2);
      assert(A.tp == 0 && B.tp == 0);
      ll L = A.L, R = B.R;
      ll W1 = A.W, W2 = B.W;
      // 振動ですか?
      ll b1 = get_b(L + W2, R);
      ll b2 = get_b(L, W1 + R);
      SHOW(L, R, W1, W2);
      SHOW(b1, b2);
      if (b1 == -1 && b2 == 1) {
        SHOW("sindou", i, j);
        link(time, i, j);
      } else {
        SHOW("swap only", i, j);
        ll x1 = dat[i].pos(time);
        ll x2 = dat[j].pos(time);
        swap(dat[i].who, dat[j].who);
        where[uf[dat[i].who]] = i;
        where[uf[dat[j].who]] = j;

        dat[i].L = L, dat[i].R = R + W1;
        dat[j].L = L + W2, dat[j].R = R;
        dat[i].b = b2, dat[j].b = b1;
        swap(dat[i].W, dat[j].W);
        // a+bt==x
        dat[i].a = x1 - dat[i].b * (time + 1);
        dat[j].a = x2 - dat[j].b * (time + 1);
        upd_que(time + 1, i);
      }
      SHOW(dat[i].a, dat[i].b);
      SHOW(dat[j].a, dat[j].b);
      upd_que(time + 1, FS.prev(i - 1));
      upd_que(time + 1, j);
    }
    SHOW(time);
    SHOW(FS.to_string());
  }
  for (auto& x: ANS) print(x);
}

signed main() {
  solve();
  return 0;
}
/*#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_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;
}

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); }
#line 3 "main.cpp"

#line 2 "library/ds/unionfind/unionfind.hpp"

struct UnionFind {
  int n, n_comp;
  vc<int> dat; // par or (-size)
  UnionFind(int n = 0) { build(n); }

  void build(int m) {
    n = m, n_comp = m;
    dat.assign(n, -1);
  }

  void reset() { build(n); }

  int operator[](int x) {
    while (dat[x] >= 0) {
      int pp = dat[dat[x]];
      if (pp < 0) { return dat[x]; }
      x = dat[x] = pp;
    }
    return x;
  }

  ll size(int x) {
    x = (*this)[x];
    return -dat[x];
  }

  bool merge(int x, int y) {
    x = (*this)[x], y = (*this)[y];
    if (x == y) return false;
    if (-dat[x] < -dat[y]) swap(x, y);
    dat[x] += dat[y], dat[y] = x, n_comp--;
    return true;
  }

  vc<int> get_all() {
    vc<int> A(n);
    FOR(i, n) A[i] = (*this)[i];
    return A;
  }
};
#line 2 "library/ds/fastset.hpp"

// 64-ary tree
// space: (N/63) * u64
struct FastSet {
  static constexpr u32 B = 64;
  int n, log;
  vvc<u64> seg;

  FastSet() {}
  FastSet(int n) { build(n); }

  int size() { return n; }

  template <typename F>
  FastSet(int n, F f) {
    build(n, f);
  }

  void build(int m) {
    seg.clear();
    n = m;
    do {
      seg.push_back(vc<u64>((m + B - 1) / B));
      m = (m + B - 1) / B;
    } while (m > 1);
    log = len(seg);
  }
  template <typename F>
  void build(int n, F f) {
    build(n);
    FOR(i, n) { seg[0][i / B] |= u64(f(i)) << (i % B); }
    FOR(h, log - 1) {
      FOR(i, len(seg[h])) {
        seg[h + 1][i / B] |= u64(bool(seg[h][i])) << (i % B);
      }
    }
  }

  bool operator[](int i) const { return seg[0][i / B] >> (i % B) & 1; }
  void insert(int i) {
    for (int h = 0; h < log; h++) {
      seg[h][i / B] |= u64(1) << (i % B), i /= B;
    
  }
  for (auto& x: ANS) print(x);
}

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

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3760kb

input:

4 12
0 1
1 2
-1 3
2 2
0 1
0 2
0 3
0 4
1 1
1 2
1 3
1 4
2 1
2 2
2 3
2 4

output:

0
1
-1
2
1
0
0
1
0
1
1
0

result:

ok 12 lines

Test #2:

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

input:

5 5
-4 5
-1 3
5 5
0 4
-4 2
0 3
3 1
5 5
1 3
3 3

output:

5
-1
1
4
2

result:

ok 5 lines

Test #3:

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

input:

5 5
3 2
1 3
0 3
1 5
0 5
7 1
1 4
1 5
8 5
10 3

output:

0
0
1
0
0

result:

ok 5 lines

Test #4:

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

input:

5 5
-3 2
-2 1
5 3
0 1
1 5
10 5
3 1
1 3
2 3
8 4

output:

1
0
4
3
0

result:

ok 5 lines

Test #5:

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

input:

5 5
0 5
-3 1
-2 5
-5 2
-3 4
6 1
7 3
2 3
6 1
8 1

output:

-2
-3
-2
-2
-2

result:

ok 5 lines

Test #6:

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

input:

5 5
-1 1
-8 4
0 2
4 3
5 1
1 3
10 5
4 4
4 1
9 4

output:

-1
-1
0
-1
-1

result:

ok 5 lines

Test #7:

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

input:

4 4
-5 4
1 0
2 3
-1 -2
1 1
1 3
0 1
9 2

output:

-4
1
-5
-2

result:

ok 4 lines

Test #8:

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

input:

4 4
-7 -2
10 1
9 2
-10 3
11 3
4 3
0 1
20 4

output:

0
6
-7
0

result:

ok 4 lines

Test #9:

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

input:

100 1000
4 77
6 -9
3 -9
6 0
-5 44
-1 -47
-2 -77
10 71
-3 -18
-10 78
-2 41
-3 18
-1 -46
-1 26
8 -72
-8 69
6 71
-5 -9
-3 6
8 64
-5 66
-2 -73
-4 49
-9 -10
2 74
10 65
9 68
10 15
6 -11
5 -18
-10 -79
9 -27
5 52
3 -71
-2 -77
9 -70
9 -30
9 66
9 8
-1 -7
7 67
-6 -17
-6 -8
-3 20
-10 75
7 41
6 -61
1 5
-5 66
-8 ...

output:

6
6
6
5
6
5
6
5
5
6
5
5
6
5
5
5
5
6
6
6
-1
5
2
5
6
6
6
5
7
5
6
6
5
6
6
6
5
5
5
5
6
5
5
6
5
6
6
5
5
5
5
8
6
6
5
5
5
5
5
5
3
5
6
6
6
5
6
6
6
8
6
5
6
-5
5
5
4
6
6
5
5
6
6
5
6
6
6
6
6
6
5
6
5
6
5
5
6
5
6
6
5
5
5
5
6
5
6
6
7
5
6
5
6
6
5
5
5
5
5
5
6
5
5
6
6
5
5
6
6
5
6
5
6
6
5
6
6
5
6
2
6
5
5
5
5
6
5
5
6
...

result:

ok 1000 lines

Test #10:

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

input:

5 50
-1 -4
1 4
-2 0
0 3
-2 3
13 3
13 2
6 4
4 1
15 4
0 5
7 4
11 2
1 1
2 1
7 1
6 1
2 4
14 2
3 3
4 1
14 4
3 1
10 3
0 3
2 1
14 3
6 3
8 5
11 5
11 3
7 5
9 2
6 5
7 4
8 3
15 3
0 4
15 1
6 5
9 2
6 4
1 5
0 3
2 4
6 4
9 5
0 1
8 1
11 1
5 2
6 2
8 4
3 5
0 3

output:

0
0
0
0
0
-2
0
0
0
0
0
0
0
0
0
0
0
0
0
-2
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
-1
-2
0
0
0
-1
0
0
0
0
0
0
-2

result:

ok 50 lines

Test #11:

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

input:

1000 1000
-631 10
954 2
-663 -9
996 4
479 9
160 -7
-479 -8
540 6
729 1
-280 10
-567 2
572 0
587 1
-592 2
806 3
-84 -9
-117 3
-958 1
-147 -4
-870 -3
44 4
709 -4
-889 10
263 1
-590 7
-242 -1
483 -7
79 -8
59 -7
-618 9
860 -9
110 -2
735 4
-797 -5
362 1
-357 -1
-54 -1
-381 5
-907 -3
-275 -8
798 -7
-150 -...

output:

-1011
-108
-1010
-666
1355
-375
-540
-100
1154
-178
754
-598
-1112
-1135
-509
6
-353
-57
-395
-1080
-555
974
-335
706
366
-37
-1250
-557
-1338
1466
-969
18
-512
-851
-1057
-926
-602
-513
-1403
1267
1121
-358
224
-675
-530
-250
-1206
-1292
102
1437
-697
-891
981
267
-75
-63
-589
1417
-89
-489
-845
34...

result:

ok 1000 lines

Test #12:

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

input:

1 1
-1000000000 -1000000000
1000000000 1

output:

-1000000000

result:

ok single line: '-1000000000'

Test #13:

score: 0
Accepted
time: 16ms
memory: 9268kb

input:

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

output:

2
4
11
6
9
10
5
12
7
8
1
5
10
0
9
-10
4
5
11
12
-3
10
-9
2
-5
14
13
2
10
14
8
-8
-9
9
7
-9
7
14
4
11
1
3
4
5
2
4
-7
-8
9
-6
14
3
9
6
10
7
6
4
-10
-4
6
5
8
12
11
12
5
9
3
5
4
2
-6
-5
2
10
0
13
4
13
0
7
9
6
14
-2
9
7
0
-5
9
10
1
-6
-12
4
5
2
10
8
5
-7
-4
12
2
5
0
3
1
10
5
3
10
4
7
7
14
10
10
8
4
-8
0
...

result:

ok 100000 lines

Test #14:

score: 0
Accepted
time: 19ms
memory: 9436kb

input:

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

output:

-10
10
-10
6
10
12
-3
-5
15
12
11
8
9
-3
-8
-5
-9
1
-11
-3
-4
-10
-6
-2
-5
-6
-7
-5
0
0
-5
-9
-2
-10
9
15
-3
8
-5
-7
-7
-12
8
-7
14
-2
-8
0
3
-6
8
-6
-5
-2
-5
-2
-8
-3
-7
-4
-3
3
-5
-10
-10
1
-4
13
11
-9
-10
-3
-2
15
1
-5
-12
15
9
8
-9
-3
0
12
-10
9
-2
-2
-11
-7
-6
-2
-11
-5
-3
6
14
-9
5
10
-10
-11
...

result:

ok 100000 lines

Test #15:

score: 0
Accepted
time: 20ms
memory: 11048kb

input:

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

output:

-7
-7
-5
-1
-6
3
-7
-1
-1
-3
-3
-5
-1
-4
4
0
-9
-1
-7
-2
0
-4
3
-1
-3
0
-7
-7
-3
4
-7
3
1
0
-4
1
-5
2
-5
-1
4
-1
-6
-9
4
1
3
-4
3
-5
-3
-7
-1
-7
0
-6
-4
2
-3
-2
-6
2
-6
0
-2
-2
-2
1
-1
-1
-1
-2
3
-9
-1
-4
-6
-2
-8
-5
-5
3
-4
0
1
-3
-3
-7
2
-2
-3
-2
-6
-6
-3
3
-3
3
2
-9
-4
-9
-7
-2
1
-6
-2
-4
-5
0
-4...

result:

ok 100000 lines

Test #16:

score: 0
Accepted
time: 12ms
memory: 10172kb

input:

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

output:

6
11
9
10
8
4
-1
2
7
7
3
3
0
2
3
13
11
11
7
2
7
10
7
2
1
5
14
0
5
1
5
3
7
9
-1
3
1
11
10
6
4
8
3
6
14
10
4
1
12
7
-1
0
8
13
6
7
10
5
11
4
4
5
2
5
6
5
6
2
4
6
0
3
8
6
12
4
7
4
-1
11
6
7
2
2
7
2
7
8
8
11
6
4
10
2
7
3
5
3
2
6
6
11
13
0
3
14
6
5
6
11
8
7
2
2
1
6
5
14
8
0
2
2
4
5
7
9
3
9
5
12
9
9
2
3
0
3...

result:

ok 100000 lines

Test #17:

score: 0
Accepted
time: 16ms
memory: 10008kb

input:

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

output:

1
-1
4
4
3
2
4
4
6
7
2
9
3
6
8
2
7
4
6
9
1
8
6
0
0
9
3
6
5
7
2
4
-2
1
3
7
8
7
7
7
7
5
6
6
7
2
7
2
7
3
8
7
-1
7
6
6
8
2
4
6
2
6
6
4
8
6
7
0
0
2
1
1
4
1
0
2
2
8
8
2
1
4
2
7
7
2
0
4
4
1
3
1
2
6
8
2
3
8
6
2
9
3
1
9
9
1
7
7
-1
6
4
7
7
7
0
2
0
7
8
6
2
3
7
2
0
9
7
2
0
3
-2
3
9
3
0
5
3
6
2
4
2
0
7
0
2
8
5
7...

result:

ok 100000 lines

Test #18:

score: 0
Accepted
time: 17ms
memory: 10552kb

input:

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

output:

-2
1
1
0
1
-1
4
0
-2
0
1
0
0
0
5
1
1
0
1
2
-1
4
5
2
0
-2
5
0
2
3
2
1
4
2
3
1
1
3
-5
2
5
2
1
0
2
1
2
2
0
-2
2
1
6
4
6
1
-1
5
2
1
3
2
0
1
4
-1
-1
0
2
4
0
1
-1
1
3
2
6
0
2
0
3
1
4
1
5
4
1
3
1
3
0
5
2
2
3
-2
4
1
-1
5
0
0
2
-4
5
1
-2
2
5
3
3
-2
1
4
5
3
-4
1
-5
-3
0
0
0
-1
3
-3
3
1
1
1
0
-3
4
-1
2
3
2
3
3...

result:

ok 100000 lines

Test #19:

score: 0
Accepted
time: 20ms
memory: 11000kb

input:

5 100000
-5 5
3 1
-1 0
-4 -1
3 0
722464463 3
160153265 3
515887073 3
792161740 3
700363144 1
257871163 4
985882098 5
622391595 3
497814648 5
257689210 3
424536396 2
57303421 2
893685148 3
887126381 5
92312757 3
909180665 3
90045475 3
843939343 2
921025750 1
551022351 1
316367770 3
939526319 1
745326...

output:

-2
-2
-2
-1
-2
-1
-1
-2
-1
-1
-1
-2
-1
-2
-2
-2
-2
-2
-2
-1
-1
-1
-2
-1
-2
-2
-1
-2
-2
-1
-2
-2
-2
-2
-1
-1
-2
-2
-2
-1
-1
-2
-2
-2
-1
-1
-2
-2
-2
-1
-2
-1
-1
-2
-2
-1
-2
-2
-2
-2
-1
-1
-2
-2
-2
-2
-2
-1
-1
-1
-2
-2
-1
-1
-2
-1
-1
-1
-2
-1
-1
-1
-2
-2
-1
-1
-2
-1
-1
-1
-1
-2
-2
-2
-2
-2
-1
-1
-2
-2
...

result:

ok 100000 lines

Test #20:

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

input:

10 100000
0 -4
2 1
4 -3
-4 6
8 -7
-9 0
10 5
3 4
-8 3
-4 6
1 2
1 3
11 7
1 10
6 5
10 2
14 10
17 3
12 1
14 2
11 4
6 3
7 10
16 5
20 10
5 9
12 6
6 1
16 3
13 2
6 2
15 3
14 2
8 10
4 2
7 9
14 6
6 10
12 6
20 8
6 6
11 3
18 8
8 9
13 1
10 10
12 8
20 5
5 6
14 6
10 4
6 6
0 8
0 3
13 8
8 8
7 1
17 1
8 10
4 9
19 2
19...

output:

1
3
-1
-5
2
-8
-18
-13
-12
-12
-15
-2
-11
-8
-24
-9
-15
-6
-12
-11
-4
-11
-12
-12
-2
-11
-17
-10
-15
-17
-9
-7
-15
-12
-13
-14
-9
-12
-8
-17
-14
-9
3
4
-10
-5
-7
-17
-12
-8
-17
-23
-14
-18
-12
-5
-14
-17
-22
2
-16
3
-13
-9
10
-18
1
-7
-17
8
-19
-14
-11
-12
-18
-3
-14
-11
2
-4
7
-17
-4
-13
-13
-14
-1...

result:

ok 100000 lines

Test #21:

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

input:

10 100000
-3 -8
-8 -8
-7 10
3 -5
1 9
6 1
-2 10
10 5
-3 5
-1 -2
6 3
15 4
13 5
12 8
0 9
0 8
17 6
16 3
15 9
19 10
10 1
4 1
16 5
18 7
7 4
13 1
13 7
17 10
19 4
12 5
19 6
20 2
10 1
20 7
8 6
2 5
5 6
0 1
13 6
20 1
2 1
11 10
17 1
12 7
10 9
1 5
18 6
6 4
11 8
17 7
2 8
16 6
1 8
4 7
15 2
0 6
5 3
1 2
12 7
6 7
8 7...

output:

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

result:

ok 100000 lines

Test #22:

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

input:

10 100000
-7 4
-1 6
-5 -5
10 -1
-10 2
-7 -5
-10 7
6 5
-5 -9
-6 -6
20 1
6 3
18 1
17 1
18 9
14 4
15 2
5 4
1 8
7 4
3 1
8 10
0 5
9 7
5 5
11 3
0 7
19 4
2 9
5 1
5 7
4 2
15 7
6 1
7 10
18 5
1 8
11 6
14 9
19 5
14 1
17 8
18 7
4 3
13 8
17 7
12 7
9 8
18 5
0 2
7 2
0 7
5 8
12 6
9 7
4 1
20 4
7 3
9 3
0 3
17 3
20 4
...

output:

-27
1
-25
-24
13
24
14
15
7
17
-10
-14
-10
-19
-15
6
-10
29
-3
-12
-15
3
-25
-13
-13
-28
7
-18
9
-29
-21
23
-28
-1
19
-27
-22
15
-28
-1
6
-10
11
-19
-19
-11
30
2
4
-5
12
30
-8
-23
-9
-1
29
-22
5
17
-29
-15
-12
-14
28
6
23
15
15
9
7
3
-21
-7
-23
-24
-16
26
16
-15
7
1
7
-20
10
-7
6
-23
20
21
-13
-14
-...

result:

ok 100000 lines

Test #23:

score: 0
Accepted
time: 13ms
memory: 10064kb

input:

10 100000
10 0
-5 10
-4 -6
7 3
-7 -9
-4 -7
-10 10
-7 -4
0 8
10 -2
20 9
5 7
19 3
5 6
7 9
14 3
9 5
15 2
1 9
19 1
9 4
7 4
19 3
12 1
20 9
12 6
20 7
4 1
10 2
6 5
20 10
5 4
2 2
13 8
19 8
9 8
1 5
12 6
15 6
5 1
0 5
20 1
3 5
4 6
16 7
8 10
13 6
13 3
18 7
0 10
16 6
18 10
17 10
17 5
12 8
15 6
1 2
17 4
17 10
12 ...

output:

20
-15
15
1
7
10
-16
-20
1
19
8
6
15
12
20
8
-30
6
-15
-13
20
4
-7
-20
-26
-16
-8
8
11
5
-7
20
-10
0
-26
8
9
9
-28
10
12
18
17
-24
-19
11
-6
16
17
12
-14
9
6
-23
5
-15
13
13
6
-15
16
18
14
8
-17
7
-29
13
11
5
-20
8
10
9
-9
2
1
4
7
10
-1
7
-12
-14
13
8
-15
3
-11
14
4
18
-10
-16
20
-19
10
-22
-13
10
2...

result:

ok 100000 lines

Test #24:

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

input:

10 100000
2 -9
3 -10
10 5
-4 7
3 10
8 7
0 7
-7 8
9 -6
9 7
0 5
18 6
16 2
10 7
13 6
2 7
3 1
20 8
9 4
11 8
2 4
11 9
17 6
3 1
18 10
6 2
2 6
2 5
13 3
3 10
7 9
11 8
10 1
16 8
18 4
17 2
18 7
14 6
12 3
12 9
4 1
1 9
1 9
17 6
18 3
20 2
18 3
3 7
4 2
8 4
13 10
2 5
12 10
5 6
7 4
15 1
3 3
2 7
18 2
15 6
10 3
5 7
1...

output:

3
0
0
0
-1
-2
-1
-1
-1
0
-2
0
-1
-1
-1
2
6
3
-1
6
2
0
0
-1
0
-1
0
0
0
-1
-2
8
8
-1
0
0
0
-3
3
0
0
3
-1
3
-1
-1
7
-2
0
-1
0
-3
-1
0
-1
-1
-1
0
-1
-1
0
3
0
3
0
-1
2
-1
9
8
0
-1
-1
-3
0
-1
0
-7
0
0
0
0
0
1
0
-1
-1
-1
0
-1
-1
0
-1
-3
-1
0
3
0
-1
0
-4
0
0
9
0
0
3
-1
-1
-4
-1
1
5
-1
4
-1
-1
3
-3
0
-3
0
0
...

result:

ok 100000 lines

Test #25:

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

input:

10 100000
-2 -1
2 -5
-10 8
-6 7
-7 3
-9 -8
-8 -8
-7 -1
-10 10
5 3
9 6
9 1
0 2
15 10
6 6
19 1
1 3
13 10
9 9
2 6
7 9
15 7
1 6
6 1
20 5
12 10
5 10
8 9
17 8
0 6
18 6
16 10
6 7
15 10
17 8
16 8
18 9
11 6
9 6
11 4
11 7
4 3
3 1
13 3
17 6
11 3
19 4
6 5
3 3
4 10
18 6
7 8
12 2
5 5
9 5
18 5
1 10
16 2
19 5
13 6
...

output:

-18
-11
2
-10
-15
-21
-11
-8
-19
-11
-17
-23
-10
-8
-25
-7
0
-18
-22
-9
-27
-11
-14
-10
-22
-21
-28
-20
-18
-17
-19
-14
-5
-23
-26
-21
-25
-11
-13
1
-27
-12
-10
-10
-14
-23
4
-14
-24
-22
-20
-27
-13
-15
-29
-22
-15
-10
-25
-22
-28
-21
-10
-22
-6
-18
-22
-21
-8
-8
-14
-21
-14
-15
-24
-17
-13
-13
-19
...

result:

ok 100000 lines

Test #26:

score: 0
Accepted
time: 19ms
memory: 10392kb

input:

10 100000
-1 9
7 2
-2 1
3 10
8 10
-6 -3
3 3
9 -7
-1 -2
-7 9
112 7
73 9
118 7
92 9
0 3
189 3
110 10
34 3
105 7
16 9
63 7
12 2
81 9
87 1
160 10
6 5
148 4
54 9
14 5
87 5
57 3
100 4
72 3
166 8
71 7
5 10
189 2
162 3
175 5
73 5
176 8
18 3
24 5
82 9
76 8
199 2
3 6
23 9
49 5
126 2
66 7
45 2
5 7
118 3
48 2
1...

output:

-2
-1
-2
-2
-2
-1
-1
-2
-1
-2
-1
-1
-1
-1
-1
2
-2
-2
-2
-1
-1
-2
-2
-1
-1
-2
-2
-2
-1
-1
-1
-2
-2
-2
-1
-2
-3
-1
-1
-1
-2
-2
-1
-2
-1
-2
-2
-2
-1
-2
-2
-2
0
-2
-2
-1
-1
-2
-1
-1
-1
-2
-1
-1
-2
-2
-1
-1
-1
-1
-2
1
-1
-1
-1
-1
-2
-1
-1
-2
-2
-4
-1
-2
-2
-2
-1
-2
-2
-1
-2
-2
-1
-2
-2
-2
-1
-1
-1
-1
-1
...

result:

ok 100000 lines

Test #27:

score: 0
Accepted
time: 19ms
memory: 9432kb

input:

10 100000
-9 6
1 4
8 8
3 -5
4 -1
-6 0
1 8
-1 -1
-8 1
-1 -4
792434366 4
92102881 1
122696805 2
969313415 10
267007213 3
535748226 6
302806043 1
814393002 2
83864524 7
106160937 2
769231385 3
477853985 5
783986181 2
863038609 10
870475676 4
913155583 1
698243559 5
930099728 6
516688515 8
536420389 1
6...

output:

0
0
-1
-1
-1
0
0
0
0
-1
-1
-1
-1
-1
0
0
-1
0
-1
0
0
-1
0
0
-1
-1
0
-1
-1
0
0
-1
0
-1
0
-1
0
0
0
0
-1
0
-1
0
0
-1
0
0
0
0
0
0
0
0
-1
-1
0
0
0
-1
0
0
0
0
-1
-1
0
-1
0
0
-1
-1
0
0
0
0
-1
-1
0
0
-1
-1
-1
-1
0
-1
0
0
-1
-1
-1
0
0
-1
-1
-1
0
-1
0
0
-1
-1
0
0
-1
-1
-1
-1
0
-1
0
-1
-1
-1
-1
-1
0
0
0
0
0
0
-...

result:

ok 100000 lines

Test #28:

score: 0
Accepted
time: 17ms
memory: 10852kb

input:

100 100000
17 11
-42 -29
58 48
18 48
0 -57
-73 36
41 55
-38 -99
53 -100
-37 -64
-80 4
9 -11
17 99
-94 15
34 -98
34 -61
-45 -10
-47 25
16 -49
16 26
-23 -25
-71 -27
58 -27
-43 46
-12 -36
-70 -85
-76 13
36 56
15 -35
-78 -26
12 -51
-84 97
-63 -23
-93 71
-52 78
47 -29
-58 82
-8 -38
-8 60
23 -50
59 22
-50...

output:

-94
-51
-37
-72
1
-112
2
14
-62
-73
2
-73
-68
-56
-54
-28
-45
-65
-7
-50
-21
21
-40
-96
-80
-73
-108
40
-102
-74
29
-113
-69
-92
-72
78
-58
-14
-37
-77
-28
-93
-54
-13
75
-56
47
-88
62
-56
-10
-69
-115
-123
14
-100
-73
-52
-131
-122
7
-125
-73
-47
-99
-74
-125
-89
-76
44
-54
-85
-98
-74
-106
33
4
-7...

result:

ok 100000 lines

Test #29:

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

input:

100 100000
-1 62
-73 8
49 -3
83 -19
51 55
-28 21
-71 -17
-98 -83
30 -61
23 -88
-17 -78
37 42
85 -50
39 -80
62 -1
-61 -40
-14 73
-95 93
38 -94
86 89
10 91
45 73
79 -58
-3 100
-43 76
88 -74
85 1
-50 -42
71 -34
17 46
-1 -56
35 -59
11 -37
-46 -17
-36 62
41 -93
97 46
45 57
-49 59
-21 -90
-4 98
-80 -48
-5...

output:

-904
-685
-334
-574
-138
-372
7
-346
-864
-769
-966
-424
-79
-937
-677
-497
-885
-131
-263
-742
-448
-604
-843
-949
-768
-843
-680
-263
-655
-612
-471
-801
-839
-752
-22
-977
-90
-876
-77
-671
-781
-819
-884
-165
-382
-147
-402
-875
-514
-164
-174
-59
-932
-742
-709
-659
-435
-171
-410
-795
-906
-76...

result:

ok 100000 lines

Test #30:

score: 0
Accepted
time: 20ms
memory: 9592kb

input:

100 100000
20 35
-27 65
82 -72
43 14
91 41
40 99
20 32
96 -20
-20 -6
34 -81
-88 86
-37 -86
-25 -73
-37 -8
-81 37
-70 1
23 -81
87 -80
39 -33
81 -65
-2 65
99 -10
-38 -53
-80 44
-80 55
-33 31
-72 -40
90 -29
2 47
84 91
-60 -16
83 -100
71 93
12 20
16 3
81 -6
-65 88
-23 -78
53 -90
93 -10
-11 97
59 -60
-29...

output:

-3112
-7720
-8620
-1771
-7662
-4459
-1658
-1272
-9
-9909
-4563
-3582
-1879
-4361
-9807
-458
-2893
-2648
-5421
-380
-4630
-9118
-369
-7526
-2359
-2411
-1830
-2649
-8900
-7570
-1686
-4750
-7341
-7663
-3968
-1601
-3168
-9162
-3410
-2104
-7429
-1523
-3137
-5049
-6979
-1081
-2405
-9672
-4431
-5845
-6515
...

result:

ok 100000 lines

Test #31:

score: 0
Accepted
time: 19ms
memory: 9364kb

input:

100 100000
256155699 -547211095
-774345966 244576889
-489494512 -650843324
-216046407 936858375
-972216842 -994427050
406192309 616950876
69550216 305546853
14578662 -281359711
-183678722 -905559184
-646599996 -891956841
-921646468 677834276
655390404 187442412
-970539166 435720738
-408675181 -56111...

output:

-953694823
538115658
-945311783
-824680761
76415447
500252825
402098669
770070532
733844052
274519145
174329093
-27193765
-524187363
-947840006
-183672912
735929260
13405697
592004500
621473073
365423669
735935490
-913441540
-972219436
76415666
14582949
202399400
-278533900
41417664
149168518
621479...

result:

ok 100000 lines

Test #32:

score: 0
Accepted
time: 16ms
memory: 10684kb

input:

100 100000
744617759 158238326
340923698 -360072198
-991138470 -529277242
-199896385 -586829407
-148984877 -310206000
570899918 -740737853
-132209688 157071629
791203118 -821670121
204761796 679231292
900497734 395825676
63231449 -962828753
-648556788 -838850790
-767269417 -825933974
771859635 26616...

output:

-48307732
-607353993
951677097
483017978
955397673
-226366120
-226322194
-254790396
428396155
-21220357
771912311
-362170287
-199939924
173528991
-767251116
-563620453
340824963
568153528
-7081793
474455145
568202413
794156188
-132239964
433713221
-101885848
765688146
-900892201
89197107
63266605
-7...

result:

ok 100000 lines

Test #33:

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

input:

1000 100000
-434707201 -683661427
384781359 195621116
-951981420 781679258
-376074812 -581864278
428495470 482257122
-485361571 -231980232
318018358 546654220
755178326 -379948948
846857455 396009876
884142897 612544667
-830021241 124329110
-341821805 994936687
942683906 461913370
486906068 10143728...

output:

593580392
707881878
112696715
994093392
621249962
-273575528
72993016
881726697
348571700
-949352699
253246269
-120196549
400932945
-102612996
-190241830
549794901
-692235959
-881736891
800235674
975401539
-448302720
865442554
773904010
-995352295
-784611782
965589306
552963158
569880354
379631471
2...

result:

ok 100000 lines

Test #34:

score: 0
Accepted
time: 17ms
memory: 11352kb

input:

1000 100000
996999716 -34234903
400525215 -674912568
-55411236 222777222
-981748676 -408580972
-796406973 653686899
776754580 -948838675
9273709 955106065
554774087 449419555
-546907422 -190859901
-215040542 638122164
-967305902 64747929
-838776191 -11517133
425018184 -75393651
-268162808 533689787
...

output:

189789496
-757817007
-823093232
688388823
-327622928
526922189
-77145252
-125098514
759496
526926500
318655834
812773016
-604515294
-242449662
-788823122
507921972
-302596104
94285007
-992017072
880319426
569135406
144925975
456639566
626188103
463369829
456638677
-414922995
972068551
803213522
1250...

result:

ok 100000 lines

Test #35:

score: 0
Accepted
time: 25ms
memory: 11116kb

input:

10000 100000
451772880 -156086078
-950254772 927910017
891939666 -469915736
-860487758 -532719735
-567623395 -579566135
-482938321 -174746207
-72418614 609693111
530736894 468835873
-237259199 627247518
-995730942 -804582695
365316524 882959515
-808769910 -179962205
361830722 622888461
-48319332 235...

output:

-204527960
-378903070
62255589
852825025
-346701865
-950657488
490542991
534306652
483988290
-413237666
870710952
-210226764
635171030
935727328
-882351403
758421787
73536360
-586412042
814007077
470300624
-26222194
505354794
517257442
-741767895
-367426807
890150064
-982242426
117830210
58830549
-8...

result:

ok 100000 lines

Test #36:

score: 0
Accepted
time: 20ms
memory: 10312kb

input:

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

output:

-73385393
-61734787
93333112
-61522813
-10397170
-26327062
17805567
-2799682
-23095102
-8937987
-28735369
-68867844
1972248
-3874404
-75612832
-17194657
-13848421
-24694779
-66719951
-61793164
-70026215
-42159667
-21987872
-63862344
11806371
-70847717
-34510812
-46274918
-90589299
-95205712
-5779112...

result:

ok 100000 lines

Test #37:

score: 0
Accepted
time: 23ms
memory: 11264kb

input:

100000 100000
9 944359534
-2 277227375
8 -773149008
8 628295871
-4 -821907488
-2 -188575447
-1 -929530780
0 448989146
-4 -581847871
-7 846839738
5 628096431
1 775236356
-3 -185562343
-4 -939766393
5 694969897
-4 -864927003
-10 -841934125
-9 114196285
3 323366808
-9 471555976
-3 -504782745
1 65348899...

output:

270365985
150639067
468932042
297078804
891055722
924219699
574873537
677775650
144747048
681510473
309408490
35892574
380081715
825222137
581732087
196491670
496169337
355766126
636839475
576364386
758553411
517150283
608493572
854896692
613406885
434294076
922734082
224861074
380454645
688705341
2...

result:

ok 100000 lines

Test #38:

score: 0
Accepted
time: 95ms
memory: 21708kb

input:

100000 100000
-296460011 10
-748228463 8
549227188 -8
-925202056 -7
727222945 5
592939595 -6
765262067 -1
921188558 6
-199556343 9
-574817362 9
400002615 6
993984094 -7
-330466551 3
300272045 -6
-927024342 -4
-221508167 -1
85469524 -4
-442213879 5
792956663 -7
-575779456 9
604558700 -5
167721540 1
1...

output:

370620588
-545525120
387172159
670115019
585735755
287704138
53028116
9642178
-211245561
1456658287
-322635261
-351902818
96039327
805676105
-567177214
278707631
714181356
444120673
252621303
-437049384
261986564
302566305
-647736226
138843881
253990398
246744171
-291147172
692033774
458097866
10673...

result:

ok 100000 lines

Test #39:

score: 0
Accepted
time: 78ms
memory: 20948kb

input:

100000 100000
287158494 468569126
-759400102 479005436
9224200 735737370
-487094525 -916754661
-265725415 783847922
-818680615 702961624
301159712 456986386
344500159 -872939691
514917964 8167047
284680414 566451471
798924115 -38002837
883338728 400769685
-928436385 -562274014
-674132864 -190980349
...

output:

384260027
49361637
-152243459
-701996119
667652795
-501974523
-677823543
255037091
-512142999
848348378
-851177420
-739215099
597152867
-599402744
-690554903
-642244581
-689246874
-699479610
910898896
-143236942
886222051
-309472552
368428143
872068156
749313753
-972123580
-544636858
-535340081
-141...

result:

ok 100000 lines

Test #40:

score: 0
Accepted
time: 104ms
memory: 21508kb

input:

100000 100000
985616625 -541277150
771121018 987395516
-270410900 36892587
775618538 600376872
-122225248 774531538
235018672 81101323
-784561786 -223741542
707535619 -968131588
243250033 -591634095
317867272 -838122470
972069232 995811670
-603617686 -448042504
384613778 -51856128
850847268 -2908386...

output:

-854371732
-125874157
-153061888
-200474966
-111410975
86542542
-30066692
-886510167
-473441821
863942457
634332711
-716495565
-724979416
-800988904
-714652762
-854713536
-854371732
-354439862
-289326794
-471278590
-845908986
-868231014
-787955078
-863737323
262578856
-179652229
-830214823
258612801...

result:

ok 100000 lines

Test #41:

score: 0
Accepted
time: 108ms
memory: 22392kb

input:

100000 100000
281793987 -612870803
94305086 -560673933
-295513002 799528035
-540335441 368007457
-994148615 168189490
-251380159 -240836148
830551416 845691603
-541708172 -717794559
381479460 -711648554
784442711 170822908
177146652 -482022948
454677247 100446470
-894524326 -830844423
-904411557 -39...

output:

-694183691
716347306
-266930674
-619830251
-229242709
-619830250
614885035
-618882153
523053289
101000147
-440761559
-619830250
23678448
-166300736
-530798241
765868954
112616001
-692052039
263477195
-225469202
-619830251
274394351
247857588
193641799
-184963081
141048961
-619830250
353862996
-61983...

result:

ok 100000 lines

Test #42:

score: 0
Accepted
time: 109ms
memory: 20956kb

input:

100000 100000
-964559972 -631901904
-556990602 104372060
-710718564 -296031182
-25462638 -995192610
955777317 -736021459
-260580311 780254081
983144723 570913802
-618574557 -422386108
72134646 -213699479
-201554602 -191152520
206392799 -364149338
-482916343 -436067881
398429352 -281033237
371966703 ...

output:

-391940170
-395185238
-726862742
-391727352
-804354033
-453109000
-326461200
-397583180
-324954058
-679150595
-440574818
658433392
-807429615
127147486
473775920
-904011405
-442770667
-389454685
-30694191
136370114
-325523457
-508652522
260613730
-691463551
300734981
852354603
-389454685
-326461199
...

result:

ok 100000 lines

Test #43:

score: 0
Accepted
time: 77ms
memory: 20864kb

input:

90000 100000
502039555 209250582
-444359527 -207281547
183192756 -427133907
420664856 -882193463
762643102 -537838960
-849279809 687520501
119720700 -541964994
506112534 -596514223
-715457534 -971620343
-206938912 223190193
-148198813 358949006
-421623706 557259839
-328389604 548595891
313872333 283...

output:

1176623464
-53472874
276900145
765929269
1632953231
179558347
588406739
553515698
1490337553
1327318717
414789821
1493761479
282155259
-4010076
1081909339
-537208912
538722992
655251272
1024472252
1277368747
1019325376
482186049
960089941
187233000
1286786779
257490840
-830385584
882296518
538052297...

result:

ok 100000 lines

Test #44:

score: 0
Accepted
time: 88ms
memory: 21204kb

input:

100000 100000
-223708673 -702436384
-999099108 94338999
547433890 -747491546
-491512453 512628370
487172489 250916656
17381169 -518905532
-816071725 -727403547
-413706036 -825375237
-627842488 813329258
-30209292 -977325756
-772182084 -94715016
368138666 -564899470
-996931517 204195496
-65616765 585...

output:

-13663834
-178736601
-1380798619
-1110041540
-21905975
-76762316
-151401624
-233980355
-1845940849
-1048120327
518361176
-1084916571
39446420
-30025177
-1308604439
-629228031
-142350576
-511576652
-1019318276
-445223616
-1173857268
-1440673231
-1626003031
-1154284639
240183880
487255215
-1247255338
...

result:

ok 100000 lines

Test #45:

score: 0
Accepted
time: 22ms
memory: 9840kb

input:

900 100000
-602 -865
985 -313
737 -886
87 708
356 -809
-455 -912
-414 661
253 -172
-164 -801
-556 -58
-644 112
-20 -881
908 -850
-115 284
-575 -88
940 -444
594 -812
-445 -35
-899 -895
258 -20
18 416
-102 -288
-442 -652
953 -569
-94 886
11 -594
-139 590
-658 900
-641 975
70 258
-329 788
3 225
5 -143
...

output:

120
-32
241
-680
440
-32
235
366
-499
68
23
-277
234
207
565
-89
-460
-45
460
723
144
-90
173
-674
27
-27
-55
-31
94
471
-9
88
-718
376
293
514
59
404
-14
623
364
398
75
-965
-24
-224
661
-686
311
-99
-27
349
-212
47
371
-690
59
416
130
400
253
-318
228
91
-470
341
683
-707
-19
-710
561
122
603
-637...

result:

ok 100000 lines

Test #46:

score: 0
Accepted
time: 18ms
memory: 10492kb

input:

1000 100000
-147 -416
-393 -50
470 -275
-920 805
798 853
-273 795
784 281
-9 -793
706 34
-631 894
28 549
-388 565
849 -899
-250 471
105 696
170 371
299 715
269 -645
-252 -226
544 -649
76 -374
397 -854
-278 177
-530 -277
-313 503
-456 202
-210 313
410 148
-347 -667
-120 -624
-566 -210
-716 654
386 64...

output:

809
-68
-911
-498
-894
-1335
57
-1185
-616
-1324
-1375
227
-947
461
23
183
393
45
-482
-369
-117
-315
576
-874
-653
-853
-926
770
867
-822
21
-894
-886
-340
-121
-1021
-466
-635
-877
-732
126
518
-426
-546
19
528
151
-158
-648
-981
-339
-309
-852
-1146
608
-1308
-1072
-893
-37
-893
866
-662
236
274
...

result:

ok 100000 lines

Test #47:

score: 0
Accepted
time: 95ms
memory: 21572kb

input:

100000 100000
684285263 180693552
-76651999 -389372051
-879653508 -600952017
798704427 -701919940
119579671 587756508
-100296843 989620333
-375844363 -416164963
-142330586 990249737
-493174522 233907575
-755521469 -759992701
859433612 714920235
65299679 -683945454
908759410 226316242
152628828 68588...

output:

796427657
-459852712
2608939
-434662153
-651517920
-601190660
158135757
-105677886
150644341
708124645
-472642872
-85948007
-670598191
-392539579
-720655083
665353614
207543916
75037639
-726705773
658299085
-470716490
53070040
-438588313
-443249386
-683902173
-558221341
476337853
459554132
30339712
...

result:

ok 100000 lines

Test #48:

score: 0
Accepted
time: 78ms
memory: 21764kb

input:

99999 100000
156564462 -488302017
-192132388 -362924118
-446104520 -47498133
-756801924 788641462
-705663686 -999252477
434250146 -955439930
954104475 887694624
436960796 -33940367
-961465996 -868280920
217211828 -18156408
-390052345 69195580
884522238 -458089095
-629069058 814705359
318873791 80893...

output:

1895093517
491521999
-149691771
1177388558
1225193236
-170179336
422730954
1337161463
943278887
418179247
976560270
406203878
552277996
1230158954
862086233
1051085860
1124975386
-147602701
985193481
-1089799514
1074416516
1455846568
198589516
156749190
810271173
486890710
601669110
-237452110
35106...

result:

ok 100000 lines

Test #49:

score: 0
Accepted
time: 49ms
memory: 13632kb

input:

99999 100000
-707756108 -705222327
-1000000000 -1000000000
782307502 863535856
-1000000000 -719445671
-1000000000 -1000000000
1000000000 -1000000000
-1000000000 1000000000
-1000000000 -452829800
-1000000000 -1000000000
383838661 -799003184
-1000000000 206564145
1000000000 -456774190
1000000000 -8813...

output:

-999999948
893056897
0
-716370228
-857684759
999999996
893056896
893056897
408251374
0
0
467889305
-5580799
893056897
999999900
893056896
999999921
-507566263
893056896
0
893056896
18711302
893056897
893056896
-67068219
893056897
999999996
0
-835092468
0
893056897
-999999973
893056897
305963537
1090...

result:

ok 100000 lines

Test #50:

score: 0
Accepted
time: 47ms
memory: 15056kb

input:

100000 100000
-1000000000 1000000000
-1000000000 -1000000000
-1000000000 447417896
155258565 -163472790
-733343196 -1000000000
1000000000 1000000000
-1000000000 -470712138
735386345 -1000000000
-1000000000 1000000000
1000000000 122168718
1000000000 -1000000000
477285556 1000000000
1000000000 9296782...

output:

2000000000
2000000000
2000000000
14720687
316566133
555859268
-2000000000
-1490351667
1000000002
1000000058
2000000000
2000000000
-1230559944
1755759823
1000000034
2000000000
-1000000085
-253599633
-1000000002
1000000059
1737139234
-1000000046
1000000081
-1705827307
1000000007
1558032321
1000000099
...

result:

ok 100000 lines

Extra Test:

score: 0
Extra Test Passed