QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#843694#8222. 投票游戏hhoppitree20 478ms54736kbC++176.2kb2025-01-04 22:02:352025-01-04 22:02:35

Judging History

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

  • [2025-01-04 22:02:35]
  • 评测
  • 测评结果:20
  • 用时:478ms
  • 内存:54736kb
  • [2025-01-04 22:02:35]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 5;

int n, q;
vector<int> G[N];
int fa[N], siz[N], son[N], dep[N];

void dfs1(int x) {
    siz[x] = 1;
    for (auto v : G[x]) {
        dep[v] = dep[x] + 1;
        dfs1(v);
        siz[x] += siz[v];
        if (siz[v] > siz[son[x]]) son[x] = v;
    }
}

int edp[N], top[N], dfn[N], dfn_c;

void dfs2(int x) {
    dfn[x] = ++dfn_c;
    if (!son[x]) {
        edp[x] = x;
        return;
    }
    top[son[x]] = top[x];
    dfs2(son[x]), edp[x] = edp[son[x]];
    for (auto v : G[x]) {
        if (v != son[x]) dfs2(top[v] = v);
    }
}

mt19937 rnd;

struct Node {
    int ls, rs, id;
    long long f, b, sb, mn;
    unsigned int key;
} p[N];

int rt[N], tot;
vector<int> rub;

int newNode() {
    if (rub.empty()) return ++tot;
    int x = rub.back();
    rub.pop_back();
    return x;
}

void delNode(int x) {
    rub.push_back(x);
}

void pushup_p(int k) {
    p[k].sb = p[p[k].ls].sb + p[p[k].rs].sb + p[k].b;
    p[k].mn = p[p[k].ls].sb + p[k].f;
    if (p[k].ls) p[k].mn = min(p[k].mn, p[p[k].ls].mn);
    if (p[k].rs) p[k].mn = min(p[k].mn, p[p[k].rs].mn + p[p[k].ls].sb + p[k].b);
}

void split(int k, long long F, int ID, int &x, int &y) {
    if (!k) {
        x = y = 0;
        return;
    }
    if (p[k].f > F || (p[k].f == F && p[k].id > ID)) {
        x = k;
        split(p[k].rs, F, ID, p[x].rs, y);
    } else {
        y = k;
        split(p[k].ls, F, ID, x, p[y].ls);
    }
    pushup_p(k);
}

int merge(int x, int y) {
    if (!x || !y) return x + y;
    if (p[x].key < p[y].key) {
        p[x].rs = merge(p[x].rs, y);
        pushup_p(x);
        return x;
    }
    p[y].ls = merge(x, p[y].ls);
    pushup_p(y);
    return y;
}

void insert_p(int &x, long long F, long long B, int ID) {
    int k = newNode();
    p[k].ls = p[k].rs = 0, p[k].id = ID;
    p[k].f = F, p[k].b = p[k].sb = B, p[k].mn = F;
    p[k].key = rnd();
    int le, ri;
    split(x, F, ID, le, ri);
    x = merge(merge(le, k), ri);
}

void erase_p(int &x, long long F, long long, int ID) {
    int le, mid, ri;
    split(x, F, ID, le, mid);
    split(mid, F, ID + 1, mid, ri);
    delNode(mid);
    x = merge(le, ri);
}

int find_p(int x, long long y) {
    if (!x || p[x].mn >= y) return 0;
    if (!p[x].ls && !p[x].rs) return x;
    int ans = find_p(p[x].ls, y);
    if (ans) return ans;
    if (p[p[x].ls].sb + p[x].f < y) return x;
    return find_p(p[x].rs, y - p[p[x].ls].sb - p[x].b);
}

long long query_p(int &x, int y) {
    int le, ri;
    split(x, p[y].f, p[y].id, le, ri);
    long long S = p[le].sb;
    x = merge(le, ri);
    return S;
}

long long A[N], B[N], sB[N];

struct Info {
    long long mid, le, ri;

    long long get(long long x) {
        return (x <= mid ? le : ri);
    }

    Info operator + (Info y) {
        Info res;
        res.mid = mid;
        res.le = y.get(le);
        res.ri = y.get(ri);
        return res;
    }
} s[1 << 19];

void pushup_s(int k) {
    s[k] = s[k << 1 | 1] + s[k << 1];
}

void update_s(int k, int l, int r, int x, Info y) {
    if (l == r) {
        s[k] = y;
        return;
    }
    int mid = (l + r) >> 1;
    if (x <= mid) update_s(k << 1, l, mid, x, y);
    else update_s(k << 1 | 1, mid + 1, r, x, y);
    pushup_s(k);
}

Info query_s(int k, int l, int r, int x, int y) {
    if (l >= x && r <= y) return s[k];
    int mid = (l + r) >> 1;
    if (y <= mid) return query_s(k << 1, l, mid, x, y);
    if (x > mid) return query_s(k << 1 | 1, mid + 1, r, x, y);
    return query_s(k << 1 | 1, mid + 1, r, x, y) + query_s(k << 1, l, mid, x, y);
}

void updateF(int x) {
    if (!son[x]) return;
    int pos = find_p(rt[x], A[x] + sB[x]);
    Info res;
    if (pos == 0) {
        res.mid = A[x] + B[son[x]] - 1;
        res.le = A[x] + B[son[x]];
        res.ri = A[x];
    } else {
        long long v = A[x] + sB[x] - query_p(rt[x], pos);
        res.mid = v - 1, res.le = v;
        pos = find_p(rt[x], A[x] + sB[x] - B[son[x]]);
        if (pos == 0) res.ri = A[x];
        else {
            v = A[x] + sB[x] - query_p(rt[x], pos);
            res.ri = v;
        }
    }
    update_s(1, 1, n, dfn[x], res);
}

long long getF(int x) {
    if (G[x].empty()) return A[x];
    return query_s(1, 1, n, dfn[x], dfn[edp[x]] - 1).get(A[edp[x]]);
}

long long f[N];

void record(int x) {
    f[x] = getF(x);
    if (x != 1) f[fa[x]] = getF(fa[x]);
    x = top[fa[fa[x]]];
    while (x) f[x] = getF(x), x = top[fa[x]];
}

void remove(int x) {
    auto del = [&](int id) {
        if (fa[id] && son[fa[id]] != id) erase_p(rt[fa[id]], f[id], B[id], id);
    };
    del(x);
    if (x != 1) del(fa[x]);
    x = top[fa[fa[x]]];
    while (x) del(x), x = top[fa[x]];
}

void reset(int id, long long x, long long y) {
    if (id != 1) sB[fa[id]] += y - B[id];
    A[id] = x, B[id] = y;
}

void append(int x) {
    auto add = [&](int id) {
        updateF(id);
        if (fa[id] && son[fa[id]] != id) insert_p(rt[fa[id]], getF(id), B[id], id);
    };
    add(x);
    if (x != 1) add(fa[x]);
    x = top[fa[fa[x]]];
    while (x) add(x), x = top[fa[x]];
}

signed main() {
    scanf("%d%d", &n, &q);
    for (int i = 2; i <= n; ++i) {
        scanf("%d", &fa[i]);
        G[fa[i]].push_back(i);
    }
    dfs1(dep[1] = 1);
    dfs2(top[1] = 1);
    for (int i = 1; i <= n; ++i) {
        scanf("%lld", &A[i]);
    }
    for (int i = 1; i <= n; ++i) {
        scanf("%lld", &B[i]);
        if (fa[i]) sB[fa[i]] += B[i];
    }
    for (int i = n; i >= 1; --i) {
        updateF(i);
        if (fa[i] && son[fa[i]] != i) {
            insert_p(rt[fa[i]], getF(i), B[i], i);
        }
    }
    while (q--) {
        int opt; scanf("%d", &opt);
        if (opt == 1) {
            int id;
            long long x, y;
            scanf("%d%lld%lld", &id, &x, &y);
            record(id);
            remove(id);
            reset(id, x, y);
            append(id);
        } else {
            int x, y; scanf("%d%d", &x, &y);
            long long fx = getF(x), fy = getF(y);
            if (fx > fy || (fx == fy && x > y)) puts("0");
            else puts("1");
        }
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 25268kb

input:

20 500
1 1 3 1 3 5 6 6 7 3 5 3 9 5 4 7 7 18 2
42129194 82765784 1447057 29726963 82321558 32094641 22474113 49277574 27527633 20746795 47630926 92888389 26787144 80703040 43876864 97991729 12117966 75633318 33577855 93462601
69163546 49621952 45236756 46447931 34085269 55246550 54414402 99593046 103...

output:

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

result:

wrong answer 19th numbers differ - expected: '1', found: '0'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Wrong Answer

Test #13:

score: 0
Wrong Answer
time: 85ms
memory: 25524kb

input:

200 200000
1 2 3 3 5 3 1 6 2 9 11 5 5 2 4 9 17 8 1 4 10 20 18 20 23 13 16 28 15 4 6 27 26 11 30 25 10 2 13 23 25 35 4 8 40 43 36 26 7 27 45 35 14 31 54 45 9 8 9 54 16 32 62 9 29 2 43 39 34 39 27 2 52 56 6 9 48 26 66 28 35 57 79 13 71 61 38 43 80 26 61 26 79 1 24 64 79 15 41 42 56 55 6 24 92 43 89 76...

output:

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

result:

wrong answer 32nd numbers differ - expected: '1', found: '0'

Subtask #4:

score: 0
Wrong Answer

Test #18:

score: 25
Accepted
time: 85ms
memory: 25100kb

input:

200 200000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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
0
0
0
0
0
1
1
1
0
0
0
0
0
1
0
1
0
0
1
0
1
0
1
1
1
1
0
1
0
0
0
1
1
1
0
0
0
1
1
1
1
0
0
1
0
0
1
0
0
1
1
0
0
0
0
0
1
1
1
1
1
0
1
0
0
1
1
1
0
0
0
1
0
0
0
1
1
1
1
0
1
1
0
0
1
1
0
1
0
1
1
1
0
0
0
1
0
1
1
0
0
0
1
0
0
0
0
1
1
0
1
0
1
1
0
1
1
1
0
0
1
0
1
1
1
1
1
1
0
0
0
1
0
0
0
0
1
0
0
0
0
0
1
0
0
0
0
1
0
...

result:

ok 99788 numbers

Test #19:

score: 25
Accepted
time: 73ms
memory: 25132kb

input:

200 200000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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
1
1
1
0
0
1
1
1
1
0
0
0
0
0
0
1
1
1
1
1
0
1
0
1
0
0
0
1
1
0
1
0
1
1
1
1
0
1
0
0
1
1
0
0
0
1
1
1
1
0
1
0
1
1
0
0
0
1
0
0
0
1
0
1
1
1
1
1
0
1
0
0
0
0
1
0
1
1
1
0
1
0
0
0
1
1
1
1
0
0
0
1
0
1
1
1
0
0
1
0
0
0
0
0
0
1
0
1
1
1
1
1
1
1
1
0
1
0
1
1
1
1
1
1
1
1
0
1
0
0
0
1
0
0
0
0
0
0
0
1
1
0
0
0
0
1
1
1
0
...

result:

ok 99818 numbers

Test #20:

score: 25
Accepted
time: 125ms
memory: 25200kb

input:

2000 200000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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
1
1
1
0
1
1
0
1
0
1
1
1
0
1
1
1
1
1
1
0
1
1
1
1
0
0
1
1
1
1
0
1
1
1
0
0
1
1
1
1
1
0
1
1
0
1
0
1
1
0
0
1
1
1
0
0
0
1
1
1
1
1
1
1
0
1
0
1
1
0
1
1
0
1
1
0
1
1
0
0
1
0
0
1
0
1
0
0
1
1
0
0
0
0
1
0
0
1
1
1
1
0
0
1
1
1
0
0
1
1
0
0
1
1
0
1
0
1
0
0
0
1
1
0
0
1
1
1
1
1
1
0
1
0
0
0
1
0
1
0
0
1
1
1
1
0
1
0
...

result:

ok 100002 numbers

Test #21:

score: 25
Accepted
time: 227ms
memory: 24708kb

input:

20000 200000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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
1
1
1
0
0
0
0
0
0
0
0
0
0
0
0
1
1
1
1
1
1
1
1
0
1
1
0
1
1
1
0
0
0
1
0
1
1
0
0
0
1
1
1
1
1
0
1
0
1
0
1
0
1
1
1
0
0
0
0
0
0
1
0
0
1
0
0
0
0
0
0
1
1
1
0
0
0
1
0
0
0
0
0
0
1
1
1
1
0
1
0
1
1
1
0
0
0
0
1
0
0
0
1
1
0
0
0
1
1
1
1
0
0
0
1
1
1
0
0
0
0
0
0
1
1
0
1
1
1
1
1
1
0
1
0
1
1
1
0
1
0
0
0
1
0
0
0
0
...

result:

ok 99886 numbers

Test #22:

score: 25
Accepted
time: 478ms
memory: 40308kb

input:

200000 200000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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
0
1
1
0
1
0
0
0
0
1
0
1
1
1
1
1
0
1
1
0
0
0
0
1
0
0
0
1
1
0
0
1
1
1
0
1
0
1
0
0
1
0
0
0
1
1
1
0
1
1
0
1
0
0
0
0
1
1
1
0
0
1
1
0
0
1
0
0
1
0
1
0
0
1
0
0
0
0
1
0
1
0
1
1
0
0
1
0
0
0
1
0
0
0
0
1
0
0
1
0
0
1
0
1
0
0
0
1
1
1
0
0
0
0
0
0
0
1
1
0
1
1
0
1
1
0
1
1
1
0
1
1
0
1
0
0
1
0
1
0
1
0
1
1
1
0
1
0
...

result:

ok 100006 numbers

Test #23:

score: 0
Wrong Answer
time: 476ms
memory: 38396kb

input:

200000 200000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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
0
0
1
1
1
0
0
0
1
1
1
0
0
0
0
0
1
0
1
0
1
0
0
1
0
1
0
0
0
1
0
1
0
0
1
0
0
0
0
0
1
0
0
0
0
1
1
0
0
0
1
1
1
0
1
0
0
0
1
1
1
0
1
1
1
0
0
0
1
0
0
1
0
1
0
0
1
1
1
0
0
1
0
0
1
0
0
0
1
1
1
0
0
1
0
1
1
0
0
1
0
0
0
1
1
0
1
1
0
1
1
1
0
0
0
0
0
0
1
1
0
0
0
1
1
0
1
0
0
0
1
1
1
0
1
1
1
1
1
1
0
0
1
0
1
0
1
0
...

result:

wrong answer 80840th numbers differ - expected: '0', found: '1'

Subtask #5:

score: 20
Accepted

Test #26:

score: 20
Accepted
time: 76ms
memory: 22352kb

input:

200 200000
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 1...

output:

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

result:

ok 100455 numbers

Test #27:

score: 20
Accepted
time: 85ms
memory: 24176kb

input:

200 200000
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 1...

output:

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

result:

ok 99902 numbers

Test #28:

score: 20
Accepted
time: 119ms
memory: 22796kb

input:

2000 200000
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 ...

output:

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

result:

ok 99882 numbers

Test #29:

score: 20
Accepted
time: 165ms
memory: 26108kb

input:

20000 200000
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99...

output:

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

result:

ok 100151 numbers

Test #30:

score: 20
Accepted
time: 322ms
memory: 54736kb

input:

200000 200000
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 9...

output:

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

result:

ok 100291 numbers

Test #31:

score: 20
Accepted
time: 311ms
memory: 52692kb

input:

200000 200000
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 9...

output:

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

result:

ok 100358 numbers

Test #32:

score: 20
Accepted
time: 262ms
memory: 52656kb

input:

200000 200000
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 9...

output:

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

result:

ok 66538 numbers

Subtask #6:

score: 0
Skipped

Dependency #1:

0%