QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#50624#4879. Standard ProblemQingyuAC ✓527ms21760kbC++2316.8kb2022-09-28 00:42:522022-09-28 00:42:53

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-09-28 00:42:53]
  • 评测
  • 测评结果:AC
  • 用时:527ms
  • 内存:21760kb
  • [2022-09-28 00:42:52]
  • 提交

answer

#include <bits/stdc++.h>

#define all(x) (x).begin(), (x).end()
#define fr first
#define sc second
#define unique(a) a.resize(unique(a.begin(), a.end()) - a.begin())
#define shuffle(a) shuffle(a.begin(), a.end(), rnd)

using namespace std;

using ll = long long;

#ifdef ONPC
mt19937 rnd(224);
mt19937_64 rndll(231);
#else
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
mt19937_64 rndll(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif


template<typename T>
void setmin(T &x, T y) {
    x = min(x, y);
}

template<typename T>
void setmax(T &x, T y) {
    x = max(x, y);
}

#define TIME (clock() * 1.0 / CLOCKS_PER_SEC)

namespace Ment {
    template<typename T>
    T inverse(T a, T m) {
        T u = 0, v = 1;
        while (a != 0) {
            T t = m / a;
            m -= t * a;
            swap(a, m);
            u -= t * v;
            swap(u, v);
        }
        assert(m == 1);
        return u;
    }

    template<typename T>
    class Modular {
    public:
        using Type = typename decay<decltype(T::value)>::type;

        constexpr Modular() : value() {}

        template<typename U>
        Modular(const U &x) {
            value = normalize(x);
        }

        template<typename U>
        static Type normalize(const U &x) {
            Type v;
            if (-mod() <= x && x < mod()) v = static_cast<Type>(x);
            else v = static_cast<Type>(x % mod());
            if (v < 0) v += mod();
            return v;
        }

        const Type &operator()() const { return value; }

        template<typename U>
        explicit operator U() const { return static_cast<U>(value); }

        constexpr static Type mod() { return T::value; }

        Modular &operator+=(const Modular &other) {
            value += other.value - mod();
            value += (value >> 31) & mod();
            return *this;
        }

        Modular &operator-=(const Modular &other) {
            value -= other.value;
            value += (value >> 31) & mod();
            return *this;
        }

        template<typename U>
        Modular &operator+=(const U &other) { return *this += Modular(other); }

        template<typename U>
        Modular &operator-=(const U &other) { return *this -= Modular(other); }

        Modular &operator++() { return *this += 1; }

        Modular &operator--() { return *this -= 1; }

        Modular operator++(int) {
            Modular result(*this);
            *this += 1;
            return result;
        }

        Modular operator--(int) {
            Modular result(*this);
            *this -= 1;
            return result;
        }

        Modular operator-() const { return Modular(-value); }

        template<typename U = T>
        typename enable_if<is_same<typename Modular<U>::Type, int>::value, Modular>::type &
        operator*=(const Modular &rhs) {
#ifdef _WIN32
            uint64_t x = static_cast<int64_t>(value) * static_cast<int64_t>(rhs.value);
            uint32_t xh = static_cast<uint32_t>(x >> 32), xl = static_cast<uint32_t>(x), d, m;
            asm(
            "divl %4; \n\t"
            : "=a" (d), "=d" (m)
            : "d" (xh), "a" (xl), "r" (mod())
            );
            value = m;
#else
            value = normalize(static_cast<int64_t>(value) * static_cast<int64_t>(rhs.value));
#endif
            return *this;
        }

        template<typename U = T>
        typename enable_if<is_same<typename Modular<U>::Type, int64_t>::value, Modular>::type &
        operator*=(const Modular &rhs) {
            int64_t q = static_cast<int64_t>(static_cast<long double>(value) * rhs.value / mod());
            value = normalize(value * rhs.value - q * mod());
            return *this;
        }

        template<typename U = T>
        typename enable_if<!is_integral<typename Modular<U>::Type>::value, Modular>::type &
        operator*=(const Modular &rhs) {
            value = normalize(value * rhs.value);
            return *this;
        }

        Modular &operator/=(const Modular &other) { return *this *= Modular(inverse(other.value, mod())); }

        template<typename U>
        friend bool operator==(const Modular<U> &lhs, const Modular<U> &rhs);

        template<typename U>
        friend bool operator<(const Modular<U> &lhs, const Modular<U> &rhs);

        template<typename U>
        friend std::istream &operator>>(std::istream &stream, Modular<U> &number);

    private:
        Type value;
    };

    template<typename T>
    bool operator==(const Modular<T> &lhs, const Modular<T> &rhs) { return lhs.value == rhs.value; }

    template<typename T, typename U>
    bool operator==(const Modular<T> &lhs, U rhs) { return lhs == Modular<T>(rhs); }

    template<typename T, typename U>
    bool operator==(U lhs, const Modular<T> &rhs) { return Modular<T>(lhs) == rhs; }

    template<typename T>
    bool operator!=(const Modular<T> &lhs, const Modular<T> &rhs) { return !(lhs == rhs); }

    template<typename T, typename U>
    bool operator!=(const Modular<T> &lhs, U rhs) { return !(lhs == rhs); }

    template<typename T, typename U>
    bool operator!=(U lhs, const Modular<T> &rhs) { return !(lhs == rhs); }

    template<typename T>
    bool operator<(const Modular<T> &lhs, const Modular<T> &rhs) { return lhs.value < rhs.value; }

    template<typename T>
    Modular<T> operator+(const Modular<T> &lhs, const Modular<T> &rhs) { return Modular<T>(lhs) += rhs; }

    template<typename T, typename U>
    Modular<T> operator+(const Modular<T> &lhs, U rhs) { return Modular<T>(lhs) += rhs; }

    template<typename T, typename U>
    Modular<T> operator+(U lhs, const Modular<T> &rhs) { return Modular<T>(lhs) += rhs; }

    template<typename T>
    Modular<T> operator-(const Modular<T> &lhs, const Modular<T> &rhs) { return Modular<T>(lhs) -= rhs; }

    template<typename T, typename U>
    Modular<T> operator-(const Modular<T> &lhs, U rhs) { return Modular<T>(lhs) -= rhs; }

    template<typename T, typename U>
    Modular<T> operator-(U lhs, const Modular<T> &rhs) { return Modular<T>(lhs) -= rhs; }

    template<typename T>
    Modular<T> operator*(const Modular<T> &lhs, const Modular<T> &rhs) { return Modular<T>(lhs) *= rhs; }

    template<typename T, typename U>
    Modular<T> operator*(const Modular<T> &lhs, U rhs) { return Modular<T>(lhs) *= rhs; }

    template<typename T, typename U>
    Modular<T> operator*(U lhs, const Modular<T> &rhs) { return Modular<T>(lhs) *= rhs; }

    template<typename T>
    Modular<T> operator/(const Modular<T> &lhs, const Modular<T> &rhs) { return Modular<T>(lhs) /= rhs; }

    template<typename T, typename U>
    Modular<T> operator/(const Modular<T> &lhs, U rhs) { return Modular<T>(lhs) /= rhs; }

    template<typename T, typename U>
    Modular<T> operator/(U lhs, const Modular<T> &rhs) { return Modular<T>(lhs) /= rhs; }

    template<typename T, typename U>
    Modular<T> pow(const Modular<T> &a, const U &b) {
        assert(b >= 0);
        Modular<T> x = a, res = 1;
        U p = b;
        while (p > 0) {
            if (p & 1) res *= x;
            x *= x;
            p >>= 1;
        }
        return res;
    }

    template<typename T>
    string to_string(const Modular<T> &number) {
        return to_string(number());
    }

    template<typename T>
    std::ostream &operator<<(std::ostream &stream, const Modular<T> &number) {
        return stream << number();
    }

    template<typename T>
    std::istream &operator>>(std::istream &stream, Modular<T> &number) {
        typename common_type<typename Modular<T>::Type, int64_t>::type x;
        stream >> x;
        number.value = Modular<T>::normalize(x);
        return stream;
    }

    constexpr int md = 998244353;
    using Mint = Modular<std::integral_constant<decay<decltype(md)>::type, md>>;
}
//using Ment::Mint;
using namespace Ment;

const int maxn = 2e5 + 100, inf = 1e9 + 100;

namespace descent_segtree {
    struct item {
        ll set = -1, add = 0, r = 0;
    };

    vector<item> q;

    int N;

    void init(int n) {
        N = 1;
        while (N < n)
            N *= 2;
        q.assign(2 * N, {});
    }

    // w = (set) + (add)

    void save(int v, ll set, ll add) {
        if (set != -1) {
            q[v].set = q[v].r = set;
            q[v].add = 0;
        }
        if (add != 0) {
            q[v].add += add;
            q[v].r += add;
        }
    }

    void push(int v) {
        save(2 * v, q[v].set, q[v].add);
        save(2 * v + 1, q[v].set, q[v].add);
        q[v].set = -1;
        q[v].add = 0;
    }

    void calc(int v) {
        q[v].r = q[2 * v + 1].r;
    }

    void modify(int v, int tl, int tr, int l, int r, pair<ll, ll> w) {
        if (l > r)
            return;
        if (tl == l && tr == r) {
            save(v, w.fr, w.sc);
            return;
        }
        assert(tl != tr);
        push(v);
        int m = (tl + tr) / 2;
        modify(2 * v, tl, m, l, min(r, m), w);
        modify(2 * v + 1, m + 1, tr, max(l, m + 1), r, w);
        calc(v);
    }

    // last equal
    int get_last(int v, int tl, int tr, int r, ll w) {
        if (tl == tr)
            return tl;
        push(v);
        int m = (tl + tr) / 2;
        if (r <= m || q[2 * v].r == w)
            return get_last(2 * v, tl, m, r, w);
        return get_last(2 * v + 1, m + 1, tr, r, w);
    }

    // first >= w
    int get_first(int v, int tl, int tr, int l, ll w) {
        if (tl == tr) {
            return q[v].r >= w ? tr : -1;
        }
        push(v);
        int m = (tl + tr) / 2;
        if (l <= m && q[2 * v].r >= w)
            return get_first(2 * v, tl, m, l, w);
        return get_first(2 * v + 1, m + 1, tr, l, w);
    }

    ll get(int v, int l, int r, int i) {
        if (l == r)
            return q[v].r;
        push(v);
        int m = (l + r) / 2;
        if (i <= m)
            return get(2 * v, l, m, i);
        return get(2 * v + 1, m + 1, r, i);
    }

    void set_value(int l, int r, ll w) {
        modify(1, 0, N - 1, l, r, {w, 0});
    }

    void add_value(int l, int r, ll w) {
        modify(1, 0, N - 1, l, r, {-1, w});
    }

    ll get_value(int i) {
        return get(1, 0, N - 1, i);
    }

    int last_equal(int r, ll w) {
        return get_last(1, 0, N - 1, r, w);
    }

    int first_atleast(int l, ll w) {
        return get_first(1, 0, N - 1, l, w);
    }
}

namespace segtree_lazy {
    struct item {
        Mint w = 0, u = 0;
        bool hasu = 0;

        template<typename T>
        void init(const T &t, int l, int r) {
            w = t;
            hasu = 0;
        }

        void update(const item &first, const item &second, int l, int r) {
            w = first.w + second.w;
        }

        static item merge(const item &first, const item &second, int l, int r) {
            item res;
            res.update(first, second, l, r);  // careful with different lengths
            return res;
        }

        template<typename Modifier>
        void modify(const Modifier &m, int l, int r) {
            w = (r - l + 1) * Mint(m);
            u = m;
            hasu = 1;
        }

        void push(item &first, item &second, int l, int r) {
            if (hasu) {
                int m = (l + r) / 2;
                first.modify(u, l, m);
                second.modify(u, m + 1, r);
                hasu = 0;
            }
        }
    };

    struct segtree {
        vector<item> tree;
        int n = 1;

        segtree(int n = 1) : n(n) {
            tree.resize(1 << (__lg(max(1, n - 1)) + 2));
        }

        template<typename T>
        segtree(const vector<T> &v) {
            build(v);
        }

        template<typename T>
        void build(const vector<T> &v, int i, int l, int r) {
            if (l == r) {
                tree[i].init(v[l], l, r);
                return;
            }
            int m = (l + r) >> 1;
            build(v, i * 2 + 1, l, m);
            build(v, i * 2 + 2, m + 1, r);
            tree[i].update(tree[i * 2 + 1], tree[i * 2 + 2], l, r);
        }

        template<typename T>
        void build(const vector<T> &v) {
            n = v.size();
            tree.assign(1 << (__lg(max(1, n - 1)) + 2), item());
            build(v, 0, 0, n - 1);
        }

        item ask(int l, int r, int i, int vl, int vr) {
            if (vl != vr) {
                tree[i].push(tree[i * 2 + 1], tree[i * 2 + 2], vl, vr);
            }
            if (l == vl && r == vr) {
                return tree[i];
            }
            int m = (vl + vr) >> 1;
            if (r <= m) {
                return ask(l, r, i * 2 + 1, vl, m);
            } else if (m < l) {
                return ask(l, r, i * 2 + 2, m + 1, vr);
            } else {
                return item::merge(ask(l, m, i * 2 + 1, vl, m), ask(m + 1, r, i * 2 + 2, m + 1, vr), l, r);
            }
        }

        item ask(int l, int r) {
            l = max(l, 0);
            r = min(r, n - 1);
            if (l > r) return item();
            return ask(l, r, 0, 0, n - 1);
        }

        template<typename T>
        void set(int ind, const T &t) {
            static array<pair<int, int>, 30> st;
            int l = 0, r = n - 1, i = 0;
            int ptr = -1;
            while (l != r) {
                if (l != r) {
                    tree[i].push(tree[i * 2 + 1], tree[i * 2 + 2], l, r);
                }
                st[++ptr] = {l, r};
                int m = (l + r) >> 1;
                if (ind <= m) {
                    i = i * 2 + 1;
                    r = m;
                } else {
                    i = i * 2 + 2;
                    l = m + 1;
                }
            }
            tree[i].init(t, l, r);
            while (i != 0) {
                i = (i - 1) / 2;
                tree[i].update(tree[i * 2 + 1], tree[i * 2 + 2], st[ptr].first, st[ptr].second);
                --ptr;
            }
        }

        template<typename Modifier>
        void modify(int l, int r, const Modifier &modifier, int i, int vl, int vr) {
            if (vl != vr) {
                tree[i].push(tree[i * 2 + 1], tree[i * 2 + 2], vl, vr);
            }
            if (l == vl && r == vr) {
                tree[i].modify(modifier, vl, vr);
                return;
            }
            int m = (vl + vr) >> 1;
            if (r <= m) {
                modify(l, r, modifier, i * 2 + 1, vl, m);
            } else if (m < l) {
                modify(l, r, modifier, i * 2 + 2, m + 1, vr);
            } else {
                modify(l, m, modifier, i * 2 + 1, vl, m);
                modify(m + 1, r, modifier, i * 2 + 2, m + 1, vr);
            }
            tree[i].update(tree[i * 2 + 1], tree[i * 2 + 2], vl, vr);
        }

        template<typename Modifier>
        void modify(int l, int r, const Modifier &modifier) {
            l = max(l, 0);
            r = min(r, n - 1);
            if (l > r) return;
            modify(l, r, modifier, 0, 0, n - 1);
        }
    };


}

void solve() {
    int nig, m;
    cin >> m >> nig;
    segtree_lazy::segtree cnts(nig + 1);
    descent_segtree::init(nig + 1);
    cnts.modify(0, 0, 1);
    for (int it = 0; it < m; it++) {
        int l, r, c;
        cin >> l >> r >> c;
        ll l_value = descent_segtree::get_value(l);
        int left_pos = descent_segtree::last_equal(l, l_value);
        Mint l_cnt = cnts.ask(left_pos, l).w;
        cnts.set(l, l_cnt);
        descent_segtree::add_value(l, r, c);
        ll r_value = descent_segtree::get_value(r);
        int right_pos = descent_segtree::first_atleast(r + 1, r_value);
        if (right_pos == -1)
            right_pos = descent_segtree::N;
//        cerr << l_value << ' ' << left_pos << ' ' << l_cnt << ' ' << r_value << ' ' << right_pos << '\n';
        if (r + 1 <= right_pos - 1) {
            descent_segtree::set_value(r + 1, right_pos - 1, r_value);
            cnts.modify(r + 1, right_pos - 1, 0);
        }
//        for (int i = 0; i <= nig; i++)
//            cerr << descent_segtree::get_value(i) << ',' << cnts.ask(i, i).w << ' ';
//        cerr << '\n';
    }
    ll ans = descent_segtree::get_value(nig);
    int left_pos = descent_segtree::last_equal(nig, ans);
    Mint cnt = cnts.ask(left_pos, nig).w;
    cout << ans << ' ' << cnt << '\n';
}
// check test counter

int main() {
#ifdef ONPC
    freopen("../a.in", "r", stdin);
    freopen("../a.out", "w", stdout);
#endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    int ts;
    ts = 1;
    cin >> ts;
    for (int its = 1; its <= ts; its++)
        solve();
}

詳細信息

Test #1:

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

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: 3536kb

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: 2ms
memory: 3576kb

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: 2ms
memory: 3764kb

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: 117ms
memory: 3664kb

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: 225ms
memory: 3604kb

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: 424ms
memory: 12484kb

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: 429ms
memory: 21684kb

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: 450ms
memory: 21760kb

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: 493ms
memory: 21756kb

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: 253ms
memory: 21600kb

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: 247ms
memory: 21728kb

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: 268ms
memory: 21604kb

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: 119ms
memory: 21736kb

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: 87ms
memory: 3752kb

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: 165ms
memory: 3600kb

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: 378ms
memory: 12496kb

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: 442ms
memory: 21712kb

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: 313ms
memory: 21520kb

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: 207ms
memory: 4192kb

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: 527ms
memory: 21676kb

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: 115ms
memory: 21708kb

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: 78ms
memory: 21688kb

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: 90ms
memory: 3692kb

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: 172ms
memory: 3684kb

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: 385ms
memory: 12488kb

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: 475ms
memory: 21728kb

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: 464ms
memory: 21680kb

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: 264ms
memory: 21652kb

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: 211ms
memory: 4196kb

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: 525ms
memory: 21580kb

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: 83ms
memory: 21652kb

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: 89ms
memory: 21728kb

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: 113ms
memory: 21656kb

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: 115ms
memory: 21576kb

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"