QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#438431#6826. Forest of MagicAthanasyAC ✓4014ms191692kbC++2310.1kb2024-06-10 17:55:562024-06-10 17:55:56

Judging History

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

  • [2024-06-10 17:55:56]
  • 评测
  • 测评结果:AC
  • 用时:4014ms
  • 内存:191692kb
  • [2024-06-10 17:55:56]
  • 提交

answer

#include <bits/stdc++.h>

// #pragma GCC optimize(2)
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
#pragma pack(1)
// #define isPbdsFile

#ifdef isPbdsFile

#include <bits/extc++.h>

#else

#include <ext/pb_ds/priority_queue.hpp>
#include <ext/pb_ds/hash_policy.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/trie_policy.hpp>
#include <ext/pb_ds/tag_and_trait.hpp>
#include <ext/pb_ds/hash_policy.hpp>
#include <ext/pb_ds/list_update_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/exception.hpp>
#include <ext/rope>

#endif

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> tii;
typedef tuple<ll, ll, ll> tll;
typedef unsigned int ui;
typedef unsigned long long ull;
#define hash1 unordered_map
#define hash2 gp_hash_table
#define hash3 cc_hash_table
#define stdHeap std::priority_queue
#define pbdsHeap __gnu_pbds::priority_queue
#define sortArr(a, n) sort(a+1,a+n+1)
#define all(v) v.begin(),v.end()
#define yes cout<<"YES"
#define no cout<<"NO"
#define Spider ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define MyFile freopen("..\\input.txt", "r", stdin),freopen("..\\output.txt", "w", stdout);
#define forn(i, a, b) for(int i = a; i <= b; i++)
#define forv(i, a, b) for(int i=a;i>=b;i--)
#define ls(x) (x<<1)
#define rs(x) (x<<1|1)
#define endl '\n'
//用于Miller-Rabin
[[maybe_unused]] static int Prime_Number[13] = {0, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37};

template <typename T>
int disc(T* a, int n)
{
    return unique(a + 1, a + n + 1) - (a + 1);
}

template <typename T>
T lowBit(T x)
{
    return x & -x;
}

template <typename T>
T Rand(T l, T r)
{
    static mt19937 Rand(time(nullptr));
    uniform_int_distribution<T> dis(l, r);
    return dis(Rand);
}

template <typename T1, typename T2>
T1 modt(T1 a, T2 b)
{
    return (a % b + b) % b;
}

template <typename T1, typename T2, typename T3>
T1 qPow(T1 a, T2 b, T3 c)
{
    a %= c;
    T1 ans = 1;
    for (; b; b >>= 1, (a *= a) %= c) if (b & 1) (ans *= a) %= c;
    return modt(ans, c);
}

template <typename T>
void read(T& x)
{
    x = 0;
    T sign = 1;
    char ch = getchar();
    while (!isdigit(ch))
    {
        if (ch == '-') sign = -1;
        ch = getchar();
    }
    while (isdigit(ch))
    {
        x = (x << 3) + (x << 1) + (ch ^ 48);
        ch = getchar();
    }
    x *= sign;
}

template <typename T, typename... U>
void read(T& x, U&... y)
{
    read(x);
    read(y...);
}

template <typename T>
void write(T x)
{
    if (typeid(x) == typeid(char)) return;
    if (x < 0) x = -x, putchar('-');
    if (x > 9) write(x / 10);
    putchar(x % 10 ^ 48);
}

template <typename C, typename T, typename... U>
void write(C c, T x, U... y)
{
    write(x), putchar(c);
    write(c, y...);
}


template <typename T11, typename T22, typename T33>
struct T3
{
    T11 one;
    T22 tow;
    T33 three;

    bool operator<(const T3 other) const
    {
        if (one == other.one)
        {
            if (tow == other.tow) return three < other.three;
            return tow < other.tow;
        }
        return one < other.one;
    }

    T3()
    {
        one = tow = three = 0;
    }

    T3(T11 one, T22 tow, T33 three) : one(one), tow(tow), three(three)
    {
    }
};

template <typename T1, typename T2>
void uMax(T1& x, T2 y)
{
    if (x < y) x = y;
}

template <typename T1, typename T2>
void uMin(T1& x, T2 y)
{
    if (x > y) x = y;
}

constexpr int N = 4e5 + 10;
constexpr ll MOD = 1 << 31;
constexpr int MX = 1e9;
constexpr int T = log2(5e4) + 1;
int n, q, cnt;
int root[N], fa[N][T + 1], deep[N];
vector<int> child[N];

struct Node
{
    int left, right;
    ll kSum, valSum;
} node[N * 100];

#define left(x) node[x].left
#define right(x) node[x].right
#define kSum(x) node[x].kSum
#define valSum(x) node[x].valSum

inline void pushUp(const int curr)
{
    kSum(curr) = kSum(left(curr)) + kSum(right(curr));
    valSum(curr) = valSum(left(curr)) + valSum(right(curr));
}

inline void update(const int pre, int& curr, const int color, const int kAdd, const ll val, const int l = 1,
                   const int r = MX)
{
    node[curr = ++cnt] = node[pre];
    kSum(curr) += kAdd, valSum(curr) += val;
    if (l == r) return;
    const int mid = l + r >> 1;
    if (color <= mid) update(left(pre),left(curr), color, kAdd, val, l, mid);
    else update(right(pre),right(curr), color, kAdd, val, mid + 1, r);
}

inline ll query(const int curr, const int color, const int dep, const int l = 1, const int r = MX)
{
    if (!curr) return 0;
    if (r <= color) return kSum(curr) * (dep - 1) + valSum(curr);
    const int mid = l + r >> 1;
    ll ans = query(left(curr), color, dep, l, mid);
    if (color > mid) ans += query(right(curr), color, dep, mid + 1, r);
    return ans;
}

inline void merge(int& curr, const int rtL, const int rtR, const int l = 1, const int r = MX)
{
    if (!rtL or !rtR)
    {
        curr = rtL | rtR;
        return;
    }
    curr = ++cnt;
    kSum(curr) = kSum(rtL) + kSum(rtR);
    valSum(curr) = valSum(rtL) + valSum(rtR);
    if (l == r) return;
    const int mid = l + r >> 1;
    merge(left(curr), left(rtL), left(rtR), l, mid);
    merge(right(curr), right(rtL), right(rtR), mid + 1, r);
}

struct Query
{
    int color, kAdd;
    ll valAdd;
};

vector<Query> op[N];

inline void initFa(const int curr)
{
    forn(i, 1, T) fa[curr][i] = fa[fa[curr][i - 1]][i - 1];
}

inline void dfs(const int curr, const int pa, const bool init = false)
{
    if (init)
    {
        deep[curr] = deep[fa[curr][0] = pa] + 1;
        initFa(curr);
    }
    for (const int nxt : child[curr])
    {
        if (nxt == pa) continue;
        dfs(nxt, curr, init);
        if (!init) merge(root[curr], root[curr], root[nxt]);
    }
    for (const auto [color,kAdd,valAdd] : op[curr])
    {
        update(root[curr], root[curr], color, kAdd, valAdd);
    }
    op[curr].clear();
}

inline int LCA(int x, int y)
{
    if (deep[x] < deep[y]) swap(x, y);
    forv(i, T, 0) if (deep[fa[x][i]] >= deep[y]) x = fa[x][i];
    if (x == y) return x;
    forv(i, T, 0) if (fa[x][i] != fa[y][i]) x = fa[x][i], y = fa[y][i];
    return fa[x][0];
}

typedef tuple<int, int, int, int, ll> qOp;
vector<qOp> build, all;

inline void rebuild()
{
    forn(i, 1, n) root[i] = 0;
    cnt = 0;
    all.insert(all.end(),all(build));
    build.clear();
    for (const auto [u,v,lca,c,k] : all)
    {
        //树上点差分
        const int Fa = fa[lca][0];
        op[u].emplace_back(c, -k, k * deep[u]);
        op[v].emplace_back(c, -k, k * deep[v]);
        op[lca].emplace_back(c, k, -k * deep[lca]);
        op[Fa].emplace_back(c, k, -k * deep[Fa]);
    }
    dfs(1, 0);
}

inline ll cale(const int curr, const int color, const qOp& qu)
{
    const auto [u,v,lca,c,k] = qu;
    if (color < c) return 0;
    if (LCA(lca, curr) == curr) return (deep[u] + deep[v] - deep[lca] - deep[fa[lca][0]]) * k;
    if (LCA(u, curr) == curr) return (deep[u] - deep[curr] + 1) * k;
    if (LCA(v, curr) == curr) return (deep[v] - deep[curr] + 1) * k;
    return 0;
}

ll last;
int type;

namespace fasI
{
    constexpr int BF_SIZE = 1 << 12;
    bool IOerr = false;

    inline char nc()
    {
        static char buf[BF_SIZE], *p1 = buf + BF_SIZE, *pend = buf + BF_SIZE;
        if (p1 == pend)
        {
            p1 = buf;
            pend = buf + fread(buf, 1, BF_SIZE,stdin);
            if (pend == p1)
            {
                IOerr = true;
                return -1;
            }
        }
        return *p1++;
    }

    inline bool bla(const char ch)
    {
        return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t';
    }

    template <typename T>
    void Rd(T& x)
    {
        char ch;
        while (bla(ch = nc()));
        T sign = 1;
        if (ch == '-') sign = -1, ch = nc();
        for (x = ch - '0'; (ch = nc()) >= '0' && ch <= '9'; x = x * 10 + ch - '0');
        x *= sign;
    }

    template <typename T, typename... U>
    void Rd(T& x, U&... y)
    {
        Rd(x);
        Rd(y...);
    }
#undef BF_SIZE
}

using namespace fasI;

inline void solve()
{
    Rd(n, q);
    const int siz = sqrt(10 * n + q);
    forn(i, 1, n-1)
    {
        int u, v;
        Rd(u, v);
        child[u].push_back(v);
        child[v].push_back(u);
    }
    dfs(1, 0, true);
    while (q--)
    {
        Rd(type);
        if (type == 1)
        {
            int pos;
            Rd(pos);
            pos ^= last;
            ++n;
            child[n].push_back(pos), child[pos].push_back(n);
            fa[n][0] = pos, deep[n] = deep[pos] + 1;
            initFa(n);
        }
        else if (type == 2)
        {
            int u, v, c, k;
            Rd(u, v, c, k);
            u ^= last, v ^= last, c ^= last, k ^= last;
            build.emplace_back(u, v, LCA(u, v), c, k);
        }
        else
        {
            int u, c;
            Rd(u, c);
            u ^= last, c ^= last;
            if (build.size() > siz) rebuild();
            last = query(root[u], c, deep[u]);
            for (const auto& t : build) last += cale(u, c, t);
            cout << last << endl;
            last %= MOD;
        }
    }
}

signed int main()
{
    // MyFile
    Spider
    //------------------------------------------------------
    // clock_t start = clock();
    int test = 1;
    //    read(test);
    // cin >> test;
    forn(i, 1, test) solve();
    //    while (cin >> n, n)solve();
    //    while (cin >> test)solve();
    // clock_t end = clock();
    // cerr << "time = " << double(end - start) / CLOCKS_PER_SEC << "s" << endl;
}

// 3 5
// 1 2
// 1 3
// 2 2 3 1 4
// 3 1 1
// 1 13
// 2 13 8 14 13
// 3 13 14

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

詳細信息

Test #1:

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

input:

3 5
1 2
1 3
2 2 3 1 4
3 1 1
1 13
2 13 8 14 13
3 13 14

output:

12
14

result:

ok 2 number(s): "12 14"

Test #2:

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

input:

100 116
2 1
3 2
1 4
5 3
2 6
7 5
8 4
9 4
10 2
8 11
9 12
13 6
11 14
5 15
16 6
1 17
1 18
11 19
20 9
21 15
22 21
9 23
12 24
25 10
26 14
16 27
13 28
29 6
17 30
31 13
17 32
25 33
34 12
23 35
36 15
37 5
32 38
39 38
28 40
41 32
42 34
43 5
14 44
44 45
22 46
47 17
6 48
49 29
50 45
12 51
26 52
53 45
54 21
55 1...

output:

0
0
0
18575924
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
4605938
0
0
4605938
0
0
25367112
0
0
11598401
7040566
0
0
26267646

result:

ok 35 numbers

Test #3:

score: 0
Accepted
time: 2ms
memory: 4028kb

input:

2000 288
2 1
3 1
4 1
5 1
6 3
3 7
1 8
6 9
10 7
11 6
2 12
5 13
14 5
2 15
4 16
17 8
18 8
19 15
20 10
21 16
10 22
21 23
24 18
25 23
26 12
27 10
28 7
29 7
21 30
18 31
20 32
33 15
34 2
29 35
36 11
37 24
38 32
10 39
30 40
41 36
42 39
19 43
23 44
36 45
13 46
8 47
38 48
27 49
48 50
37 51
52 30
53 2
54 3
43 5...

output:

0
0
0
0
0
0
0
2305240
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
8951080
0
0
0
0
0
0
0
0
0
9421276
0
0
0
2305240
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
20769550
0
0
0
0
0
0

result:

ok 84 numbers

Test #4:

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

input:

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

output:


result:

ok 0 number(s): ""

Test #5:

score: 0
Accepted
time: 2ms
memory: 5752kb

input:

10 4
2 1
2 3
4 3
5 3
6 1
7 5
8 7
6 9
4 10
1 1
1 1
3 2 540904132
2 6 6 9973447 1324362

output:

0

result:

ok 1 number(s): "0"

Test #6:

score: 0
Accepted
time: 4014ms
memory: 160828kb

input:

29579 97073
2 1
1 3
2 4
4 5
4 6
6 7
1 8
9 2
10 5
11 4
12 4
13 2
8 14
3 15
9 16
9 17
18 16
2 19
20 12
21 3
22 12
21 23
4 24
22 25
7 26
27 21
13 28
12 29
6 30
18 31
3 32
33 9
34 22
31 35
14 36
21 37
4 38
39 33
38 40
41 9
42 39
1 43
4 44
45 20
46 2
16 47
48 15
27 49
21 50
51 13
49 52
53 51
54 1
38 55
5...

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
78256750
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
22707642
0
8467566
0
0
0
0
0
0
0
0
0
15329702
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
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 38223 numbers

Test #7:

score: 0
Accepted
time: 3988ms
memory: 163480kb

input:

29952 99805
2 1
3 1
4 3
4 5
1 6
7 1
2 8
3 9
8 10
8 11
6 12
7 13
14 8
10 15
10 16
12 17
16 18
19 14
15 20
21 15
22 21
23 20
18 24
25 23
26 20
26 27
24 28
29 27
30 28
29 31
28 32
28 33
34 31
29 35
31 36
36 37
34 38
39 34
35 40
35 41
42 40
39 43
40 44
45 39
43 46
47 45
48 47
49 44
45 50
51 46
50 52
53 ...

output:

3606377445
0
0
0
0
0
0
0
127495141669
24141204114
0
0
0
97028567393
0
69029074275
0
0
0
37689049023
0
134562922691
0
0
0
86777476372
14583830482
0
0
0
119846447201
0
2408298450
209635762910
164836893177
0
0
0
0
0
0
0
229325093612
0
78643630463
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
77022904688
491481593729
2...

result:

ok 39673 numbers

Test #8:

score: 0
Accepted
time: 3790ms
memory: 162000kb

input:

29732 99402
2 1
1 3
3 4
5 3
6 4
7 4
8 3
5 9
6 10
11 7
12 10
13 9
14 11
15 13
12 16
14 17
18 13
19 17
18 20
16 21
22 19
17 23
19 24
21 25
26 20
24 27
25 28
25 29
30 29
31 25
32 28
33 28
34 33
35 31
36 31
37 35
38 37
38 39
37 40
38 41
39 42
41 43
44 38
45 42
41 46
43 47
48 42
49 46
50 46
45 51
52 50
5...

output:

0
466031225
466031225
0
466031225
0
0
0
20021393372
0
0
0
82119522352
0
0
0
0
0
0
0
0
0
480204445311
52758878606
0
0
0
0
0
0
32292491520
37066189420
0
0
0
52094313128
0
0
0
0
0
5365508117
0
293556576042
0
5355970109
0
0
0
0
0
76524851518
239082710554
0
0
0
561800459778
0
281888621989
0
0
47855594193...

result:

ok 39796 numbers

Test #9:

score: 0
Accepted
time: 3249ms
memory: 165596kb

input:

29277 97122
2 1
3 1
1 4
5 1
1 6
7 1
1 8
9 1
10 1
11 1
1 12
1 13
1 14
15 1
1 16
17 1
1 18
1 19
20 1
1 21
1 22
1 23
1 24
25 1
1 26
1 27
28 1
1 29
1 30
1 31
32 1
1 33
34 1
1 35
1 36
37 1
1 38
39 1
40 1
1 41
42 1
1 43
1 44
45 1
46 1
1 47
1 48
1 49
1 50
51 1
52 1
53 1
54 1
55 1
1 56
57 1
58 1
59 1
1 60
6...

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 38179 numbers

Test #10:

score: 0
Accepted
time: 3430ms
memory: 167128kb

input:

30000 100000
2 1
3 1
1 4
5 1
6 1
7 1
8 1
9 1
1 10
1 11
12 1
13 1
14 1
15 1
1 16
1 17
18 1
19 1
20 1
21 1
1 22
23 1
1 24
25 1
1 26
27 1
28 1
29 1
1 30
1 31
1 32
1 33
34 1
35 1
36 1
1 37
38 1
39 1
1 40
1 41
42 1
1 43
1 44
1 45
1 46
1 47
1 48
1 49
1 50
51 1
52 1
53 1
1 54
1 55
1 56
57 1
1 58
59 1
60 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
4405632
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 40096 numbers

Test #11:

score: 0
Accepted
time: 3055ms
memory: 141072kb

input:

29656 98742
14751 2485
14751 8895
8895 10992
5063 10992
5063 13797
13797 4340
10326 4340
16302 10326
16302 38
1390 38
1390 15785
14904 15785
14904 6961
9719 6961
9719 28490
11889 28490
11889 15439
249 15439
249 4552
2560 4552
2560 24449
24449 20296
20296 11446
14150 11446
14150 21676
23924 21676
239...

output:

0
31658265314
13063089260
121837417078
10767928080
121644843241
81447961371
0
188821292685
33306322370
172137903801
80733391591
551169395009
462317796974
84814999785
40811271852
602481061681
31553059226
51873429912
99060299026
32719093368
563421623451
246304578246
82812185229
158780399426
8180895670...

result:

ok 39164 numbers

Test #12:

score: 0
Accepted
time: 2813ms
memory: 140284kb

input:

30000 100000
10925 19663
10925 3184
3184 11108
11108 20568
8684 20568
8684 4695
28692 4695
19511 28692
19511 18086
11530 18086
13687 11530
15442 13687
15442 14155
4215 14155
4215 17955
19675 17955
7365 19675
7365 21210
10942 21210
10942 2801
2801 19197
16051 19197
16051 15617
17685 15617
17685 9083
...

output:

0
0
0
39456609408
20945644840
9536609994
41644928962
144853169579
111321481013
126738998333
285590868908
0
620136763162
108755964826
177363659965
837644203271
316366256293
143979239413
202624730743
456311885800
1101193305255
97962293368
1256609585
0
800683279640
826351544094
1489275750018
1737742504...

result:

ok 39951 numbers

Test #13:

score: 0
Accepted
time: 3974ms
memory: 164720kb

input:

29909 99241
1 2
1 3
2 4
2 5
3 6
3 7
8 4
9 4
5 10
5 11
6 12
6 13
14 7
15 7
16 8
8 17
9 18
19 9
10 20
21 10
11 22
23 11
24 12
12 25
13 26
13 27
28 14
14 29
30 15
15 31
16 32
16 33
34 17
35 17
36 18
37 18
19 38
39 19
40 20
20 41
21 42
43 21
22 44
45 22
23 46
47 23
24 48
49 24
50 25
25 51
52 26
26 53
54...

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
7187118
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
45145720
0
0
0
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 39358 numbers

Test #14:

score: 0
Accepted
time: 3880ms
memory: 164136kb

input:

29607 99516
2 1
3 1
4 2
2 5
3 6
3 7
8 4
9 4
5 10
11 5
6 12
6 13
14 7
7 15
8 16
17 8
9 18
9 19
10 20
21 10
11 22
23 11
12 24
12 25
26 13
13 27
28 14
14 29
30 15
15 31
32 16
33 16
17 34
35 17
18 36
18 37
38 19
39 19
40 20
41 20
42 21
21 43
22 44
22 45
46 23
47 23
24 48
49 24
50 25
25 51
26 52
26 53
54...

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
991706
0
0
0
0
0
0
0
0
0
0
0
0
0
15325890
82802600
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
53841576
0
0
0
0
0
0
0
0
0
410498...

result:

ok 39527 numbers

Test #15:

score: 0
Accepted
time: 3847ms
memory: 191692kb

input:

29944 97708
2 1
2 3
4 3
4 5
5 6
6 7
8 7
9 8
9 10
11 10
11 12
12 13
14 13
15 14
16 15
17 16
17 18
19 18
20 19
20 21
21 22
23 22
24 23
25 24
26 25
27 26
27 28
28 29
30 29
30 31
31 32
32 33
34 33
35 34
36 35
36 37
38 37
38 39
39 40
41 40
42 41
43 42
44 43
44 45
46 45
46 47
47 48
49 48
49 50
50 51
52 51...

output:

4510290375
114070812445
6571934969
217910132343
6571934969
307559766492
188996268462
234123319862
693808941242
604761255610
863064525168
240085325266
174068203584
358004780723
686867199311
264855161128
826800986030
1664175437517
265074493584
1259982249654
2317588104085
227226953642
637901165501
3026...

result:

ok 27652 numbers

Test #16:

score: 0
Accepted
time: 3876ms
memory: 189508kb

input:

29537 99289
1 2
2 3
3 4
5 4
6 5
6 7
8 7
9 8
10 9
11 10
11 12
13 12
14 13
15 14
16 15
16 17
18 17
18 19
19 20
21 20
21 22
23 22
24 23
24 25
26 25
27 26
28 27
28 29
29 30
30 31
31 32
32 33
34 33
34 35
35 36
36 37
37 38
39 38
40 39
40 41
42 41
42 43
43 44
44 45
45 46
46 47
47 48
48 49
50 49
50 51
52 51...

output:

29107573
311684961780
143524688161
535163799690
67858987994
9563742
335829149416
771324943102
485786231940
1072918986682
1091608863260
252802048827
884084523974
490023481653
1086066997370
920516330969
1423246417014
106113830514
2324839633580
1313317608583
925973133936
1626093909545
2025826904052
740...

result:

ok 28826 numbers

Test #17:

score: 0
Accepted
time: 2968ms
memory: 179988kb

input:

30000 100000
1 2
2 3
4 3
4 5
6 5
7 6
7 8
8 9
10 9
10 11
11 12
12 13
14 13
14 15
15 16
17 16
18 17
19 18
19 20
21 20
22 21
22 23
24 23
24 25
26 25
27 26
28 27
29 28
29 30
31 30
32 31
33 32
34 33
35 34
36 35
37 36
38 37
39 38
40 39
40 41
42 41
42 43
43 44
44 45
45 46
46 47
48 47
48 49
49 50
50 51
51 5...

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
4147263492166
171283485636
0
0
0
1803879803434
0
0
0
0
0
0
0
0
3173432451001
0
0
12271186786510
0
0
0
0
0
0
0
0
0
0
100319731618
0
0
0
0
200081336927
0
2900596570306
7432688746488
388594729933
0
0
0
0
0
1773278412
0
0
0
0
0
0
0
0
1845969941892
341157...

result:

ok 30000 numbers

Test #18:

score: 0
Accepted
time: 2972ms
memory: 167432kb

input:

30000 100000
2 1
3 2
3 4
5 4
6 5
6 7
8 7
9 8
10 9
10 11
11 12
12 13
14 13
14 15
15 16
16 17
17 18
19 18
19 20
20 21
21 22
23 22
23 24
24 25
26 25
27 26
27 28
29 28
30 29
30 31
32 31
32 33
34 33
35 34
36 35
37 36
38 37
38 39
40 39
40 41
42 41
43 42
43 44
44 45
45 46
46 47
48 47
49 48
49 50
51 50
51 5...

output:

0
0
0
0
0
117462604990
0
0
0
2998548650146
0
0
1826771893306
0
0
0
0
0
0
0
4106373005521
0
0
0
0
0
0
5118784500443
1309291844260
0
0
0
0
5814472266352
0
0
842434114791
0
0
0
0
0
0
0
0
0
0
0
0
501874019149
0
0
0
0
0
0
0
0
0
0
0
0
27916772469990
0
0
0
0
0
6685083153128
0
0
0
0
0
0
0
0
0
0
0
0
0
0
2766...

result:

ok 30000 numbers

Test #19:

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

input:

1 0

output:


result:

ok 0 number(s): ""