QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#399991#3299. Advertisement Matchinghos_lyricWA 166ms27332kbC++1410.1kb2024-04-26 20:44:032024-04-26 20:44:04

Judging History

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

  • [2024-04-26 20:44:04]
  • 评测
  • 测评结果:WA
  • 用时:166ms
  • 内存:27332kb
  • [2024-04-26 20:44:03]
  • 提交

answer

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")


// T: monoid representing information of an interval.
//   T()  should return the identity.
//   T(S s)  should represent a single element of the array.
//   T::push(T &l, T &r)  should push the lazy update.
//   T::pull(const T &l, const T &r)  should pull two intervals.
template <class T> struct SegmentTreeRange {
  int logN, n;
  vector<T> ts;
  SegmentTreeRange() : logN(0), n(0) {}
  explicit SegmentTreeRange(int n_) {
    for (logN = 0, n = 1; n < n_; ++logN, n <<= 1) {}
    ts.resize(n << 1);
  }
  template <class S> explicit SegmentTreeRange(const vector<S> &ss) {
    const int n_ = ss.size();
    for (logN = 0, n = 1; n < n_; ++logN, n <<= 1) {}
    ts.resize(n << 1);
    for (int i = 0; i < n_; ++i) at(i) = T(ss[i]);
    build();
  }
  T &at(int i) {
    return ts[n + i];
  }
  void build() {
    for (int u = n; --u; ) pull(u);
  }

  inline void push(int u) {
    ts[u].push(ts[u << 1], ts[u << 1 | 1]);
  }
  inline void pull(int u) {
    ts[u].pull(ts[u << 1], ts[u << 1 | 1]);
  }

  // Applies T::f(args...) to [a, b).
  template <class F, class... Args>
  void ch(int a, int b, F f, Args &&... args) {
    assert(0 <= a); assert(a <= b); assert(b <= n);
    if (a == b) return;
    a += n; b += n;
    for (int h = logN; h; --h) {
      const int aa = a >> h, bb = b >> h;
      if (aa == bb) {
        if ((aa << h) != a || (bb << h) != b) push(aa);
      } else {
        if ((aa << h) != a) push(aa);
        if ((bb << h) != b) push(bb);
      }
    }
    for (int aa = a, bb = b; aa < bb; aa >>= 1, bb >>= 1) {
      if (aa & 1) (ts[aa++].*f)(args...);
      if (bb & 1) (ts[--bb].*f)(args...);
    }
    for (int h = 1; h <= logN; ++h) {
      const int aa = a >> h, bb = b >> h;
      if (aa == bb) {
        if ((aa << h) != a || (bb << h) != b) pull(aa);
      } else {
        if ((aa << h) != a) pull(aa);
        if ((bb << h) != b) pull(bb);
      }
    }
  }

  // Calculates the product for [a, b).
  T get(int a, int b) {
    assert(0 <= a); assert(a <= b); assert(b <= n);
    if (a == b) return T();
    a += n; b += n;
    for (int h = logN; h; --h) {
      const int aa = a >> h, bb = b >> h;
      if (aa == bb) {
        if ((aa << h) != a || (bb << h) != b) push(aa);
      } else {
        if ((aa << h) != a) push(aa);
        if ((bb << h) != b) push(bb);
      }
    }
    T prodL, prodR, t;
    for (int aa = a, bb = b; aa < bb; aa >>= 1, bb >>= 1) {
      if (aa & 1) { t.pull(prodL, ts[aa++]); prodL = t; }
      if (bb & 1) { t.pull(ts[--bb], prodR); prodR = t; }
    }
    t.pull(prodL, prodR);
    return t;
  }

  // Calculates T::f(args...) of a monoid type for [a, b).
  //   op(-, -)  should calculate the product.
  //   e()  should return the identity.
  template <class Op, class E, class F, class... Args>
#if __cplusplus >= 201402L
  auto
#else
  decltype((std::declval<T>().*F())())
#endif
  get(int a, int b, Op op, E e, F f, Args &&... args) {
    assert(0 <= a); assert(a <= b); assert(b <= n);
    if (a == b) return e();
    a += n; b += n;
    for (int h = logN; h; --h) {
      const int aa = a >> h, bb = b >> h;
      if (aa == bb) {
        if ((aa << h) != a || (bb << h) != b) push(aa);
      } else {
        if ((aa << h) != a) push(aa);
        if ((bb << h) != b) push(bb);
      }
    }
    auto prodL = e(), prodR = e();
    for (int aa = a, bb = b; aa < bb; aa >>= 1, bb >>= 1) {
      if (aa & 1) prodL = op(prodL, (ts[aa++].*f)(args...));
      if (bb & 1) prodR = op((ts[--bb].*f)(args...), prodR);
    }
    return op(prodL, prodR);
  }

  // Find min b s.t. T::f(args...) returns true,
  // when called for the partition of [a, b) from left to right.
  //   Returns n + 1 if there is no such b.
  template <class F, class... Args>
  int findRight(int a, F f, Args &&... args) {
    assert(0 <= a); assert(a <= n);
    if ((T().*f)(args...)) return a;
    if (a == n) return n + 1;
    a += n;
    for (int h = logN; h; --h) push(a >> h);
    for (; ; a >>= 1) if (a & 1) {
      if ((ts[a].*f)(args...)) {
        for (; a < n; ) {
          push(a);
          if (!(ts[a <<= 1].*f)(args...)) ++a;
        }
        return a - n + 1;
      }
      ++a;
      if (!(a & (a - 1))) return n + 1;
    }
  }

  // Find max a s.t. T::f(args...) returns true,
  // when called for the partition of [a, b) from right to left.
  //   Returns -1 if there is no such a.
  template <class F, class... Args>
  int findLeft(int b, F f, Args &&... args) {
    assert(0 <= b); assert(b <= n);
    if ((T().*f)(args...)) return b;
    if (b == 0) return -1;
    b += n;
    for (int h = logN; h; --h) push((b - 1) >> h);
    for (; ; b >>= 1) if ((b & 1) || b == 2) {
      if ((ts[b - 1].*f)(args...)) {
        for (; b <= n; ) {
          push(b - 1);
          if (!(ts[(b <<= 1) - 1].*f)(args...)) --b;
        }
        return b - n - 1;
      }
      --b;
      if (!(b & (b - 1))) return -1;
    }
  }
};

////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////

constexpr Int INF = 1001001001001001001LL;

struct NodeMin {
  Int mn;
  Int lz;
  NodeMin() : mn(INF), lz(0) {}
  NodeMin(Int val) : mn(val), lz(0) {}
  void push(NodeMin &l, NodeMin &r) {
    if (lz) {
      l.add(lz);
      r.add(lz);
      lz = 0;
    }
  }
  void pull(const NodeMin &l, const NodeMin &r) {
    mn = min(l.mn, r.mn);
  }
  void add(Int val) {
    mn += val;
    lz += val;
  }
  // leaf
  void change(Int val) {
    mn = val;
  }
};

////////////////////////////////////////////////////////////////////////////////


// maintain non-decr. sequence
struct Increasing {
  // values in [0, m)
  int m;
  // value a: position [ls[a], rs[a]]
  vector<int> ls, rs;
  Increasing(int m_, vector<int> as) : m(m_), ls(m, 0), rs(m, -1) {
    sort(as.begin(), as.end());
    for (int i = 0; i < (int)as.size(); ++i) {
      const int a = as[i];
      assert(0 <= a); assert(a < m);
      if (ls[a] <= rs[a]) {
        assert(rs[a] == i - 1);
        rs[a] = i;
      } else {
        ls[a] = rs[a] = i;
      }
    }
  }
  // a -> a+1, where to increase?
  int inc(int a) {
    assert(0 <= a); assert(a + 1 < m);
    assert(ls[a] <= rs[a]);
    const int i = rs[a]--;
    if (ls[a + 1] <= rs[a + 1]) {
      assert(ls[a + 1] == i + 1);
      ls[a + 1] = i;
    } else {
      ls[a + 1] = rs[a + 1] = i;
    }
    return i;
  }
  // a -> a-1, where to increase?
  int dec(int a) {
    assert(0 <= a - 1); assert(a < m);
    const int i = ls[a]++;
    if (ls[a - 1] <= rs[a - 1]) {
      assert(rs[a - 1] == i - 1);
      rs[a - 1] = i;
    } else {
      ls[a - 1] = rs[a - 1] = i;
    }
    return i;
  }
};


/*
  a[0] <= ... <= a[M-1]
  b[0] <= ... <= b[N-1]
  
  mincut
  = \min[0<=m<=M, 0<=n<=N] (m n + \sum a[0, M-m) + \sum b[0, N-n))
  = \min[0<=m<=M] (\sum[0, M-m) + \sum[j] min{m, b[j]})
*/

int M, N;
vector<int> A, B;
int Q;
vector<int> O, C;

int main() {
  for (; ~scanf("%d%d", &M, &N); ) {
    A.resize(M); for (int i = 0; i < M; ++i) scanf("%d", &A[i]);
    B.resize(N); for (int j = 0; j < N; ++j) scanf("%d", &B[j]);
    scanf("%d", &Q);
    O.resize(Q);
    C.resize(Q);
    for (int q = 0; q < Q; ++q) {
      scanf("%d%d", &O[q], &C[q]);
      --C[q];
    }
    
    auto as = A;
    auto bs = B;
    sort(as.begin(), as.end());
    sort(bs.begin(), bs.end());
    Increasing f(*max_element(A.begin(), A.end()) + Q + 1, as);
    
    vector<Int> asSum(M + 1, 0);
    vector<Int> bsSum(N + 1, 0);
    for (int i = 0; i < M; ++i) asSum[i + 1] = asSum[i] + as[i];
    for (int j = 0; j < N; ++j) bsSum[j + 1] = bsSum[j] + bs[j];
    vector<Int> ini(M + 1, 0);
    for (int j = 0, m = 0; m <= M; ++m) {
      for (; j < N && bs[j] < m; ++j) {}
      ini[m] += asSum[M - m];
      ini[m] += bsSum[j];
      ini[m] += (Int)(N - j) * m;
    }
// cerr<<"ini = "<<ini<<endl;
    SegmentTreeRange<NodeMin> seg(ini);
    Int sumA = asSum[M];
    
    for (int q = 0; q < Q; ++q) {
      if (false) {
      } else if (O[q] == 1) {
        const int i = f.inc(A[C[q]]++);
        seg.ch(0, M - i, &NodeMin::add, +1);
        ++sumA;
      } else if (O[q] == 2) {
        const int i = f.dec(A[C[q]]--);
        seg.ch(0, M - i, &NodeMin::add, -1);
        --sumA;
      } else if (O[q] == 3) {
        // min{m, b+1} - min{m, b} = +[m >= b+1]
        int &b = B[C[q]];
        seg.ch(min(max(b + 1, 0), M + 1), M + 1, &NodeMin::add, +1);
        ++b;
      } else if (O[q] == 4) {
        // min{m, b-1} - min{m, b} = -[m >= b]
        int &b = B[C[q]];
        seg.ch(min(max(b, 0), M), M + 1, &NodeMin::add, -1);
        --b;
      } else {
        assert(false);
      }
      const Int mc = seg.ts[1].mn;
// cerr<<"mc = "<<mc<<", sumA = "<<sumA<<endl;
      puts((mc == sumA) ? "1" : "0");
    }
  }
  return 0;
}

詳細信息

Test #1:

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

input:

5 5
1 5 2 4 3
3 3 3 3 3
5
4 2
3 5
2 2
1 1
1 4

output:

0
1
1
1
0

result:

ok 5 lines

Test #2:

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

input:

100 100
13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 1...

output:

1
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

result:

ok 100 lines

Test #3:

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

input:

100 100
42 28 42 64 42 29 72 64 72 29 28 72 28 72 29 42 64 42 72 29 64 29 72 28 42 64 72 64 28 42 72 42 29 64 72 64 72 29 72 29 64 42 64 72 29 28 42 64 72 64 72 28 42 64 64 42 64 64 28 28 72 29 28 64 28 64 64 72 64 28 42 29 64 42 64 42 72 64 64 64 28 64 42 72 64 29 64 29 64 64 72 29 29 28 42 72 64 7...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

result:

ok 100 lines

Test #4:

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

input:

100 100
13 40 46 59 64 64 3 34 64 13 46 13 13 46 46 16 64 48 26 13 59 50 16 46 41 5 59 13 64 16 20 43 41 26 14 16 34 64 59 41 73 71 64 50 14 48 71 50 71 26 43 59 5 50 16 71 77 77 59 14 3 41 71 7 41 40 16 13 50 13 64 64 16 59 40 5 26 50 64 59 3 5 40 41 16 5 13 46 40 14 40 34 40 59 46 14 26 41 43 64
2...

output:

1
0
1
1
0
1
1
1
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

result:

ok 100 lines

Test #5:

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

input:

100 100
69 81 86 84 48 31 42 27 14 18 7 8 61 41 97 9 38 88 24 48 52 92 60 28 18 61 51 64 98 9 72 13 35 97 32 8 17 79 54 5 100 1 76 21 11 12 52 5 98 25 61 37 82 4 18 22 96 10 23 68 92 63 40 25 27 67 39 36 44 82 6 31 17 3 7 90 21 80 62 9 73 26 75 57 20 20 86 35 46 45 89 40 18 43 16 68 4 6 89 75
37 1 7...

output:

0
1
0
1
1
1
1
1
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1

result:

ok 100 lines

Test #6:

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

input:

1000 1000
885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 88...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 1000 lines

Test #7:

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

input:

1000 1000
499 499 499 499 917 670 499 499 947 670 917 670 917 917 917 670 556 556 947 499 670 947 556 670 499 947 556 917 947 499 556 947 556 499 670 947 947 670 947 556 499 917 670 556 556 917 947 499 947 670 947 917 670 917 556 499 670 947 556 947 499 670 947 947 947 917 556 556 670 499 499 917 55...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 1000 lines

Test #8:

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

input:

1000 1000
16 517 918 174 148 253 293 596 438 217 566 362 984 507 690 320 253 144 971 74 157 981 547 802 39 765 264 771 846 745 539 906 743 39 242 266 568 660 118 352 509 278 500 481 929 502 375 315 599 756 217 159 606 39 967 50 145 863 412 7 780 320 745 942 99 52 510 560 184 669 596 50 477 236 7 507...

output:

1
0
1
0
0
0
0
0
0
0
0
0
0
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0
0
1
1
1
1
1
1
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 1000 lines

Test #9:

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

input:

1000 1000
397 930 346 818 646 400 677 961 999 158 382 242 136 712 460 432 622 282 297 428 708 432 100 768 51 140 776 934 479 531 307 542 498 520 961 155 984 664 45 398 831 581 638 130 248 476 88 238 584 959 838 270 574 402 248 267 562 281 839 422 528 729 299 809 562 723 93 102 371 46 173 13 500 313 ...

output:

1
1
1
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 1000 lines

Test #10:

score: 0
Accepted
time: 92ms
memory: 25256kb

input:

250000 250000
505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 50...

output:

0
0
0
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0
0
0
0
0
0
0
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0
0
0
0
1
1
1
1
1
1
1
0
0
0
0
0
0
0
0
0
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 250000 lines

Test #11:

score: 0
Accepted
time: 114ms
memory: 26772kb

input:

250000 250000
95999 84922 84922 84922 84922 192441 95999 95999 84922 84922 157215 95999 95999 84922 84922 192441 84922 157215 95999 95999 84922 134374 134374 95999 157215 157215 157215 134374 95999 95999 192441 84922 157215 95999 134374 134374 157215 84922 84922 157215 157215 192441 157215 192441 84...

output:

1
1
1
1
1
1
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
1
1
1
1
1
1
1
1
1
1
1
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
1
1
0
1
1
0
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0
1
0
1
1
1
1
0
1
1
1
1
1
1
1
1
1
1
1
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 250000 lines

Test #12:

score: 0
Accepted
time: 137ms
memory: 27324kb

input:

250000 250000
99788 19597 214416 180187 1414 91483 52500 39832 44744 117384 101094 44330 184503 249204 182442 215087 202368 195489 68778 87466 14876 52500 236341 26050 150719 22826 132014 132014 87466 215690 124445 63744 164012 1414 1414 196894 108984 176873 117236 101094 104971 110463 245260 101485...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 250000 lines

Test #13:

score: 0
Accepted
time: 142ms
memory: 27332kb

input:

250000 250000
207314 14115 67772 42083 60556 170102 25993 87469 125309 182226 243715 201212 26496 131302 35572 5679 151504 72761 66407 161186 218524 120727 238184 25540 64599 4760 165334 59605 61263 245336 219527 91652 237091 151504 115034 4368 105164 8525 238713 13968 180993 206311 90847 44534 1204...

output:

0
0
0
1
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 250000 lines

Test #14:

score: 0
Accepted
time: 160ms
memory: 27192kb

input:

250000 250000
14327 112510 149249 172456 244333 17060 93928 57392 214370 116572 246841 32517 87710 200594 66590 246391 243518 117926 143081 245815 103748 202364 75105 122767 218060 128187 244 67143 227044 149790 94421 180148 60374 156556 244726 204774 9123 236150 137285 197429 9011 69189 240578 2356...

output:

1
1
1
1
1
0
0
0
0
0
0
1
1
1
1
1
1
1
1
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 250000 lines

Test #15:

score: 0
Accepted
time: 166ms
memory: 27148kb

input:

250000 250000
139218 131913 25366 163211 10536 191335 24644 84025 53163 41124 179606 21347 82566 164463 115824 1486 140585 216771 95244 31155 171492 75126 178871 235554 194463 215297 211487 161690 15011 157166 159066 28176 233330 232492 125808 111488 26058 22638 36784 67543 221751 159152 219274 1877...

output:

1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 250000 lines

Test #16:

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

input:

1 1
1
1
1
1 1

output:

0

result:

ok single line: '0'

Test #17:

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

input:

1 1
1
1
1
2 1

output:

1

result:

ok single line: '1'

Test #18:

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

input:

1 1
1
1
1
4 1

output:

0

result:

ok single line: '0'

Test #19:

score: 0
Accepted
time: 83ms
memory: 27204kb

input:

250000 250000
249200 249213 249963 249574 249640 249386 249147 249871 249696 249463 249438 249855 249810 249025 249100 249838 249860 249316 249667 249439 249803 249645 249738 249011 249658 249365 249774 249126 249098 249481 249650 249051 249281 249876 249384 249462 249883 249244 249898 249129 249843...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 250000 lines

Test #20:

score: 0
Accepted
time: 74ms
memory: 27100kb

input:

250000 250000
249163 249011 249656 249502 249679 249235 249870 249966 249247 249923 249982 249168 249605 249455 249167 249796 249465 249977 249440 249341 249061 249589 249333 249380 249405 249694 249110 249668 249069 249952 249554 249005 249069 249185 249099 249478 249225 249470 249639 249169 249558...

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
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
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 250000 lines

Test #21:

score: 0
Accepted
time: 39ms
memory: 12944kb

input:

1 250000
249201
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 250000 lines

Test #22:

score: 0
Accepted
time: 35ms
memory: 13032kb

input:

1 250000
249784
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
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 250000 lines

Test #23:

score: 0
Accepted
time: 74ms
memory: 23120kb

input:

250000 1
249354 249676 249057 249916 249316 249874 249563 249495 249890 249950 249427 249735 249111 249216 249768 249467 249144 249758 249300 249255 249126 249438 249873 249900 249092 249166 249341 249943 249479 249060 249660 249749 249268 249050 249068 249472 249726 249542 249891 249795 249622 2490...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 250000 lines

Test #24:

score: 0
Accepted
time: 51ms
memory: 23344kb

input:

250000 1
249556 249085 249361 249836 249355 249724 249277 249590 249060 249789 249209 249048 249907 249647 249223 249798 249130 249417 249693 249150 249766 249383 249476 249276 249840 249883 249677 249872 249449 249538 249953 249704 249057 249361 249411 249488 249450 249768 249640 249834 249336 2492...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 250000 lines

Test #25:

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

input:

1 1
249881
1
250000
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 250000 lines

Test #26:

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

input:

1 1
249082
1
250000
3 1
3 1
3 1
3 1
3 1
3 1
3 1
3 1
3 1
3 1
3 1
3 1
3 1
3 1
3 1
3 1
3 1
3 1
3 1
3 1
3 1
3 1
3 1
3 1
3 1
3 1
3 1
3 1
3 1
3 1
3 1
3 1
3 1
3 1
3 1
3 1
3 1
3 1
3 1
3 1
3 1
3 1
3 1
3 1
3 1
3 1
3 1
3 1
3 1
3 1
3 1
3 1
3 1
3 1
3 1
3 1
3 1
3 1
3 1
3 1
3 1
3 1
3 1
3 1
3 1
3 1
3 1
3 1
3 1
3 1
...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 250000 lines

Test #27:

score: 0
Accepted
time: 148ms
memory: 27284kb

input:

250000 250000
212252 134091 189780 80306 24175 50691 86179 209123 154494 188186 213059 198107 221561 159616 80347 185244 56461 193107 13355 232403 173167 32933 34831 12587 51108 125390 30751 35940 142053 152823 133030 121806 17905 130672 196186 200012 85324 39821 48606 41507 29196 216727 158830 1358...

output:

1
1
1
1
0
1
1
1
1
1
1
1
0
1
0
1
1
1
0
1
1
1
0
1
0
1
1
1
1
1
1
1
0
1
0
1
0
1
1
1
1
1
0
1
0
1
1
1
1
1
0
1
0
1
0
1
1
1
1
1
0
1
1
1
1
1
0
1
1
1
1
1
0
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0
1
1
1
1
1
1
1
0
1
1
1
0
1
0
1
1
1
1
1
1
1
1
1
1
1
1
1
0
1
1
1
0
1
0
1
0
1
0
1
1
1
0
1
0
1
0
1
0
1
1
1
1
1
...

result:

ok 250000 lines

Test #28:

score: -100
Wrong Answer
time: 146ms
memory: 27204kb

input:

249999 250000
186583 151769 72875 42334 85090 210147 38370 74934 226668 13332 223141 226855 170872 133011 201588 64987 216615 216111 26538 208243 79411 112763 156751 166214 107011 50835 227417 238363 160383 36962 233073 249048 77075 116954 185530 220543 97988 65293 231513 34271 151615 71125 84145 97...

output:

0
1
0
1
0
1
0
1
0
1
0
1
1
1
1
1
0
1
1
1
0
1
0
1
0
1
1
1
1
1
0
1
1
1
0
1
1
1
0
1
1
1
1
1
1
1
0
1
1
1
0
1
1
1
0
1
0
1
0
1
0
1
0
1
1
1
0
1
0
1
0
1
1
1
0
1
1
1
1
1
1
1
1
1
1
1
0
1
0
1
1
1
0
1
1
1
1
1
1
1
0
1
0
1
0
1
0
1
1
1
0
1
0
1
0
1
1
1
0
1
1
1
0
1
0
1
0
1
1
1
0
1
1
1
0
1
1
1
1
1
0
1
0
1
1
1
0
1
1
1
...

result:

wrong answer 53520th lines differ - expected: '1', found: '0'