QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#443801#8647. JOI Tourarbuzick#6 127ms63956kbC++206.1kb2024-06-15 16:33:192024-06-15 16:33:19

Judging History

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

  • [2024-06-15 16:33:19]
  • 评测
  • 测评结果:6
  • 用时:127ms
  • 内存:63956kb
  • [2024-06-15 16:33:19]
  • 提交

answer

#include "joitour.h"

#include <bits/stdc++.h>
#define int long long

using namespace std;

constexpr int R = 1 << 18;

struct Node {
    array<int, 3> cnt;
    array<long long, 3> sum_cnt;
    array<long long, 3> sum_heavy;

    Node() {
        cnt.fill(0);
        sum_cnt.fill(0);
        sum_heavy.fill(0);
    }

    Node operator+(Node b) {
        Node ans;
        for (int i = 0; i < 3; ++i) {
            ans.cnt[i] = cnt[i] + b.cnt[i];
            ans.sum_cnt[i] = sum_cnt[i] + b.sum_cnt[i];
            ans.sum_heavy[i] = sum_heavy[i] + b.sum_heavy[i];
            // if (cnt[1]) {
            //     ans.sum_cnt[i] += sum_cnt[i];
            //     ans.sum_heavy[i] += sum_heavy[i];
            // }
            // if (b.cnt[1]) {
            //     ans.sum_cnt[i] += b.sum_cnt[i];
            //     ans.sum_heavy[i] += b.sum_heavy[i];
            // }
        }
        return ans;
    }

    // void add(Node b) {
    //     for (int i = 0; i < 3; ++i) {
    //         cnt[i] += b.cnt[i];
    //         sum_cnt[i] += b.sum_cnt[i];
    //         sum_heavy[i] += b.sum_heavy[i];
    //     }
    // }
};

constexpr int maxn = 2e5 + 5;

vector<int> g[maxn];

int pr[maxn], sz[maxn];

void dfs(int v) {
    sz[v] = 1;
    for (auto u : g[v]) {
        if (u != pr[v]) {
            pr[u] = v;
            dfs(u);
            sz[v] += sz[u];
        }
    }
    for (int i = 0; i < (int)g[v].size(); ++i) {
        if (g[v][i] == pr[v]) {
            swap(g[v][i], g[v].back());
        }
    }
    if (v != 0) {
        g[v].pop_back();
    }
    for (int i = 0; i < (int)g[v].size(); ++i) {
        if (sz[g[v][i]] > sz[g[v][0]]) {
            swap(g[v][i], g[v][0]);
        }
    }
}

int tp[maxn];

int cnt_all[3];

int cnt[maxn][3], cnt_heavy[maxn][3];

int t = 0;

int tin[maxn], tout[maxn];

int ord[maxn];

void calc_cnt(int v) {
    tin[v] = t++;
    ord[tin[v]] = v;
    cnt_all[tp[v]]++;
    cnt[v][tp[v]]++;
    cnt_heavy[v][tp[v]]++;
    for (auto u : g[v]) {
        calc_cnt(u);
        for (int i = 0; i < 3; ++i) {
            cnt[v][i] += cnt[u][i];
        }
    }
    if (!g[v].empty()) {
        for (int i = 0; i < 3; ++i) {
            cnt_heavy[v][i] += cnt[g[v][0]][i];
        }
    }
    tout[v] = t;
}

long long sum[maxn];

long long cnt_sum[3];

long long ans = 0;

Node vals[maxn];

void init(int32_t n, vector<int32_t> f, vector<int32_t> u, vector<int32_t> v, int32_t q) {
    for (int i = 0; i < n; ++i) {
        tp[i] = f[i];
    }
    for (int i = 0; i < n - 1; ++i) {
        g[u[i]].push_back(v[i]);
        g[v[i]].push_back(u[i]);
    }
    dfs(0);
    calc_cnt(0);
    ans = cnt_all[0] * 1LL * cnt_all[1] * 1LL * cnt_all[2];
    for (int i = 0; i < n; ++i) {
        if (tp[i] == 1) {
            for (auto j : g[i]) {
                ans -= cnt[j][0] * 1LL * cnt[j][2];
            }
            for (int j = 0; j < 3; ++j) {
                cnt_sum[j] += cnt[i][j];
            }
            ans -= (cnt_all[0] - cnt[i][0]) * 1LL * (cnt_all[2] - cnt[i][2]);
        }
        for (auto j : g[i]) {
            if (j != g[i][0]) {
                sum[i] += cnt[j][0] * 1LL * cnt[j][2];
            }
        }
        vals[i].cnt[tp[i]]++;
        for (int j = 0; j < 3; ++j) {
            vals[i].sum_cnt[j] = cnt[i][j];
            vals[i].sum_heavy[j] = cnt_heavy[i][j];
        }
    }
}

void add_to_root(int v, int vl, int tp) {
    vals[v].cnt[vl] += tp;
    vals[v].sum_cnt[vl] += tp;
    vals[v].sum_heavy[vl] += tp;
    int prv = v, nw = pr[v];
    while (prv != 0) {
        vals[nw].sum_cnt[vl] += tp;
        if (prv == g[nw][0]) {
            vals[nw].sum_heavy[vl] += tp;
        } else {
            if (vl != 1) {
                sum[nw] += tp * cnt[prv][vl ^ 2];
            }
        }
        prv = nw;
        nw = pr[nw];
    }
}

pair<Node, long long> get_to_root(int v) {
    int prv = v, nw = pr[v];
    Node ans;
    long long ret = 0;
    while (prv != 0) {
        if (tp[nw] == 1) {
            ans = ans + vals[nw];
            ret += vals[prv].cnt[tp[v] ^ 2];
        }
        prv = nw;
        nw = pr[nw];
    }
    return make_pair(ans, ret);
}

Node get_segm(int l, int r) {
    Node ans;
    for (int i = l; i < r; ++i) {
        if (tp[ord[i]] == 1) {
            ans = ans + vals[ord[i]];
        }
    }
    return ans;
}

void change(int32_t x, int32_t y) {
    if (tp[x] == y) {
        return;
    }

    ans -= cnt_all[0] * 1LL * cnt_all[1] * 1LL * cnt_all[2];
    cnt_all[tp[x]]--;
    ans += cnt_all[0] * 1LL * cnt_all[1] * 1LL * cnt_all[2];
    // cout << "? " << ans << endl;
    if (tp[x] == 0 || tp[x] == 2) {
        auto [node, ret] = get_to_root(x);
        ans += ret;
        auto node2 = get_segm(tin[0], tout[0]);
        ans += (node2.cnt[1] - node.cnt[1]) * 1LL * cnt_all[tp[x] ^ 2] - (node2.sum_cnt[tp[x] ^ 2] - node.sum_cnt[tp[x] ^ 2]);
    } else {
        ans += sum[x];
        if (!g[x].empty()) {
            ans += vals[x].sum_heavy[0] * 1LL * vals[x].sum_heavy[2];
        }
        ans += (cnt_all[0] - vals[x].sum_cnt[0]) * 1LL * (cnt_all[2] - vals[x].sum_cnt[2]);
    }
    add_to_root(x, tp[x], -1);

    tp[x] = y;
    ans -= cnt_all[0] * 1LL * cnt_all[1] * 1LL * cnt_all[2];
    cnt_all[tp[x]]++;
    ans += cnt_all[0] * 1LL * cnt_all[1] * 1LL * cnt_all[2];
    if (tp[x] == 0 || tp[x] == 2) {
        auto [node, ret] = get_to_root(x);
        ans -= ret;
        auto node2 = get_segm(tin[0], tout[0]);
        ans -= (node2.cnt[1] - node.cnt[1]) * 1LL * cnt_all[tp[x] ^ 2] - (node2.sum_cnt[tp[x] ^ 2] - node.sum_cnt[tp[x] ^ 2]);
    } else {
        // cout << "?" << cnt_all[0] << ' ' << vals[x].sum_cnt[0] << ' ' << cnt_all[2] << ' ' << vals[x].sum_cnt[2] << endl;
        ans -= sum[x];
        ans -= vals[x].sum_heavy[0] * 1LL * vals[x].sum_heavy[2];
        ans -= (cnt_all[0] - vals[x].sum_cnt[0]) * 1LL * (cnt_all[2] - vals[x].sum_cnt[2]);
    }
    add_to_root(x, tp[x], 1);
}

long long num_tours() {
    // cout << "!" << ans << "!" << endl;
    return ans;
}

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

input:

400
1 1 0 2 2 0 2 1 1 1 1 0 1 2 2 2 2 0 0 2 0 2 0 2 1 1 2 2 1 2 1 0 1 2 2 2 0 0 0 2 1 2 2 0 0 0 1 2 1 1 0 1 1 2 1 2 2 2 1 1 0 1 1 1 2 2 1 1 0 0 1 1 0 0 1 1 1 2 2 2 1 1 2 1 1 1 0 2 0 2 1 0 1 1 2 0 0 2 1 0 2 2 1 0 0 0 0 1 1 1 0 1 2 1 1 1 2 0 2 2 0 2 0 1 0 1 1 1 1 0 1 1 0 0 0 2 2 0 2 2 2 1 1 0 1 2 0 1 ...

output:

597892
606394
604500
601955
597676
592298
591756
582200
577811
576962
583802
583325
586467
587504
584676
583377
589202
595062
589250
590693
593487
589853
584436
579767
577266
575940
569737
569560
569897
568797
567940
566605
569137
576209
586044
587553
582680
581202
572250
572592
572526
576119
577673...

result:

wrong answer 

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 6
Accepted

Test #11:

score: 6
Accepted
time: 120ms
memory: 60812kb

input:

200000
0 2 2 0 2 2 0 1 1 0 2 2 0 1 2 2 0 1 0 2 1 1 0 1 0 2 0 2 0 0 0 1 0 0 2 0 2 1 0 0 1 1 1 0 0 2 1 2 2 1 0 2 2 2 0 2 2 1 2 0 1 0 0 1 2 0 0 2 1 1 1 0 1 1 1 2 1 0 1 1 0 1 2 2 2 0 1 0 1 1 0 2 0 1 0 2 0 0 2 2 2 2 2 0 0 2 1 2 2 1 2 0 1 1 1 1 1 0 2 0 2 0 1 1 1 0 1 0 2 1 2 0 1 1 0 2 1 2 2 2 0 0 2 2 2 0 1...

output:

77241161705660

result:

ok 

Test #12:

score: 6
Accepted
time: 107ms
memory: 60588kb

input:

200000
2 1 2 0 2 1 2 1 2 1 1 1 2 1 2 1 2 1 1 1 1 2 0 1 2 1 1 2 1 2 2 2 1 2 2 2 1 2 2 1 1 1 2 2 1 1 2 2 1 2 1 1 2 2 1 2 2 2 1 2 2 2 1 2 1 1 2 2 2 1 1 2 2 1 1 2 1 2 1 1 2 1 2 2 2 1 1 1 2 2 2 2 1 1 1 2 1 1 2 1 1 2 1 2 2 2 2 1 1 2 1 2 2 1 1 1 2 1 1 1 2 0 2 1 2 2 1 1 2 2 2 2 1 1 1 1 2 1 1 2 2 2 1 1 1 1 2...

output:

14535453821146

result:

ok 

Test #13:

score: 6
Accepted
time: 120ms
memory: 57688kb

input:

200000
2 2 0 2 2 0 0 0 0 0 2 2 2 2 0 2 2 2 2 1 0 2 0 2 2 0 0 2 2 0 0 2 2 1 0 2 0 2 0 0 2 1 0 0 0 2 0 0 0 2 2 0 2 0 2 2 0 0 0 0 2 0 0 2 0 2 0 2 0 2 2 2 2 2 0 2 2 2 2 0 0 0 0 0 2 0 2 2 0 2 0 0 2 0 0 2 2 2 0 2 0 2 2 0 2 2 2 0 0 2 0 1 0 2 0 2 2 0 2 2 2 0 2 2 0 2 0 2 0 2 0 0 0 0 2 0 0 2 0 0 0 2 0 0 0 2 0...

output:

15024455356747

result:

ok 

Test #14:

score: 6
Accepted
time: 118ms
memory: 61616kb

input:

200000
1 0 0 1 2 0 0 0 1 1 0 1 1 0 1 0 0 0 0 0 0 1 1 0 1 0 0 0 0 1 0 0 1 1 1 0 0 1 1 1 2 0 0 0 1 1 0 0 1 0 1 0 1 0 1 0 0 0 1 1 1 0 1 1 0 1 0 1 0 0 0 0 0 1 2 1 0 1 1 1 1 0 1 2 1 0 1 0 1 0 1 0 0 1 1 0 0 1 1 0 1 0 0 0 1 1 0 1 0 1 0 1 0 0 1 1 0 0 0 0 0 1 1 1 0 0 0 0 1 1 1 0 1 1 0 1 0 1 0 1 0 1 2 1 0 0 1...

output:

14979709993295

result:

ok 

Test #15:

score: 6
Accepted
time: 49ms
memory: 54416kb

input:

200000
0 1 2 1 2 1 0 1 0 0 2 0 0 1 0 0 2 0 0 0 2 1 0 1 0 0 2 2 2 1 0 2 1 1 2 1 2 1 2 0 2 1 0 2 0 2 2 2 2 0 2 1 2 1 1 1 0 1 2 2 1 1 0 0 0 1 1 1 0 0 1 1 1 2 0 2 2 0 2 2 2 2 0 2 2 0 1 0 1 0 1 0 2 1 1 2 0 0 2 1 1 0 0 2 2 1 2 2 2 1 1 0 1 2 0 0 1 1 1 1 1 1 0 0 2 1 1 0 0 0 0 0 2 1 1 2 2 1 1 0 2 0 1 1 1 2 2...

output:

457084700208

result:

ok 

Test #16:

score: 6
Accepted
time: 43ms
memory: 54420kb

input:

200000
0 0 1 0 1 1 1 1 0 2 2 1 2 1 2 0 0 0 2 0 0 1 0 1 1 0 1 0 2 0 0 1 1 1 1 2 1 1 1 0 2 0 0 2 2 2 0 2 1 0 0 2 0 0 2 1 0 2 1 2 0 2 2 1 0 1 0 0 2 1 2 2 2 0 1 2 2 2 2 0 1 0 2 2 1 0 0 1 2 1 0 2 1 2 0 0 2 0 2 2 2 2 1 0 0 2 0 2 0 2 2 2 1 1 1 1 1 0 1 1 0 0 2 2 1 0 2 0 2 1 2 2 2 2 2 0 0 1 0 1 0 1 2 1 0 0 2...

output:

490004211265

result:

ok 

Test #17:

score: 6
Accepted
time: 97ms
memory: 54728kb

input:

200000
1 1 1 1 0 2 1 0 1 0 2 0 2 0 2 2 2 0 2 1 1 2 0 0 0 0 0 2 2 2 0 2 1 2 0 1 0 2 2 1 2 1 0 0 2 1 0 2 1 1 0 1 2 2 0 0 2 0 2 2 1 2 1 2 0 0 1 1 0 1 2 1 2 0 2 2 0 2 0 2 1 0 2 2 2 0 1 0 0 0 2 2 2 2 0 0 0 0 1 2 2 1 1 2 2 1 2 1 2 0 0 1 2 1 0 1 0 0 0 2 1 1 1 0 0 1 2 1 1 1 0 1 1 0 2 1 1 0 1 1 2 2 1 2 1 1 0...

output:

149609988117

result:

ok 

Test #18:

score: 6
Accepted
time: 108ms
memory: 55104kb

input:

200000
0 1 2 1 2 2 2 2 0 1 1 2 0 0 0 0 1 1 0 2 0 2 1 1 1 2 2 0 2 2 0 1 1 1 2 0 0 1 2 1 2 1 0 1 2 1 1 2 0 1 1 0 0 1 0 1 0 1 0 0 1 2 2 2 2 1 2 0 0 2 1 2 1 2 1 0 2 2 0 2 1 1 1 1 2 2 1 0 2 2 2 2 1 0 2 2 0 0 1 0 1 2 1 1 2 0 2 1 1 2 2 2 1 0 2 2 1 1 1 0 0 1 1 0 0 0 0 1 1 0 1 0 1 1 2 0 0 2 1 1 0 2 2 1 1 0 1...

output:

490004211265

result:

ok 

Test #19:

score: 6
Accepted
time: 83ms
memory: 55344kb

input:

200000
2 1 1 1 2 0 0 1 2 0 1 1 1 2 0 0 2 1 2 0 0 0 2 1 0 1 1 1 2 2 2 2 2 1 0 2 2 2 1 2 0 1 2 0 0 2 2 0 0 0 0 1 2 0 1 0 0 1 1 2 2 0 0 1 2 2 1 0 1 2 2 2 0 0 0 1 2 1 1 2 2 1 2 1 0 0 0 2 1 1 2 2 2 1 0 1 2 2 1 1 1 1 2 1 1 2 2 1 2 1 2 1 0 2 2 2 2 0 0 1 2 2 2 0 1 0 2 2 0 0 0 2 2 0 2 0 0 1 0 0 2 0 1 0 1 1 2...

output:

1812572240374

result:

ok 

Test #20:

score: 6
Accepted
time: 117ms
memory: 56108kb

input:

200000
1 0 0 2 0 2 0 0 2 1 2 1 0 0 0 1 1 2 1 2 0 2 0 0 2 0 2 0 2 1 1 1 2 2 0 0 2 2 2 1 1 2 2 0 2 0 0 0 0 0 1 1 0 0 0 1 2 0 1 2 1 2 0 1 2 0 0 0 2 2 2 1 2 2 0 1 2 1 1 0 0 1 1 2 0 1 0 0 2 0 2 2 0 2 2 2 0 1 0 1 0 0 2 0 1 2 1 1 1 0 1 1 1 0 0 2 2 1 0 2 0 1 2 2 1 1 1 1 1 1 0 0 1 0 2 1 2 0 0 1 2 0 2 2 2 0 0...

output:

7322589985203

result:

ok 

Test #21:

score: 6
Accepted
time: 103ms
memory: 59132kb

input:

200000
2 2 2 1 1 0 1 0 0 1 1 0 0 1 0 0 0 2 0 0 2 0 0 1 1 2 1 0 2 1 1 1 2 2 1 0 0 2 2 0 0 1 2 0 0 1 2 2 0 1 1 1 1 1 0 2 2 2 1 0 2 1 0 1 0 2 1 0 0 0 1 0 2 1 2 0 0 0 0 2 2 2 2 0 0 1 0 1 1 0 1 2 2 2 2 2 2 2 1 0 0 2 1 0 2 0 2 2 0 0 2 1 2 0 2 2 0 2 0 0 1 0 2 1 1 2 2 1 1 2 1 2 0 0 2 2 0 0 0 2 0 0 1 2 1 0 1...

output:

33075374608087

result:

ok 

Test #22:

score: 6
Accepted
time: 101ms
memory: 59320kb

input:

200000
2 1 1 2 2 2 2 1 2 1 2 0 1 2 1 1 2 2 1 2 2 2 2 2 1 2 1 1 1 1 2 1 2 1 1 2 2 1 2 1 2 1 2 1 1 1 1 1 1 2 1 1 1 1 1 1 1 0 1 1 2 1 1 2 2 1 1 1 1 1 1 2 2 0 1 1 2 1 2 1 2 2 2 1 1 2 1 0 1 2 2 2 1 2 1 1 1 1 0 1 1 2 1 0 2 2 1 1 2 2 2 0 1 2 1 2 2 2 1 1 2 1 2 2 2 1 2 2 2 1 1 1 2 2 1 2 2 2 2 2 2 1 2 2 1 1 1...

output:

6216545751865

result:

ok 

Test #23:

score: 6
Accepted
time: 97ms
memory: 58936kb

input:

200000
2 0 2 0 0 2 0 2 0 2 2 2 0 2 2 2 0 2 2 0 2 2 2 2 0 2 0 0 0 2 2 2 2 0 2 2 0 0 0 2 2 0 0 0 2 0 2 0 0 2 2 0 2 2 0 0 0 2 2 0 0 2 0 0 0 0 2 2 0 2 0 0 2 2 2 0 0 0 0 0 0 0 2 2 2 2 2 1 0 0 2 1 2 0 2 2 0 0 0 0 0 0 0 2 0 0 0 0 0 0 2 0 0 2 0 0 2 0 0 0 2 2 2 2 0 2 0 0 0 2 2 0 2 2 0 0 0 2 2 0 0 2 2 2 2 2 2...

output:

6090130973914

result:

ok 

Test #24:

score: 6
Accepted
time: 113ms
memory: 58436kb

input:

200000
1 1 0 0 1 2 0 2 0 0 0 1 0 0 0 1 1 0 1 0 1 1 0 1 1 0 0 0 0 1 0 0 0 1 0 0 0 1 1 1 0 1 0 1 1 1 0 1 0 1 1 1 1 0 0 0 0 1 0 1 1 0 0 0 0 0 1 0 1 1 0 0 1 1 1 0 1 0 1 0 1 0 1 0 1 1 1 0 0 1 0 1 0 2 0 0 1 1 0 1 1 0 0 1 0 0 0 1 0 1 0 0 0 0 1 1 0 0 2 0 1 2 1 0 0 0 2 0 0 0 2 0 0 1 1 1 2 1 1 1 0 1 0 1 1 2 1...

output:

6392103279027

result:

ok 

Test #25:

score: 6
Accepted
time: 106ms
memory: 63956kb

input:

200000
0 0 0 2 1 1 1 0 0 1 1 2 0 2 1 2 2 0 0 2 0 2 2 1 0 2 1 2 2 2 2 0 1 1 1 1 1 1 1 1 1 2 2 1 0 2 0 1 0 1 2 0 0 2 0 2 0 0 1 0 2 2 0 0 1 0 2 1 1 0 1 0 2 0 2 0 1 2 2 1 1 0 1 2 0 1 2 1 2 0 0 0 1 0 1 2 2 0 1 1 0 0 0 1 1 2 0 0 2 2 0 0 2 2 2 2 1 0 0 1 1 1 2 2 2 2 0 0 0 1 1 1 0 1 1 2 1 1 1 0 0 2 1 0 2 0 1...

output:

98889219873489

result:

ok 

Test #26:

score: 6
Accepted
time: 0ms
memory: 17864kb

input:

3
0 0 1
1 2
0 2
0

output:

0

result:

ok 

Test #27:

score: 6
Accepted
time: 6ms
memory: 17880kb

input:

4
0 0 1 1
0 2
1 2
2 3
0

output:

0

result:

ok 

Test #28:

score: 6
Accepted
time: 0ms
memory: 17860kb

input:

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

output:

0

result:

ok 

Test #29:

score: 6
Accepted
time: 0ms
memory: 17952kb

input:

6
1 0 2 2 0 1
1 3
4 5
0 4
0 1
2 5
0

output:

4

result:

ok 

Test #30:

score: 6
Accepted
time: 109ms
memory: 54404kb

input:

200000
0 0 0 2 0 0 1 0 2 2 2 1 2 0 1 0 0 0 0 1 0 2 0 2 1 0 2 2 2 2 2 0 0 2 2 0 1 1 0 1 1 0 1 2 2 2 0 1 2 1 2 2 1 0 2 2 2 1 2 2 2 0 1 2 2 2 2 2 1 1 0 0 1 0 2 0 2 1 1 2 2 0 2 1 2 0 2 2 1 2 2 2 0 2 2 2 0 2 0 1 1 1 2 0 1 2 2 1 2 0 2 0 0 2 1 1 2 2 0 2 0 2 0 1 0 0 0 0 2 0 1 2 0 1 2 2 2 0 1 0 0 2 2 2 1 0 0...

output:

827878641518

result:

ok 

Test #31:

score: 6
Accepted
time: 98ms
memory: 54476kb

input:

200000
1 1 2 2 1 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 1 2 1 2 2 2 2 2 1 2 1 1 1 2 2 2 1 0 1 2 2 2 2 1 2 2 1 2 1 1 2 2 1 2 1 2 1 1 2 1 2 2 2 1 2 1 1 1 2 2 2 1 1 2 1 2 1 1 2 1 1 1 0 2 1 1 1 2 1 2 2 2 1 2 1 1 1 2 1 1 2 2 1 2 1 2 1 1 1 2 0 2 1 1 2 2 2 1 2 2 2 2 2 1 2 1 1 2 2 1 1 1 2 1 2 1 2 2 1 1 1 1 1 1 1...

output:

148910253102

result:

ok 

Test #32:

score: 6
Accepted
time: 118ms
memory: 54376kb

input:

200000
2 0 2 2 0 2 0 0 0 2 2 0 2 0 0 0 0 2 0 2 0 0 0 2 0 0 0 0 2 0 0 2 0 2 1 0 0 0 2 2 0 2 2 0 0 2 2 0 1 2 2 2 1 0 0 2 0 2 2 0 2 2 0 0 2 2 0 2 0 2 2 0 2 2 0 2 2 0 2 0 0 0 0 2 2 2 0 0 0 2 2 2 2 0 0 0 2 2 0 2 0 2 1 2 2 0 0 2 2 0 2 0 1 2 2 0 2 0 0 2 2 0 0 0 1 0 0 0 0 0 2 0 0 2 0 0 0 0 2 2 0 2 2 0 2 2 2...

output:

181252557212

result:

ok 

Test #33:

score: 6
Accepted
time: 127ms
memory: 54276kb

input:

200000
1 0 2 1 2 1 0 0 0 1 1 1 1 0 0 1 1 0 1 0 1 1 0 1 0 1 0 0 0 1 0 1 2 0 0 1 0 0 1 0 1 0 0 0 0 0 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 0 1 0 0 0 0 1 1 1 0 0 1 0 0 1 0 0 1 0 0 0 2 1 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 1 0 0 0 1 0 1 0 1 1 0 0 0 0 1 1 0 0 0 1 0 0 1 0 1 0 0 1 0 1 1 0 0 1 0 1 1 1 0 1 1 0 0 0...

output:

155843324547

result:

ok 

Test #34:

score: 6
Accepted
time: 65ms
memory: 53196kb

input:

200000
0 2 2 0 2 2 0 1 1 0 2 2 0 1 2 2 0 1 0 2 1 1 0 1 0 2 0 2 0 0 0 1 0 0 2 0 2 1 0 0 1 1 1 0 0 2 1 2 2 1 0 2 2 2 0 2 2 1 2 0 1 0 0 1 2 0 0 2 1 1 1 0 1 1 1 2 1 0 1 1 0 1 2 2 2 0 1 0 1 1 0 2 0 1 0 2 0 0 2 2 2 2 2 0 0 2 1 2 2 1 2 0 1 1 1 1 1 0 2 0 2 0 1 1 1 0 1 0 2 1 2 0 1 1 0 2 1 2 2 2 0 0 2 2 2 0 1...

output:

0

result:

ok 

Test #35:

score: 6
Accepted
time: 65ms
memory: 53300kb

input:

200000
2 1 2 0 2 1 2 1 2 1 1 1 2 1 2 1 2 1 1 1 1 2 0 1 2 1 1 2 1 2 2 2 1 2 2 2 1 2 2 1 1 1 2 2 1 1 2 2 1 2 1 1 2 2 1 2 2 2 1 2 2 2 1 2 1 1 2 2 2 1 1 2 2 1 1 2 1 2 1 1 2 1 2 2 2 1 1 1 2 2 2 2 1 1 1 2 1 1 2 1 1 2 1 2 2 2 2 1 1 2 1 2 2 1 1 1 2 1 1 1 2 0 2 1 2 2 1 1 2 2 2 2 1 1 1 1 2 1 1 2 2 2 1 1 1 1 2...

output:

0

result:

ok 

Test #36:

score: 6
Accepted
time: 61ms
memory: 53276kb

input:

200000
2 2 0 2 2 0 0 0 0 0 2 2 2 2 0 2 2 2 2 1 0 2 0 2 2 0 0 2 2 0 0 2 2 1 0 2 0 2 0 0 2 1 0 0 0 2 0 0 0 2 2 0 2 0 2 2 0 0 0 0 2 0 0 2 0 2 0 2 0 2 2 2 2 2 0 2 2 2 2 0 0 0 0 0 2 0 2 2 0 2 0 0 2 0 0 2 2 2 0 2 0 2 2 0 2 2 2 0 0 2 0 1 0 2 0 2 2 0 2 2 2 0 2 2 0 2 0 2 0 2 0 0 0 0 2 0 0 2 0 0 0 2 0 0 0 2 0...

output:

0

result:

ok 

Test #37:

score: 6
Accepted
time: 55ms
memory: 53232kb

input:

200000
1 0 0 1 2 0 0 0 1 1 0 1 1 0 1 0 0 0 0 0 0 1 1 0 1 0 0 0 0 1 0 0 1 1 1 0 0 1 1 1 2 0 0 0 1 1 0 0 1 0 1 0 1 0 1 0 0 0 1 1 1 0 1 1 0 1 0 1 0 0 0 0 0 1 2 1 0 1 1 1 1 0 1 2 1 0 1 0 1 0 1 0 0 1 1 0 0 1 1 0 1 0 0 0 1 1 0 1 0 1 0 1 0 0 1 1 0 0 0 0 0 1 1 1 0 0 0 0 1 1 1 0 1 1 0 1 0 1 0 1 0 1 2 1 0 0 1...

output:

598441952

result:

ok 

Subtask #4:

score: 0
Wrong Answer

Test #38:

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

input:

3
1 1 1
0 1
1 2
100
2 0
0 0
0 2
2 1
0 1
0 0
0 1
0 0
1 0
2 2
0 1
0 0
0 1
1 1
0 0
2 0
2 1
2 2
0 2
2 1
2 2
2 0
0 1
2 1
0 2
0 1
2 0
2 1
0 0
2 0
2 1
2 2
0 2
2 0
0 0
2 1
2 0
2 2
1 2
0 1
1 1
2 1
0 0
0 2
0 1
0 0
1 2
1 0
1 2
1 0
0 1
2 2
2 1
2 2
0 2
1 2
2 1
0 0
0 2
0 1
1 1
2 0
0 0
1 2
0 2
0 0
1 0
0 1
0 2
2 1
...

output:

0
0
0
1
0
0
0
0
0
0
0
0
0
0
-1
0
-1
-1
0
-1
-1
-1
0
-1
-1
-1
-1
-1
-1
-1
-1
-1
0
-1
0
-1
-1
-1
0
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-2
-2
-2
-2
-2
-2
-2
-2
-2
-2
-2
-2
-1
-2
-1
-2
-2
-2

result:

wrong answer 

Subtask #5:

score: 0
Wrong Answer

Test #60:

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

input:

3
2 0 0
0 1
0 2
100
0 1
2 2
2 1
1 1
0 0
2 2
1 2
0 2
0 1
0 0
0 1
0 2
2 1
1 0
2 2
2 0
0 0
0 2
1 1
1 2
2 2
2 1
0 0
2 2
0 1
1 0
0 0
2 0
1 1
1 0
2 1
2 0
0 2
0 1
2 2
1 1
0 0
0 1
2 1
0 0
2 0
0 1
2 1
2 0
0 2
2 2
0 1
2 0
0 0
0 1
2 1
0 2
0 1
0 2
2 2
1 0
1 1
1 2
1 0
1 2
1 0
0 0
1 1
0 1
1 0
2 0
1 2
1 0
0 2
0 0
...

output:

0
0
1
0
0
0
0
0
0
-1
0
-1
0
0
0
0
0
0
0
0
0
0
0
0
0
-1
0
0
0
0
0
0
0
0
0
1
0
1
0
0
0
0
0
0
0
0
0
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-2
-1
-2
-1
-2
-2
-2
-2
-2
-2
-2
-2
-2
-2
-2
-2
-2
-2
-2
-2
-2
-3
-2
-3
-3
-3
-3
-3
-3
-3
-3
-3
-3
-3
-3
-3
-3

result:

wrong answer 

Subtask #6:

score: 0
Skipped

Dependency #2:

0%

Subtask #7:

score: 0
Skipped

Dependency #1:

0%