QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#116484#4879. Standard Problemhos_lyricAC ✓325ms26808kbC++1411.7kb2023-06-29 13:08:112023-06-29 13:08:14

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-29 13:08:14]
  • 评测
  • 测评结果:AC
  • 用时:325ms
  • 内存:26808kb
  • [2023-06-29 13:08:11]
  • 提交

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 <map>
#include <numeric>
#include <queue>
#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; }


////////////////////////////////////////////////////////////////////////////////
template <unsigned M_> struct ModInt {
  static constexpr unsigned M = M_;
  unsigned x;
  constexpr ModInt() : x(0U) {}
  constexpr ModInt(unsigned x_) : x(x_ % M) {}
  constexpr ModInt(unsigned long long x_) : x(x_ % M) {}
  constexpr ModInt(int x_) : x(((x_ %= static_cast<int>(M)) < 0) ? (x_ + static_cast<int>(M)) : x_) {}
  constexpr ModInt(long long x_) : x(((x_ %= static_cast<long long>(M)) < 0) ? (x_ + static_cast<long long>(M)) : x_) {}
  ModInt &operator+=(const ModInt &a) { x = ((x += a.x) >= M) ? (x - M) : x; return *this; }
  ModInt &operator-=(const ModInt &a) { x = ((x -= a.x) >= M) ? (x + M) : x; return *this; }
  ModInt &operator*=(const ModInt &a) { x = (static_cast<unsigned long long>(x) * a.x) % M; return *this; }
  ModInt &operator/=(const ModInt &a) { return (*this *= a.inv()); }
  ModInt pow(long long e) const {
    if (e < 0) return inv().pow(-e);
    ModInt a = *this, b = 1U; for (; e; e >>= 1) { if (e & 1) b *= a; a *= a; } return b;
  }
  ModInt inv() const {
    unsigned a = M, b = x; int y = 0, z = 1;
    for (; b; ) { const unsigned q = a / b; const unsigned c = a - q * b; a = b; b = c; const int w = y - static_cast<int>(q) * z; y = z; z = w; }
    assert(a == 1U); return ModInt(y);
  }
  ModInt operator+() const { return *this; }
  ModInt operator-() const { ModInt a; a.x = x ? (M - x) : 0U; return a; }
  ModInt operator+(const ModInt &a) const { return (ModInt(*this) += a); }
  ModInt operator-(const ModInt &a) const { return (ModInt(*this) -= a); }
  ModInt operator*(const ModInt &a) const { return (ModInt(*this) *= a); }
  ModInt operator/(const ModInt &a) const { return (ModInt(*this) /= a); }
  template <class T> friend ModInt operator+(T a, const ModInt &b) { return (ModInt(a) += b); }
  template <class T> friend ModInt operator-(T a, const ModInt &b) { return (ModInt(a) -= b); }
  template <class T> friend ModInt operator*(T a, const ModInt &b) { return (ModInt(a) *= b); }
  template <class T> friend ModInt operator/(T a, const ModInt &b) { return (ModInt(a) /= b); }
  explicit operator bool() const { return x; }
  bool operator==(const ModInt &a) const { return (x == a.x); }
  bool operator!=(const ModInt &a) const { return (x != a.x); }
  friend std::ostream &operator<<(std::ostream &os, const ModInt &a) { return os << a.x; }
};
////////////////////////////////////////////////////////////////////////////////

constexpr unsigned MO = 998244353;
using Mint = ModInt<MO>;


// 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::merge(const T &l, const T &r)  should merge two intervals.
template <class T> struct SegmentTreeRange {
  int logN, n;
  vector<T> ts;
  SegmentTreeRange() {}
  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; ) merge(u);
  }

  inline void push(int u) {
    ts[u].push(ts[u << 1], ts[u << 1 | 1]);
  }
  inline void merge(int u) {
    ts[u].merge(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) merge(aa);
      } else {
        if ((aa << h) != a) merge(aa);
        if ((bb << h) != b) merge(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.merge(prodL, ts[aa++]); prodL = t; }
      if (bb & 1) { t.merge(ts[--bb], prodR); prodR = t; }
    }
    t.merge(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 Node {
  // (<- a) += b
  Int mx, lzA, lzB;
  Mint way;
  int lzWayA;
  Mint lzWayB;
  Node() : mx(-INF), lzA(-1), lzB(0), way(0), lzWayA(-1), lzWayB(0) {}
  void push(Node &l, Node &r) {
    if (~lzA) {
      l.change(lzA);
      r.change(lzA);
      lzA = -1;
    }
    if (lzB) {
      l.add(lzB);
      r.add(lzB);
      lzB = 0;
    }
    if (~lzWayA) {
      l.changeWay(lzWayA);
      r.changeWay(lzWayA);
      lzWayA = -1;
    }
    if (lzWayB) {
      l.addWay(lzWayB);
      r.addWay(lzWayB);
      lzWayB = 0;
    }
  }
  void merge(const Node &l, const Node &r) {
    mx = max(l.mx, r.mx);
    way = l.way + r.way;
  }
  void change(Int val) {
    mx = val;
    lzA = val;
    lzB = 0;
  }
  void add(Int val) {
    mx += val;
    lzB += val;
  }
  void changeWay(const Mint &w) {
    way = w;
    lzWayA = w.x;
    lzWayB = 0;
  }
  void addWay(const Mint &w) {
    way += w;
    lzWayB += w;
  }
  bool check(Int tar) {
    return (mx >= tar);
  }
};


int N, M;
vector<int> L, R;
vector<Int> C;

pair<Int, Mint> brute() {
  Int mx = -1;
  Mint way = 0;
  for (int p = 0; p < 1 << N; ++p) {
    bool ok = true;
    Int c = 0;
    int last = -1;
    for (int i = 0; i < N; ++i) if (p >> i & 1) {
      ok = ok && (last < R[i]);
      c += C[i];
      chmax(last, L[i]);
    }
    if (ok) {
      if (chmax(mx, c)) {
        way = 0;
      }
      if (mx == c) {
        way += 1;
      }
    }
  }
  return make_pair(mx, way);
}

int main() {
  for (int numCases; ~scanf("%d", &numCases); ) { for (int caseId = 1; caseId <= numCases; ++caseId) {
    scanf("%d%d", &N, &M);
    L.resize(N);
    R.resize(N);
    C.resize(N);
    for (int i = 0; i < N; ++i) {
      scanf("%d%d%lld", &L[i], &R[i], &C[i]);
      --L[i];
    }
    
    SegmentTreeRange<Node> seg(M);
    for (int x = 0; x < M; ++x) {
      seg.at(x).mx = 0;
      seg.at(x).way = 1;
    }
    seg.build();
    for (int i = 0; i < N; ++i) {
      seg.ch(L[i], R[i], &Node::add, C[i]);
      const auto res = seg.get(R[i] - 1, R[i]);
      const int pos0 = seg.findRight(R[i], &Node::check, res.mx) - 1;
      const int pos1 = seg.findRight(R[i], &Node::check, res.mx + 1) - 1;
      seg.ch(R[i], pos0, &Node::change, res.mx);
      seg.ch(R[i], pos0, &Node::changeWay, res.way);
      seg.ch(pos0, pos1, &Node::addWay, res.way);
// for(int x=0;x<M;++x){const auto re=seg.get(x,x+1);cerr<<make_pair(re.mx,re.way)<<" ";}cerr<<endl;
    }
    
    const auto ans = seg.get(M - 1, M);
    printf("%lld %u\n", ans.mx, ans.way.x);
    
#ifdef LOCAL
const auto brt=brute();
if(brt!=make_pair(ans.mx,ans.way)){
 cerr<<"N = "<<N<<", M = "<<M<<endl;
 cerr<<"L = "<<L<<endl;
 cerr<<"R = "<<R<<endl;
 cerr<<"C = "<<C<<endl;
 cerr<<"brt = "<<brt<<endl;
 cerr<<"ans = "<<make_pair(ans.mx,ans.way)<<endl;
}
assert(brt.first==ans.mx);
assert(brt.second==ans.way);
#endif
  }
#ifndef LOCAL
  break;
#endif
  }
  return 0;
}

詳細信息

Test #1:

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

input:

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

output:

3 1
6 1

result:

ok 4 number(s): "3 1 6 1"

Test #2:

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

input:

30
3 3
1 3 1
1 3 1
1 3 1
3 3
1 2 1
1 3 1
1 3 1
3 3
2 2 1
1 3 1
1 3 1
3 3
1 3 1
1 2 1
1 3 1
3 3
2 3 1
1 2 1
1 3 1
3 3
2 2 1
1 3 1
1 3 1
3 3
2 2 1
1 2 1
1 3 1
3 3
1 3 1
2 3 1
1 3 1
3 3
2 3 1
1 3 1
2 2 1
3 3
1 2 1
1 2 1
1 2 1
3 3
1 3 1
1 3 1
1 3 1
3 3
1 3 1
1 2 1
1 3 1
3 3
2 3 1
1 2 1
1 3 1
3 3
1 3 1
1...

output:

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
2 2
3 1
3 1
3 1
3 1
2 2
3 1
3 1
3 1
3 1
3 1
3 1
3 1
3 1
3 1
3 1

result:

ok 60 numbers

Test #3:

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

input:

20
5 5
1 5 1
1 5 1
1 4 1
1 5 1
1 5 1
5 5
2 4 1
1 5 1
1 5 1
2 4 1
2 4 1
5 5
2 4 1
1 5 1
1 5 1
2 5 1
1 3 1
5 5
1 5 1
1 5 1
2 3 1
1 5 1
1 4 1
5 5
1 4 1
1 4 1
2 5 1
1 3 1
2 4 1
5 5
2 4 1
3 3 1
1 3 1
2 4 1
4 4 1
5 5
3 3 1
1 4 1
3 3 1
2 5 1
2 5 1
5 5
2 4 1
2 3 1
4 4 1
2 4 1
2 4 1
5 5
3 3 1
3 3 1
2 4 1
1 4...

output:

5 1
5 1
5 1
5 1
5 1
5 1
5 1
5 1
4 1
5 1
5 1
5 1
5 1
5 1
4 1
5 1
5 1
5 1
5 1
5 1

result:

ok 40 numbers

Test #4:

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

input:

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

output:

10 1
10 1
10 1
10 1
10 1
10 1
10 1
9 1
9 1
10 1

result:

ok 20 numbers

Test #5:

score: 0
Accepted
time: 66ms
memory: 3656kb

input:

10000
20 20
2 3 1
2 3 1
1 6 1
1 6 1
1 2 1
1 1 1
1 5 1
4 4 1
1 2 1
2 4 1
1 2 1
1 6 1
1 2 1
1 9 1
1 4 1
8 11 1
2 11 1
1 8 1
2 4 1
2 7 1
20 20
4 8 1
1 2 1
2 3 1
2 2 1
1 5 1
3 7 1
1 4 1
2 7 1
3 4 1
1 2 1
5 5 1
1 6 1
1 7 1
1 8 1
1 1 1
1 1 1
3 3 1
2 3 1
1 1 1
1 2 1
20 20
1 1 1
3 11 1
1 8 1
2 9 1
2 7 1
3 9...

output:

17 1
13 1
17 2
12 6
16 1
20 1
20 1
19 1
17 1
13 9
13 4
14 3
12 1
11 3
12 9
19 2
20 1
20 1
19 2
13 4
13 2
13 7
16 2
16 1
18 1
20 1
20 1
20 1
16 5
18 1
13 2
14 4
13 2
14 2
13 6
20 1
20 1
19 1
17 2
15 2
13 4
15 2
16 1
13 2
12 6
20 1
20 1
20 1
18 1
14 4
15 2
15 2
13 5
13 6
16 1
20 1
20 1
20 1
20 1
18 1
...

result:

ok 20000 numbers

Test #6:

score: 0
Accepted
time: 122ms
memory: 3676kb

input:

1000
200 200
1 21 1
93 108 1
52 55 1
61 67 1
1 23 1
70 72 1
1 8 1
21 78 1
1 20 1
6 31 1
71 85 1
4 57 1
9 15 1
63 101 1
48 60 1
93 100 1
55 77 1
94 96 1
59 59 1
3 4 1
6 7 1
3 21 1
14 20 1
88 93 1
46 52 1
1 29 1
1 19 1
45 46 1
3 35 1
3 16 1
79 105 1
84 104 1
16 17 1
41 48 1
4 7 1
2 48 1
101 117 1
14 7...

output:

74 24
68 16
73 12
88 12
111 2
198 1
195 1
190 3
177 2
140 9
70 140
74 14
84 4
93 32
109 14
196 3
197 4
195 1
175 1
130 28
74 124
68 6
84 2
104 8
119 2
194 2
194 2
194 1
172 6
135 4
62 360
74 36
82 180
87 6
107 4
197 2
197 1
189 2
177 2
139 2
71 8
76 20
82 8
102 2
107 208
196 2
198 1
192 3
178 3
135 ...

result:

ok 2000 numbers

Test #7:

score: 0
Accepted
time: 283ms
memory: 16464kb

input:

1
200000 70000
3758 4743 1
33161 33877 1
24037 24952 1
33131 33134 1
24741 25130 1
12964 13639 1
32062 32778 1
12046 12449 1
28229 29159 1
12021 12282 1
5329 6033 1
16581 16923 1
30368 31177 1
29343 29965 1
32647 33027 1
25775 26193 1
878 1026 1
17927 17950 1
16554 16592 1
30029 30096 1
19536 19742 ...

output:

4170 745614878

result:

ok 2 number(s): "4170 745614878"

Test #8:

score: 0
Accepted
time: 289ms
memory: 26808kb

input:

1
200000 200000
78834 78835 1
80528 80530 1
47499 47503 1
65196 65198 1
36003 36005 1
79144 79146 1
91460 91460 1
87949 87951 1
97054 97054 1
99216 99219 1
1043 1046 1
25088 25089 1
59424 59428 1
78742 78744 1
46264 46265 1
44746 44750 1
84877 84881 1
24091 24094 1
35772 35774 1
77841 77841 1
96537 ...

output:

898 862947721

result:

ok 2 number(s): "898 862947721"

Test #9:

score: 0
Accepted
time: 298ms
memory: 26780kb

input:

1
200000 200000
70228 70241 1
2243 2290 1
37711 37751 1
65609 65630 1
35069 35114 1
55461 55502 1
45322 45352 1
63193 63237 1
47993 48004 1
77797 77807 1
65933 65943 1
50756 50758 1
89846 89848 1
40757 40796 1
32542 32568 1
71472 71518 1
36752 36753 1
78477 78511 1
64720 64750 1
17369 17372 1
51635 ...

output:

958 258160284

result:

ok 2 number(s): "958 258160284"

Test #10:

score: 0
Accepted
time: 325ms
memory: 26712kb

input:

1
200000 200000
75340 75924 1
89847 90265 1
59883 60818 1
26303 26836 1
83285 84012 1
51579 51933 1
83631 83730 1
34162 35024 1
82604 83469 1
22334 22878 1
39351 40150 1
74106 74554 1
6193 6244 1
16427 16530 1
20013 20625 1
34653 35093 1
83885 84698 1
66234 67215 1
35548 36129 1
998 1540 1
86220 871...

output:

2172 380312816

result:

ok 2 number(s): "2172 380312816"

Test #11:

score: 0
Accepted
time: 173ms
memory: 26688kb

input:

1
200000 200000
1 4 1
3 4 1
1 3 1
1 2 1
4 7 1
7 10 1
6 8 1
3 6 1
7 7 1
2 3 1
6 6 1
8 10 1
4 6 1
9 11 1
2 3 1
10 14 1
6 7 1
11 11 1
19 20 1
1 5 1
8 8 1
6 9 1
2 3 1
16 19 1
18 20 1
23 27 1
6 9 1
6 10 1
30 32 1
19 23 1
17 21 1
7 9 1
15 19 1
3 5 1
1 2 1
37 38 1
14 16 1
14 16 1
26 28 1
5 9 1
34 38 1
26 2...

output:

31676 227442792

result:

ok 2 number(s): "31676 227442792"

Test #12:

score: 0
Accepted
time: 177ms
memory: 26780kb

input:

1
200000 200000
2 16 1
3 24 1
3 21 1
5 36 1
3 30 1
6 45 1
7 17 1
6 46 1
4 28 1
1 11 1
11 26 1
9 51 1
1 18 1
9 41 1
8 23 1
10 10 1
1 41 1
5 27 1
16 55 1
20 27 1
10 53 1
12 52 1
20 32 1
1 3 1
1 49 1
24 65 1
20 56 1
18 29 1
11 32 1
20 48 1
3 22 1
20 53 1
32 76 1
4 43 1
17 37 1
34 74 1
12 17 1
32 68 1
1...

output:

68340 480122735

result:

ok 2 number(s): "68340 480122735"

Test #13:

score: 0
Accepted
time: 171ms
memory: 26804kb

input:

1
200000 200000
1 105 1
3 24 1
3 742 1
3 689 1
5 445 1
5 384 1
1 796 1
3 880 1
8 984 1
4 907 1
8 79 1
12 887 1
1 731 1
8 154 1
6 745 1
6 328 1
7 487 1
7 526 1
2 819 1
6 698 1
10 464 1
13 222 1
3 885 1
10 222 1
14 627 1
20 133 1
13 600 1
22 507 1
23 342 1
14 58 1
21 546 1
27 283 1
7 720 1
22 337 1
1 ...

output:

98727 824244096

result:

ok 2 number(s): "98727 824244096"

Test #14:

score: 0
Accepted
time: 86ms
memory: 25008kb

input:

1
79364 198410
79365 79366 1
79367 79368 1
79369 79370 1
79371 79372 1
79373 79374 1
79375 79376 1
79377 79378 1
79379 79380 1
79381 79382 1
79383 79384 1
79385 79386 1
79387 79388 1
79389 79390 1
79391 79392 1
79393 79394 1
79395 79396 1
79397 79398 1
79399 79400 1
79401 79402 1
79403 79404 1
79405...

output:

39682 2

result:

ok 2 number(s): "39682 2"

Test #15:

score: 0
Accepted
time: 68ms
memory: 3700kb

input:

10000
20 20
1 20 1
1 20 1
1 17 1
1 17 1
1 18 1
2 15 1
2 18 1
3 19 1
2 20 1
1 18 1
1 20 1
2 20 1
2 16 1
4 18 1
3 20 1
1 19 1
2 20 1
1 20 1
1 19 1
1 20 1
20 20
2 16 1
6 17 1
4 19 1
4 18 1
1 19 1
1 20 1
1 18 1
2 20 1
1 14 1
1 20 1
3 18 1
1 20 1
2 20 1
1 20 1
4 15 1
2 20 1
1 20 1
3 20 1
4 20 1
1 18 1
20...

output:

20 1
20 1
20 1
20 1
20 1
19 1
19 1
19 1
18 2
18 1
20 1
20 1
20 1
20 1
20 1
20 1
18 1
18 1
17 2
17 1
20 1
20 1
20 1
19 2
20 1
20 1
19 1
18 3
16 4
16 2
20 1
20 1
20 1
20 1
20 1
20 1
20 1
17 3
19 1
18 1
20 1
20 1
20 1
20 1
20 1
18 2
20 1
16 1
16 3
18 1
20 1
20 1
20 1
20 1
18 2
20 1
20 1
19 1
18 2
19 2
...

result:

ok 20000 numbers

Test #16:

score: 0
Accepted
time: 102ms
memory: 3660kb

input:

1000
200 200
1 199 1
1 200 1
1 194 1
48 158 1
88 118 1
6 199 1
2 196 1
58 141 1
34 190 1
94 123 1
1 200 1
85 113 1
74 120 1
56 140 1
98 115 1
68 133 1
95 112 1
6 199 1
24 187 1
93 113 1
5 200 1
4 194 1
52 138 1
85 126 1
30 171 1
74 151 1
46 164 1
3 197 1
98 103 1
86 116 1
86 112 1
9 190 1
97 98 1
10...

output:

197 1
194 1
195 2
195 2
195 1
192 3
194 4
195 2
192 2
187 1
198 2
194 2
198 1
196 1
192 8
196 2
195 1
190 1
190 1
186 6
197 1
197 2
195 2
190 4
190 2
195 1
194 2
192 1
192 6
188 3
196 2
192 1
192 4
195 4
189 4
193 5
195 2
195 4
191 2
190 11
195 1
196 3
188 3
192 1
191 2
192 3
196 2
199 1
189 6
188 6...

result:

ok 2000 numbers

Test #17:

score: 0
Accepted
time: 229ms
memory: 16512kb

input:

1
200000 70000
27719 42274 1
6647 63356 1
5652 64350 1
22872 47119 1
3679 66321 1
11511 58495 1
23308 46704 1
24449 45557 1
33000 36998 1
5669 64344 1
2638 67371 1
17273 52732 1
26524 43487 1
6542 63460 1
23855 46144 1
3415 66589 1
8348 61652 1
10806 59196 1
14117 55892 1
2754 67250 1
10393 59604 1
...

output:

199993 1

result:

ok 2 number(s): "199993 1"

Test #18:

score: 0
Accepted
time: 231ms
memory: 26720kb

input:

1
200000 200000
13120 186896 1
57545 142432 1
91680 108341 1
46072 153888 1
4082 195951 1
59587 140389 1
22601 177420 1
95670 104331 1
56267 143757 1
86957 113079 1
25102 174930 1
4532 195474 1
21523 178514 1
83244 116749 1
42887 157135 1
40685 159320 1
96933 103074 1
21007 179004 1
79655 120339 1
5...

output:

199986 8

result:

ok 2 number(s): "199986 8"

Test #19:

score: 0
Accepted
time: 197ms
memory: 26776kb

input:

1
200000 200000
2 199999 1
1 200000 1
1 200000 1
5 200000 1
4 199997 1
3 199996 1
7 200000 1
7 199992 1
8 199995 1
10 199997 1
8 199995 1
13 199989 1
11 199992 1
7 199989 1
8 200000 1
8 199997 1
12 199988 1
3 199983 1
10 199985 1
10 199982 1
13 199990 1
1 199985 1
19 199992 1
10 199995 1
8 199975 1
...

output:

199985 1

result:

ok 2 number(s): "199985 1"

Test #20:

score: 0
Accepted
time: 145ms
memory: 4512kb

input:

300
1497 2969
558 2856 1
1484 1893 1
438 2226 1
1292 2738 1
397 903 1
1181 1723 1
2692 2880 1
885 2721 1
951 1346 1
937 2486 1
409 929 1
311 1817 1
458 1530 1
1058 1216 1
1056 1104 1
2484 2706 1
766 1796 1
754 1413 1
1684 2509 1
173 1090 1
580 1121 1
2047 2086 1
1586 1841 1
428 1819 1
1599 2696 1
73...

output:

816 280
1349 16248
249 2
92 600
348 48
23 1
38 2
297 40
196 16
1346 288
54 4
188 72
396 24
109 50
224 30
63 8
118 2
74 12
193 336
306 80
522 64
379 120
1672 1
515 8
256 56
565 45
64 2
73 2
616 128
178 8
4 2
64 2
732 6
21 9
120 8
334 128
15 7
170 320
31 1
302 72
464 4
50 13
717 1104
405 8
71 4
483 12...

result:

ok 600 numbers

Test #21:

score: 0
Accepted
time: 292ms
memory: 26776kb

input:

1
200000 200000
53839 55210 1
103761 171904 1
51490 64117 1
52415 59053 1
28403 81648 1
36025 96539 1
34877 167586 1
37797 192220 1
103331 198197 1
104826 194492 1
70132 87411 1
60069 142685 1
124807 162475 1
56049 120528 1
109669 121796 1
36092 179102 1
156082 170394 1
117350 157532 1
39585 145600 ...

output:

100201 402633336

result:

ok 2 number(s): "100201 402633336"

Test #22:

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

input:

1
79364 198410
158727 198410 1
158725 198410 1
158723 198410 1
158721 198410 1
158719 198410 1
158717 198410 1
158715 198410 1
158713 198410 1
158711 198410 1
158709 198410 1
158707 198410 1
158705 198410 1
158703 198410 1
158701 198410 1
158699 198410 1
158697 198410 1
158695 198410 1
158693 198410...

output:

39682 2

result:

ok 2 number(s): "39682 2"

Test #23:

score: 0
Accepted
time: 57ms
memory: 24636kb

input:

1
66666 199998
133331 199998 1
133329 199998 1
133327 199998 1
133325 199998 1
133323 199998 1
133321 199998 1
133319 199998 1
133317 199998 1
133315 199998 1
133313 199998 1
133311 199998 1
133309 199998 1
133307 199998 1
133305 199998 1
133303 199998 1
133301 199998 1
133299 199998 1
133297 199998...

output:

66666 1

result:

ok 2 number(s): "66666 1"

Test #24:

score: 0
Accepted
time: 70ms
memory: 3660kb

input:

10000
20 20
2 20 5
1 20 5
2 20 2
1 20 6
3 17 3
1 20 4
2 20 7
5 20 1
1 18 5
2 18 7
2 18 2
2 18 1
1 19 6
1 20 3
1 20 7
1 16 1
2 18 10
9 15 8
1 19 6
5 20 4
20 20
2 15 3
2 19 7
1 20 2
1 18 6
3 20 5
1 20 9
1 20 10
1 19 1
1 19 3
3 16 7
2 19 4
3 17 3
1 20 10
3 16 4
2 18 4
2 15 6
2 20 2
2 20 9
3 20 5
2 13 5...

output:

93 1
105 1
128 1
117 1
114 1
124 1
98 1
101 1
127 1
117 1
112 1
108 1
111 1
99 1
97 1
105 1
106 1
116 1
97 1
107 1
113 1
115 1
86 1
137 1
99 1
108 2
114 1
94 1
96 1
83 1
113 1
104 1
99 1
82 1
117 1
91 1
103 1
107 1
100 1
86 1
123 1
111 1
119 1
112 1
78 1
128 1
122 1
117 1
91 1
108 1
118 1
99 1
99 1
...

result:

ok 20000 numbers

Test #25:

score: 0
Accepted
time: 101ms
memory: 3700kb

input:

1000
200 200
62 139 8
89 110 10
40 183 5
59 156 10
3 189 4
75 128 4
78 125 1
5 192 9
8 195 3
32 151 3
92 99 9
65 139 1
74 119 2
12 185 6
70 143 2
3 194 5
24 174 5
80 142 6
63 144 3
71 134 10
1 200 5
85 123 1
95 126 8
112 121 8
94 111 10
92 113 1
1 199 5
57 144 9
81 122 4
52 160 5
2 200 9
60 139 10
5...

output:

1077 1
1073 1
1028 1
1048 1
1088 2
1075 1
1021 1
1008 2
1093 2
1127 1
1083 1
1104 1
1102 1
1146 1
994 1
1047 1
970 1
1089 1
1052 1
998 1
996 1
1135 1
1155 1
1158 1
1046 1
1129 1
1012 1
1080 2
990 1
1002 1
1077 1
1098 1
1089 1
995 1
1109 1
1133 1
1037 1
1108 1
1053 2
1088 1
1043 1
1153 1
1053 1
1051 ...

result:

ok 2000 numbers

Test #26:

score: 0
Accepted
time: 225ms
memory: 16576kb

input:

1
200000 70000
13421 56568 1
4349 65667 2
15557 54445 2
25559 44450 1
23675 46328 1
13772 56231 1
23551 46447 3
23209 46801 2
6747 63266 1
8699 61307 1
24946 45064 3
18881 51117 3
25923 44084 3
31091 38916 1
31929 38072 2
16293 53701 2
16194 53809 2
10662 59337 3
6960 63032 3
25829 44157 2
34484 355...

output:

400757 1

result:

ok 2 number(s): "400757 1"

Test #27:

score: 0
Accepted
time: 240ms
memory: 26700kb

input:

1
200000 200000
14346 185691 9
15513 184451 4
95019 104950 3
5289 194720 4
78689 121304 1
54194 145818 4
17594 182430 10
45423 154549 7
32203 167784 6
80570 119468 6
57035 142929 3
50995 149009 8
56869 143107 9
68883 131145 3
49209 150773 8
8768 191241 3
18033 181985 2
19511 180501 10
83354 116645 2...

output:

1101347 2

result:

ok 2 number(s): "1101347 2"

Test #28:

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

input:

1
200000 200000
1835 1860 3
72172 72215 7
80101 80110 6
19476 19513 9
93148 93242 8
46447 46522 9
35057 35071 6
66552 66630 8
83931 83967 4
8564 8567 10
20863 20946 1
39346 39441 6
25535 25599 8
12284 12309 3
9979 9999 6
99467 99549 9
22984 23004 10
1635 1665 4
72541 72615 3
99278 99346 2
50884 5091...

output:

6621 113246208

result:

ok 2 number(s): "6621 113246208"

Test #29:

score: 0
Accepted
time: 162ms
memory: 26724kb

input:

1
200000 200000
2 5 7
1 88 5
2 93 9
3 29 1
1 29 3
4 93 5
7 27 4
9 32 6
8 29 9
8 103 9
10 76 4
3 89 6
4 23 6
8 64 4
3 43 8
15 77 3
13 51 6
19 26 6
4 40 7
5 95 9
21 60 5
18 58 6
3 73 10
19 79 1
15 49 7
12 105 3
26 88 8
1 55 8
21 65 8
30 60 9
31 89 1
33 116 6
31 112 2
11 82 10
34 75 7
22 24 5
27 69 1
1...

output:

462635 711287574

result:

ok 2 number(s): "462635 711287574"

Test #30:

score: 0
Accepted
time: 134ms
memory: 4408kb

input:

300
55 318
69 305 4029
182 308 4191
40 306 2136
6 262 1542
105 128 4386
75 192 2596
131 288 3792
112 118 632
34 187 785
104 119 3567
231 253 3264
164 215 2600
82 107 4796
115 168 1140
39 165 1064
95 291 2364
184 232 49
22 264 972
4 190 4675
10 245 3304
67 183 3844
171 175 400
88 140 3296
85 130 2544...

output:

93668 1
1475675 1
1861822 1
1729524 1
1017322 1
906885 1
259697 1
585460 1
1139624 1
63824 1
1015898 1
683051 1
780407 1
555390 1
68540 1
1196528 1
1398141 1
94744 1
548364 1
667084 1
371386 2
161105 1
1292366 1
393038 1
635798 1
799982 1
113188 1
204880 1
22995 1
79812 1
223924 1
777346 1
119204 1
...

result:

ok 600 numbers

Test #31:

score: 0
Accepted
time: 268ms
memory: 26784kb

input:

1
200000 200000
54789 89627 8054928
128204 171619 8705846
111831 185204 287046
35223 98646 1902720
37958 87251 9760212
74544 85603 1537270
70376 131929 4873392
44922 170533 2705892
166191 168630 9013379
27266 128950 7524690
93950 112980 5561322
63354 106040 4891284
42904 153325 9266452
11155 35900 2...

output:

494907106860 1

result:

ok 2 number(s): "494907106860 1"

Test #32:

score: 0
Accepted
time: 45ms
memory: 24576kb

input:

1
59524 198410
158727 198410 1
158725 198410 1
158723 198410 1
158721 198410 1
158719 198410 1
158717 198410 1
158715 198410 1
158713 198410 1
158711 198410 1
158709 198410 1
158707 198410 1
158705 198410 1
158703 198410 1
158701 198410 1
158699 198410 1
158697 198410 1
158695 198410 1
158693 198410...

output:

1000019841 1

result:

ok 2 number(s): "1000019841 1"

Test #33:

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

input:

1
59524 198410
79365 79366 1
79367 79368 1
79369 79370 1
79371 79372 1
79373 79374 1
79375 79376 1
79377 79378 1
79379 79380 1
79381 79382 1
79383 79384 1
79385 79386 1
79387 79388 1
79389 79390 1
79391 79392 1
79393 79394 1
79395 79396 1
79397 79398 1
79399 79400 1
79401 79402 1
79403 79404 1
79405...

output:

1000019841 1

result:

ok 2 number(s): "1000019841 1"

Test #34:

score: 0
Accepted
time: 70ms
memory: 24956kb

input:

1
79364 198410
158727 198410 1
158725 198410 1
158723 198410 1
158721 198410 1
158719 198410 1
158717 198410 1
158715 198410 1
158713 198410 1
158711 198410 1
158709 198410 1
158707 198410 1
158705 198410 1
158703 198410 1
158701 198410 1
158699 198410 1
158697 198410 1
158695 198410 1
158693 198410...

output:

29762000000000 1

result:

ok 2 number(s): "29762000000000 1"

Test #35:

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

input:

1
79364 198410
79365 79366 1
79367 79368 1
79369 79370 1
79371 79372 1
79373 79374 1
79375 79376 1
79377 79378 1
79379 79380 1
79381 79382 1
79383 79384 1
79385 79386 1
79387 79388 1
79389 79390 1
79391 79392 1
79393 79394 1
79395 79396 1
79397 79398 1
79399 79400 1
79401 79402 1
79403 79404 1
79405...

output:

29762000000000 1

result:

ok 2 number(s): "29762000000000 1"