QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#469618#8730. ParticijaPorNPtree61 80ms27808kbC++175.3kb2024-07-09 21:03:352024-07-09 21:03:35

Judging History

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

  • [2024-07-09 21:03:35]
  • 评测
  • 测评结果:61
  • 用时:80ms
  • 内存:27808kb
  • [2024-07-09 21:03:35]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 5;

int n, a[N], b[N], col[N << 1], c[2];
vector<int> G[N << 1];

void dfs(int x) {
    ++c[col[x]];
    for (auto v : G[x]) if (!~col[v]) col[v] = !col[x], dfs(v);
}

int dfn[N << 1], low[N << 1], mx;

pair<int, int> Tarjan(int x, int fa = 0) {
    dfn[x] = low[x] = ++dfn[0];
    pair<int, int> p = make_pair(!col[x], col[x]);
    for (auto v : G[x]) if (v != fa) {
        if (!dfn[v]) {
            pair<int, int> q = Tarjan(v, x);
            p.first += q.first, p.second += q.second;
            low[x] = min(low[x], low[v]);
        } else low[x] = min(low[x], dfn[v]);
    } else fa = 0;
    if (low[x] == dfn[x]) {
        mx = max(mx, min(c[0], c[1]) - min(p.first, p.second) - min(c[0] - p.first, c[1] - p.second));
    }
    return p;
}

multiset< pair<int, pair<int, int> > > S;
pair<int, int> cz;

pair<int, int> Tarj(int x, int fa = 0) {
    dfn[x] = low[x] = ++dfn[0];
    int tv = fa;
    pair<int, int> p = make_pair(!col[x], col[x]);
    for (auto v : G[x]) if (v != fa) {
        if (!dfn[v]) {
            pair<int, int> q = Tarj(v, x);
            p.first += q.first, p.second += q.second;
            low[x] = min(low[x], low[v]);
        } else low[x] = min(low[x], dfn[v]);
    } else fa = 0;
    if (!tv) return p;
    if (low[x] == dfn[x]) {
        S.erase(S.find(make_pair(cz.first - cz.second, cz)));
        S.insert(make_pair(p.first - p.second, p));
        int v1, v2, v3, v4;
        v1 = cz.first - p.first, v2 = cz.second - p.second;
        tie(v3, v4) = (*S.begin()).second;
        mx = max(mx, min(v1 + v3, v2 + v4) - min(v1, v2) - min(v3, v4) + min(p.first, p.second) + min(cz.first - p.first, cz.second - p.second) - min(cz.first, cz.second));
        v1 = cz.first - p.first, v2 = cz.second - p.second;
        tie(v3, v4) = (*--S.end()).second;
        mx = max(mx, min(v1 + v3, v2 + v4) - min(v1, v2) - min(v3, v4) + min(p.first, p.second) + min(cz.first - p.first, cz.second - p.second) - min(cz.first, cz.second));
        S.erase(S.find(make_pair(p.first - p.second, p)));
        S.insert(make_pair((cz.first - p.first) - (cz.second - p.second), make_pair(cz.first - p.first, cz.second - p.second)));
        v1 = p.first, v2 = p.second;
        tie(v3, v4) = (*S.begin()).second;
        mx = max(mx, min(v1 + v3, v2 + v4) - min(v1, v2) - min(v3, v4) + min(p.first, p.second) + min(cz.first - p.first, cz.second - p.second) - min(cz.first, cz.second));
        v1 = p.first, v2 = p.second;
        tie(v3, v4) = (*--S.end()).second;
        mx = max(mx, min(v1 + v3, v2 + v4) - min(v1, v2) - min(v3, v4) + min(p.first, p.second) + min(cz.first - p.first, cz.second - p.second) - min(cz.first, cz.second));
        S.erase(S.find(make_pair((cz.first - p.first) - (cz.second - p.second), make_pair(cz.first - p.first, cz.second - p.second))));
        S.insert(make_pair(cz.first - cz.second, cz));
    } else {
        S.erase(S.find(make_pair(cz.first - cz.second, cz)));
        if (!S.empty()) {
            int v1, v2, v3, v4;
            v1 = cz.first, v2 = cz.second;
            tie(v3, v4) = (*S.begin()).second;
            mx = max(mx, min(v1 + v3, v2 + v4) - min(v1, v2) - min(v3, v4));
            v1 = cz.first, v2 = cz.second;
            tie(v3, v4) = (*--S.end()).second;
            mx = max(mx, min(v1 + v3, v2 + v4) - min(v1, v2) - min(v3, v4));
        }
        S.insert(make_pair(cz.first - cz.second, cz));
    }
    return p;
}

signed main() {
    int T, opt; scanf("%d%d", &T, &opt);
    while (T--) {
        scanf("%d", &n);
        for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
        for (int i = 1; i <= n; ++i) scanf("%d", &b[i]);
        for (int i = 1; i <= n << 1; ++i) G[i].clear(), col[i] = -1;
        for (int i = 1; i <= n; ++i) {
            G[a[i]].push_back(b[i] + n), G[b[i] + n].push_back(a[i]);
        }
        if (opt == 0) {
            int res = 0;
            for (int i = 1; i <= n << 1; ++i) if (!~col[i]) {
                c[0] = c[1] = 0, col[i] = 0, dfs(i), res += min(c[0], c[1]);
            }
            printf("%d\n", res);
        } else if (opt == 1) {
            if (n == 1) {
                puts("1");
                continue;
            }
            int res = 0;
            for (int i = 0; i <= n << 1; ++i) dfn[i] = 0;
            mx = 0;
            for (int i = 1; i <= n << 1; ++i) if (!~col[i]) {
                c[0] = c[1] = 0, col[i] = 0, dfs(i), res += min(c[0], c[1]);
                Tarjan(i);
            }
            printf("%d\n", res - mx);
        } else {
            int res = 0;
            S.clear();
            vector< pair<int, int> > arr;
            for (int i = 1; i <= n << 1; ++i) if (!~col[i]) {
                c[0] = c[1] = 0, col[i] = 0, dfs(i), res += min(c[0], c[1]);
                S.insert(make_pair(c[0] - c[1], make_pair(c[0], c[1])));
                arr.push_back(make_pair(c[0], c[1]));
            }
            for (int i = 0; i <= n << 1; ++i) dfn[i] = 0;
            mx = 0;
            int now = 0;
            for (int i = 1; i <= n << 1; ++i) if (!dfn[i]) {
                cz = arr[now++];
                Tarj(i);
            }
            printf("%d\n", res + mx);
        }
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 7
Accepted

Test #1:

score: 7
Accepted
time: 0ms
memory: 16356kb

input:

751 0
5
5 5 5 5 5
1 2 3 4 5
6
1 2 2 6 4 5
3 6 3 4 3 3
8
5 8 6 5 4 3 6 6
3 4 4 3 2 6 6 2
5
1 1 1 1 1
5 5 4 3 3
8
5 7 3 7 8 2 7 5
4 2 6 3 6 2 5 6
8
5 8 7 3 4 6 5 2
3 3 3 3 3 3 1 3
6
2 1 3 1 3 6
5 5 3 6 3 5
8
8 6 2 4 7 7 4 1
7 7 3 3 7 7 3 3
5
2 1 4 4 2
1 2 1 4 1
6
2 2 2 2 2 2
5 3 2 1 4 6
7
4 1 7 4 2 3 ...

output:

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

result:

ok 751 numbers

Subtask #2:

score: 23
Accepted

Dependency #1:

100%
Accepted

Test #2:

score: 23
Accepted
time: 29ms
memory: 16132kb

input:

10000 0
1
1
1
22
3 20 22 15 8 18 14 19 15 11 18 15 15 19 20 14 10 20 19 4 18 20
22 19 9 17 2 17 8 9 22 22 8 2 15 9 19 6 15 17 9 22 22 1
6
4 1 4 1 4 4
2 2 3 3 3 2
2
1 1
2 2
65
16 27 7 58 30 4 58 59 30 45 27 58 65 15 20 26 58 48 58 25 4 39 4 16 28 28 28 33 59 30 59 19 48 41 59 58 4 65 25 20 59 42 45 5...

output:

1
9
2
1
22
1
15
3
10
1
1
2
1
2
1
10
1
2
5
3
1
17
4
4
1
5
22
1
1
2
11
5
9
4
6
2
2
7
4
8
1
1
1
1
1
6
3
4
8
9
21
1
2
1
1
2
5
5
5
1
1
3
5
5
1
6
1
4
3
1
2
1
10
1
1
11
1
1
1
17
38
2
11
4
5
1
4
1
4
2
16
5
4
25
4
23
8
9
5
6
5
1
3
1
1
1
2
2
1
1
1
2
2
3
38
24
5
5
2
4
4
2
9
7
1
6
35
4
1
3
8
8
12
4
12
2
6
2
4
1...

result:

ok 10000 numbers

Test #3:

score: 0
Accepted
time: 26ms
memory: 16116kb

input:

10000 0
5
2 4 5 3 1
3 3 3 3 3
39
3 5 24 31 18 26 12 18 16 27 1 2 20 20 4 34 4 20 14 38 2 34 13 10 25 31 23 20 2 31 30 35 22 31 6 36 29 21 22
22 4 30 11 35 14 11 10 14 21 18 10 10 22 10 10 18 29 9 4 4 9 10 10 21 36 35 13 16 34 16 18 29 31 34 10 29 9 20
42
12 13 22 25 13 11 11 3 11 13 19 41 3 20 38 11...

output:

1
16
6
12
23
24
3
4
6
3
21
5
15
3
7
7
2
10
6
8
1
2
5
3
15
2
9
3
1
19
3
15
9
1
7
1
2
2
1
6
1
9
1
2
3
8
4
11
3
12
10
14
1
2
1
2
5
14
3
4
1
24
9
3
4
9
5
5
13
1
9
3
1
1
7
1
11
9
14
3
4
6
3
6
1
5
5
1
14
8
4
5
13
4
21
4
1
18
1
1
7
1
21
29
2
12
6
4
2
1
1
1
7
4
1
1
25
2
3
3
4
4
23
2
8
1
1
14
5
3
3
10
7
2
5
...

result:

ok 10000 numbers

Test #4:

score: 0
Accepted
time: 26ms
memory: 16140kb

input:

10000 0
42
22 41 38 29 7 20 32 9 17 1 14 19 40 17 39 26 31 12 37 10 35 24 30 8 8 34 4 11 33 36 25 17 23 36 25 15 28 38 16 2 42 21
13 24 24 23 23 41 13 23 23 23 23 13 24 24 13 24 13 41 23 13 23 24 41 27 13 24 24 24 13 24 13 13 24 36 41 24 23 36 27 13 13 13
3
3 3 3
2 2 1
4
4 2 1 1
2 2 2 2
7
2 6 6 3 6 ...

output:

6
1
1
2
4
7
17
7
2
2
2
2
1
6
19
11
7
2
13
1
10
2
1
15
2
8
2
1
3
2
2
1
1
5
1
7
4
5
1
17
6
11
8
1
16
1
2
5
1
12
4
1
17
1
1
4
4
12
2
1
1
32
22
5
1
1
51
1
1
3
5
5
1
5
5
8
1
7
2
4
2
3
4
9
1
1
1
1
5
2
6
2
1
4
1
16
3
3
1
3
11
6
2
4
6
12
1
1
6
4
1
7
1
5
1
5
1
4
2
6
5
1
1
2
4
4
14
1
26
1
2
10
2
5
10
2
11
1
2...

result:

ok 10000 numbers

Test #5:

score: 0
Accepted
time: 50ms
memory: 24620kb

input:

1 0
200000
187537 18767 101813 163606 48410 170649 76822 130218 89330 118401 172319 59998 23511 38330 144493 25491 8802 151268 189229 12042 4447 90944 3117 74158 20010 127637 161507 144844 81563 30958 14332 56186 135755 152121 71529 70034 79871 110696 85775 153001 135318 169390 85445 93814 32413 848...

output:

51015

result:

ok 1 number(s): "51015"

Test #6:

score: 0
Accepted
time: 64ms
memory: 24144kb

input:

1 0
200000
35028 121987 18839 127027 111261 194927 82719 113384 153997 35176 27076 183194 48387 128670 189053 112598 195273 194243 41109 180804 108702 177398 9342 45879 199964 197302 37350 17230 49346 57628 41197 170195 92073 107978 94705 171598 61622 70349 81374 111639 31947 13890 51348 79679 785 1...

output:

55719

result:

ok 1 number(s): "55719"

Test #7:

score: 0
Accepted
time: 61ms
memory: 24176kb

input:

1 0
200000
138519 168476 183840 134736 190461 5116 13667 159468 133786 4190 119815 130598 141492 33050 40906 139150 151429 101609 18214 120314 164914 138694 108838 154071 80487 94010 93009 38605 112559 140771 141675 16819 76448 113377 36185 115247 139527 117111 15998 148912 177636 29482 177219 17397...

output:

44165

result:

ok 1 number(s): "44165"

Test #8:

score: 0
Accepted
time: 56ms
memory: 23020kb

input:

1 0
200000
3513 67285 198547 32776 5797 143977 34496 176480 75284 72200 82905 116098 40986 199651 70240 90517 147287 14722 26032 90245 19925 80740 150300 91991 162748 29580 104389 127295 84353 172689 90217 126969 189559 117484 90336 153782 192791 125420 172800 48998 130350 43857 173431 23110 143590 ...

output:

47160

result:

ok 1 number(s): "47160"

Test #9:

score: 0
Accepted
time: 65ms
memory: 23316kb

input:

1 0
200000
83034 29934 7639 53738 86571 112470 188606 151239 174639 115197 160615 90066 70477 69825 71274 13167 157710 175588 184042 9329 195761 54008 133119 126080 123098 53084 22530 29648 108438 4312 105264 184797 71622 172887 184926 79439 143700 79447 174229 193304 64335 6959 12576 100452 94876 3...

output:

59514

result:

ok 1 number(s): "59514"

Test #10:

score: 0
Accepted
time: 59ms
memory: 24940kb

input:

1 0
200000
71735 59782 40990 159955 158396 61677 120140 108108 90472 120033 93945 159982 173388 111158 91048 38935 137669 127656 185936 153538 178865 4112 11119 21865 127899 8673 24290 154377 160836 139774 67706 95473 106305 94872 182031 185824 1449 173005 67567 184610 91139 142203 8189 20355 80902 ...

output:

59388

result:

ok 1 number(s): "59388"

Test #11:

score: 0
Accepted
time: 54ms
memory: 23452kb

input:

1 0
200000
75179 83698 165139 112108 56661 40923 34829 22484 96146 29060 71444 119149 21277 50989 105192 160539 1085 167863 131915 182220 57630 196589 4991 84041 49825 102945 192364 186625 72791 154368 185326 88337 96848 70737 40769 100184 111261 115171 65620 198383 18518 154456 106359 116713 110737...

output:

48580

result:

ok 1 number(s): "48580"

Test #12:

score: 0
Accepted
time: 53ms
memory: 24388kb

input:

1 0
200000
186148 38986 30647 142364 182882 35923 161993 54055 116406 23087 153956 22532 142684 60155 64145 9603 5183 17445 159714 12970 185475 54218 24157 84518 45909 47548 91423 158033 122406 28216 165342 12747 12658 42337 103290 29555 164211 197186 181766 122891 178563 5498 15663 157410 181528 16...

output:

21886

result:

ok 1 number(s): "21886"

Test #13:

score: 0
Accepted
time: 59ms
memory: 25016kb

input:

1 0
200000
130206 46063 98170 21224 6304 60015 55867 151125 157945 191346 117918 133897 94404 113743 181378 3827 92280 122192 90462 40961 30650 82537 30753 42205 66585 184818 173919 151847 16997 121028 113142 25101 37747 85759 98605 48681 126382 48717 158856 34089 5221 20482 107091 92811 90437 32241...

output:

50093

result:

ok 1 number(s): "50093"

Subtask #3:

score: 15
Accepted

Test #14:

score: 15
Accepted
time: 0ms
memory: 18408kb

input:

719 1
8
1 1 2 1 5 1 5 1
2 5 6 1 4 4 8 7
5
5 5 5 5 5
1 4 1 2 5
8
5 2 4 7 8 6 1 3
4 4 4 4 4 4 4 4
7
4 5 5 4 4 5 5
1 7 5 3 6 2 4
5
1 4 4 5 2
1 4 2 1 3
2
1 2
2 1
8
6 8 6 2 8 4 5 6
3 4 7 4 8 8 8 4
8
2 7 2 7 2 2 2 2
3 4 1 3 8 5 7 4
8
3 3 2 8 5 6 4 4
4 7 7 4 7 7 8 7
5
2 4 4 4 4
5 2 3 1 4
6
1 1 1 1 1 1
6 5 ...

output:

2
1
1
2
2
1
3
2
2
1
1
3
2
1
1
1
2
2
2
2
2
1
1
1
1
2
1
2
1
1
3
2
2
1
2
2
3
2
2
2
2
1
1
2
3
3
1
1
3
2
2
1
2
2
2
2
3
3
1
2
1
1
3
1
3
2
2
3
3
2
1
1
2
3
1
2
1
2
2
2
1
2
1
3
1
2
1
2
2
2
2
2
2
1
2
2
1
1
1
3
2
2
1
1
1
1
2
1
1
1
1
2
2
1
2
3
1
3
1
2
1
3
2
1
2
2
2
2
2
2
3
3
1
2
2
1
1
2
2
1
1
2
4
1
1
1
2
2
2
2
...

result:

ok 719 numbers

Test #15:

score: 0
Accepted
time: 8ms
memory: 18144kb

input:

4998 1
8
8 6 4 7 7 2 2 4
4 4 4 5 5 7 7 4
9
6 1 7 7 2 9 3 6 5
8 8 8 8 8 8 8 8 8
3
3 2 1
2 2 2
17
12 12 11 3 16 11 12 17 12 16 12 10 12 6 17 3 17
5 6 5 8 11 6 10 11 11 1 8 16 14 5 8 1 2
21
12 21 4 21 12 9 4 8 3 12 5 12 5 16 11 12 9 3 21 5 12
18 17 17 2 3 21 17 21 14 12 5 12 15 8 11 18 11 14 2 21 18
7
...

output:

3
1
1
6
8
2
2
4
1
1
1
1
2
1
1
1
1
5
2
3
10
1
3
1
4
5
1
1
3
3
1
4
2
1
1
6
4
2
1
1
1
1
2
1
17
3
8
4
7
1
1
1
5
5
6
3
1
1
1
1
1
4
2
6
1
1
1
1
4
5
10
2
1
1
21
1
5
1
1
14
1
1
2
1
4
1
1
2
2
1
8
1
8
4
3
1
1
1
1
4
1
2
1
1
6
2
1
4
3
4
4
5
1
4
5
5
1
3
3
5
2
20
2
1
7
2
1
1
1
2
1
8
4
1
1
2
2
4
1
5
4
1
2
6
2
1
1
...

result:

ok 4998 numbers

Test #16:

score: 0
Accepted
time: 7ms
memory: 16084kb

input:

4996 1
12
3 11 8 12 10 10 8 9 5 10 12 7
9 6 9 1 7 5 6 11 7 12 8 9
5
1 3 2 2 4
1 1 1 3 3
2
1 2
2 1
4
3 1 1 4
4 4 2 4
2
1 2
1 1
1
1
1
5
4 5 2 3 1
2 5 2 1 2
7
4 2 5 4 7 5 7
2 6 7 5 2 6 1
3
3 2 1
3 1 1
2
1 2
1 1
1
1
1
1
1
1
15
15 12 3 6 5 10 2 10 11 4 9 1 10 11 14
14 11 5 4 4 11 11 5 11 5 4 4 9 14 11
7
...

output:

5
2
1
1
1
1
2
3
1
1
1
1
4
1
1
1
1
5
1
2
2
2
3
2
1
2
5
2
31
1
2
19
1
2
2
1
1
3
8
1
4
20
8
3
1
7
2
2
5
1
1
1
1
1
6
4
3
1
6
1
2
2
3
2
3
3
1
5
1
2
3
1
11
4
2
4
1
2
1
1
15
4
3
1
3
1
1
2
6
1
2
4
5
3
3
10
2
1
4
1
1
5
1
2
11
1
1
6
1
5
1
7
1
5
1
2
1
6
3
5
5
2
6
2
4
2
7
2
6
1
7
11
1
1
2
3
3
8
2
3
7
1
1
1
2
7
...

result:

ok 4996 numbers

Test #17:

score: 0
Accepted
time: 12ms
memory: 16088kb

input:

5000 1
4
4 1 1 1
1 1 1 1
8
6 8 3 5 6 5 3 6
2 8 4 2 8 5 6 6
18
2 2 13 11 16 11 11 14 11 13 13 11 16 11 17 7 4 13
11 1 16 12 12 4 11 10 3 8 10 14 9 9 1 11 11 11
4
2 4 3 3
2 2 2 2
4
3 4 4 3
3 1 3 4
2
2 2
2 2
2
1 1
1 1
2
2 1
2 2
10
5 2 6 6 6 5 4 6 6 6
10 7 1 7 1 3 7 9 7 10
4
3 3 3 3
4 4 4 4
9
7 3 5 7 3 ...

output:

1
3
7
1
2
1
1
1
3
1
3
1
7
5
3
1
1
1
3
3
1
1
3
4
5
2
1
4
1
3
1
2
1
1
1
3
9
1
2
1
1
1
1
1
1
1
5
1
2
1
4
2
2
6
3
1
1
4
4
2
6
3
1
1
7
1
5
1
1
1
13
3
1
1
1
7
2
2
1
4
2
11
1
2
1
3
8
1
1
1
1
10
1
1
2
1
1
2
3
2
1
2
2
3
1
2
1
1
6
2
1
5
3
13
3
3
5
2
1
2
1
2
1
1
7
3
5
1
1
2
1
1
1
2
1
1
15
2
1
2
1
1
2
1
2
1
1
1...

result:

ok 5000 numbers

Test #18:

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

input:

1 1
1000
633 994 363 66 897 652 945 525 339 813 479 735 9 729 294 9 655 424 633 387 476 315 193 343 640 331 561 841 652 960 946 388 106 273 485 344 797 691 719 787 279 37 215 982 975 945 323 596 311 591 331 385 395 786 221 157 243 786 864 256 732 395 82 802 117 423 208 968 365 935 362 459 443 121 33...

output:

248

result:

ok 1 number(s): "248"

Test #19:

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

input:

1 1
1000
179 574 133 562 425 802 55 15 889 624 248 622 628 800 34 579 776 789 404 550 351 226 167 83 623 580 15 945 499 793 455 777 862 733 37 410 571 70 64 308 581 127 335 239 169 550 675 462 814 710 326 462 297 601 698 682 169 198 280 793 549 273 550 836 269 193 258 239 705 135 714 378 870 427 956...

output:

278

result:

ok 1 number(s): "278"

Test #20:

score: 0
Accepted
time: 4ms
memory: 16120kb

input:

1 1
1000
898 691 835 424 7 666 117 986 612 789 467 4 172 789 385 1 986 353 352 928 967 384 129 46 410 575 385 835 114 998 900 298 163 966 772 302 51 939 53 327 842 651 944 351 528 338 774 587 332 53 545 762 715 183 708 837 636 247 829 836 504 210 219 450 836 254 772 308 176 424 443 708 953 308 434 8...

output:

207

result:

ok 1 number(s): "207"

Test #21:

score: 0
Accepted
time: 4ms
memory: 18156kb

input:

1 1
1000
741 709 192 79 802 741 571 530 597 387 826 351 684 704 276 220 383 36 251 382 269 340 201 794 841 64 579 511 424 983 647 938 17 611 80 950 53 106 294 904 396 511 192 692 500 602 98 592 64 581 464 213 633 30 627 168 157 530 600 112 678 954 962 674 637 922 209 597 773 765 206 171 568 846 370 ...

output:

233

result:

ok 1 number(s): "233"

Test #22:

score: 0
Accepted
time: 4ms
memory: 18156kb

input:

1 1
1000
240 83 712 773 844 867 597 292 483 939 212 444 418 234 610 599 348 319 80 24 163 55 573 851 664 740 274 491 260 17 890 141 720 840 653 900 958 180 739 517 837 14 399 352 405 734 904 253 230 757 90 594 908 129 588 40 731 67 653 653 14 464 975 811 842 84 1 530 696 775 797 420 846 533 463 65 8...

output:

263

result:

ok 1 number(s): "263"

Test #23:

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

input:

1 1
1000
790 545 546 830 38 741 712 434 192 729 837 417 350 944 905 478 722 960 70 480 327 103 474 313 729 481 391 494 155 166 253 15 97 553 192 15 329 326 396 329 419 287 247 960 120 746 969 553 403 202 662 247 208 674 851 474 881 647 674 232 712 958 72 87 653 162 976 433 2 222 110 326 440 572 881 ...

output:

341

result:

ok 1 number(s): "341"

Test #24:

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

input:

1 1
1000
90 30 659 547 306 39 69 539 758 339 72 549 115 348 561 213 95 47 990 329 994 836 619 565 78 3 927 622 613 505 233 881 32 407 578 562 239 776 22 498 302 686 147 596 121 247 544 211 935 609 807 78 322 904 340 87 808 544 284 690 264 265 360 704 792 425 661 651 567 983 703 469 747 995 944 615 7...

output:

249

result:

ok 1 number(s): "249"

Test #25:

score: 0
Accepted
time: 3ms
memory: 16212kb

input:

1 1
1000
554 963 963 226 756 601 650 771 846 300 651 98 756 313 165 877 952 650 637 70 79 846 165 313 70 884 795 342 19 650 922 841 587 952 631 910 340 663 884 627 517 474 580 846 846 383 782 877 587 895 663 949 342 515 70 70 474 313 895 782 909 739 55 19 739 739 846 795 841 841 342 474 70 958 696 6...

output:

95

result:

ok 1 number(s): "95"

Test #26:

score: 0
Accepted
time: 4ms
memory: 18152kb

input:

1 1
1000
500 687 186 491 239 925 191 835 279 26 428 999 403 610 333 886 233 438 876 736 297 957 443 80 296 231 921 629 687 526 202 427 936 39 357 730 982 324 876 857 994 581 589 471 631 203 540 911 903 97 471 833 541 225 604 388 696 382 581 629 428 203 810 952 952 288 480 913 604 116 662 408 756 722...

output:

473

result:

ok 1 number(s): "473"

Subtask #4:

score: 16
Accepted

Dependency #3:

100%
Accepted

Test #27:

score: 16
Accepted
time: 2ms
memory: 18108kb

input:

736 1
8
7 2 2 2 2 2 7 2
2 8 5 4 6 1 3 3
7
1 5 1 4 4 1 1
1 7 2 2 7 4 6
8
4 6 4 5 4 1 7 4
5 4 4 8 1 4 4 4
7
3 2 4 3 4 2 2
7 4 6 6 7 2 6
7
1 4 1 1 1 1 4
6 4 1 7 4 3 2
8
1 7 5 1 1 7 5 7
5 1 5 2 3 3 6 5
7
1 7 7 1 7 1 7
7 3 5 3 2 5 4
8
6 8 6 8 6 8 6 8
7 1 4 5 5 6 8 3
6
4 1 3 2 1 5
5 3 5 5 2 5
8
5 7 1 8 7 ...

output:

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

result:

ok 736 numbers

Test #28:

score: 0
Accepted
time: 29ms
memory: 18152kb

input:

10000 1
1
1
1
92
3 74 7 4 40 5 9 56 70 64 1 6 56 47 9 17 67 92 2 9 72 48 28 9 9 77 82 45 9 53 63 24 9 90 9 69 84 79 10 65 41 14 32 34 60 19 12 21 80 18 9 59 9 47 71 32 42 9 23 9 9 30 46 28 45 11 29 83 28 79 36 9 37 89 81 14 9 46 68 75 9 38 5 8 43 22 82 44 6 9 85 91
45 45 37 37 26 82 58 35 45 37 37 3...

output:

1
11
11
6
4
5
1
12
3
1
13
1
8
1
2
1
3
9
3
5
9
7
1
2
2
3
3
13
10
1
1
2
6
3
11
1
2
2
1
1
5
1
3
2
30
5
4
4
4
5
1
1
5
6
2
7
5
1
1
2
9
3
2
2
1
16
30
19
8
6
1
6
9
4
5
1
1
4
2
9
2
13
30
2
1
1
1
7
2
1
3
21
5
1
6
2
2
1
2
1
9
3
5
3
1
1
3
8
7
9
2
1
1
1
1
1
6
16
4
1
2
1
1
3
4
5
4
2
2
17
5
5
3
2
3
2
1
1
16
10
15...

result:

ok 10000 numbers

Test #29:

score: 0
Accepted
time: 33ms
memory: 16068kb

input:

10000 1
46
11 3 23 15 39 18 39 30 41 38 5 23 7 37 20 16 34 13 1 25 40 44 36 30 28 10 42 9 7 22 44 5 19 45 2 27 12 39 44 25 28 29 39 24 31 8
29 29 36 5 32 29 46 7 29 29 43 9 2 29 29 29 29 29 31 9 29 14 5 11 9 29 9 29 29 29 5 36 36 32 14 29 36 31 4 30 6 29 16 29 29 9
14
4 11 13 13 3 7 1 2 9 6 14 7 8 1...

output:

13
2
4
8
8
5
2
4
2
5
19
1
6
10
1
32
2
9
1
2
9
7
1
1
8
1
11
5
7
14
3
7
1
1
19
5
16
3
7
2
2
1
3
1
11
2
2
2
6
22
5
7
1
11
7
2
2
1
2
1
2
6
1
19
8
15
4
15
23
34
1
8
3
3
8
8
1
1
3
1
5
8
4
4
1
2
1
1
8
13
11
15
1
2
8
1
12
5
17
2
6
1
4
11
3
2
1
4
1
2
7
1
3
10
2
7
1
15
2
5
2
13
2
3
15
4
1
1
4
3
1
5
14
1
2
1
2...

result:

ok 10000 numbers

Test #30:

score: 0
Accepted
time: 29ms
memory: 18188kb

input:

10000 1
7
7 7 7 7 7 7 7
5 5 1 7 4 3 1
7
3 4 4 4 6 7 4
4 4 2 1 2 1 6
11
10 2 4 11 7 5 2 11 8 4 11
8 5 4 8 5 8 4 1 5 7 4
23
8 2 2 8 2 2 2 2 2 10 10 2 2 2 8 8 8 8 2 2 10 2 8
8 2 17 23 21 7 13 6 20 15 14 10 15 12 22 18 5 19 9 18 11 1 3
3
2 2 2
3 3 3
23
8 16 22 12 10 17 4 18 11 14 5 23 16 20 21 18 19 15 ...

output:

1
3
4
3
1
3
6
1
6
14
1
1
1
1
2
1
2
12
6
1
9
1
13
4
9
8
10
1
6
12
1
1
2
14
2
5
1
3
6
11
1
1
4
1
5
1
4
6
4
2
13
1
1
2
2
15
7
7
17
11
34
2
4
1
6
2
1
3
12
10
4
1
11
1
1
1
9
6
1
1
1
2
6
4
9
3
34
2
11
6
6
3
1
4
6
29
8
1
3
12
3
1
1
1
1
3
1
1
3
2
1
18
3
1
1
2
8
6
4
5
1
1
4
12
6
26
1
1
6
5
3
18
2
2
1
4
11
3
...

result:

ok 10000 numbers

Test #31:

score: 0
Accepted
time: 74ms
memory: 26092kb

input:

1 1
200000
152716 61247 110532 28736 162558 10205 149834 38265 148755 106426 122820 30352 88550 100163 116927 99364 31104 99401 185496 123827 169456 15660 128395 112719 82779 117942 36568 34830 116661 64044 9157 26775 20146 23713 172346 70146 141692 103196 58439 63131 187620 121200 98786 21101 17547...

output:

50848

result:

ok 1 number(s): "50848"

Test #32:

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

input:

1 1
200000
79408 71299 9709 91315 136219 21079 65255 187194 155800 179436 6085 138759 132393 168454 144574 23207 55025 140485 169719 175481 145738 139751 154654 174764 181620 122865 116184 182067 59757 88140 102136 4554 39678 85258 138693 45173 98603 102038 86879 32734 191328 23861 154912 52080 8722...

output:

55224

result:

ok 1 number(s): "55224"

Test #33:

score: 0
Accepted
time: 74ms
memory: 26276kb

input:

1 1
200000
126216 2827 154559 187802 81950 4595 183581 166973 157942 168327 26522 44001 69156 73722 189942 7637 43365 150222 193995 18331 147607 197974 136123 122325 30673 34712 61801 22400 7293 130511 28920 46636 164316 156823 76919 98417 10403 195790 44278 56959 63172 63299 75751 130676 103432 124...

output:

38065

result:

ok 1 number(s): "38065"

Test #34:

score: 0
Accepted
time: 64ms
memory: 26628kb

input:

1 1
200000
106929 194533 90264 38304 13117 187726 67748 32162 60832 100003 180178 180303 166173 190804 54627 35729 148106 197338 23637 180092 31476 105800 13517 1983 104661 119058 96321 15134 194429 59438 117523 156947 58804 8153 14839 70418 21636 181451 130748 61192 9802 178424 195417 38073 15666 1...

output:

33795

result:

ok 1 number(s): "33795"

Test #35:

score: 0
Accepted
time: 63ms
memory: 26100kb

input:

1 1
200000
189965 30507 148210 111730 47313 181835 171929 37857 161390 8544 30077 120819 160591 42393 105251 116340 104384 93734 57914 114389 145376 39620 87729 158798 170907 69782 137907 129939 94680 53552 17150 177162 42663 157177 141319 192357 79453 69828 133983 108921 22223 158314 178564 2189 18...

output:

53965

result:

ok 1 number(s): "53965"

Test #36:

score: 0
Accepted
time: 65ms
memory: 27808kb

input:

1 1
200000
66833 175249 86731 46951 63249 57675 21990 51882 70840 184957 139350 157419 18817 168128 78684 144390 39163 184865 34998 91604 151753 180200 165159 68651 39017 71793 123502 32055 190881 119493 4603 9482 175249 183599 102162 120044 55746 89639 128562 73921 37158 152977 159988 164809 150710...

output:

28431

result:

ok 1 number(s): "28431"

Test #37:

score: 0
Accepted
time: 80ms
memory: 26212kb

input:

1 1
200000
13548 51166 39297 77082 2831 146102 33920 2535 45889 42509 174941 132682 44671 36691 186936 116239 59472 172171 182840 126446 105134 183334 159596 191586 58057 144278 48362 95043 83781 62123 9834 143316 96103 12726 68048 70645 160872 64844 191570 146919 125116 111523 50882 50860 174776 16...

output:

95873

result:

ok 1 number(s): "95873"

Test #38:

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

input:

1 1
200000
61686 79794 30914 179831 116905 148884 130231 169435 144863 45286 56480 158325 87460 151161 159800 113099 106547 94662 62485 165357 130604 145593 199784 178429 141202 94669 168072 44143 169632 111985 57474 113655 6215 143894 46316 48734 160398 89004 46224 120453 108735 131195 48026 157758...

output:

81109

result:

ok 1 number(s): "81109"

Test #39:

score: 0
Accepted
time: 74ms
memory: 26212kb

input:

1 1
200000
198099 95670 36890 40716 87639 184338 91215 136831 52451 194978 154523 29005 145217 1680 150761 31010 74811 187132 152251 26629 69928 168496 32612 88716 143170 52169 180352 65604 134072 56852 76824 142310 199020 170148 193522 36860 60694 109272 151484 115493 103327 8572 84605 199660 16133...

output:

66044

result:

ok 1 number(s): "66044"

Subtask #5:

score: 0
Wrong Answer

Test #40:

score: 0
Wrong Answer
time: 3ms
memory: 18132kb

input:

704 2
6
5 3 1 4 4 4
4 5 6 4 5 2
7
1 4 1 4 1 1 1
7 1 4 1 6 7 5
7
5 6 6 5 5 6 6
3 4 6 1 7 3 5
8
8 2 7 4 6 1 3 4
6 6 6 6 6 6 6 6
8
1 3 1 2 8 7 4 1
8 8 8 8 5 1 8 8
8
1 6 2 6 7 3 5 8
7 7 5 8 5 7 5 5
6
6 4 5 3 6 1
3 3 3 3 4 3
7
3 3 7 3 3 3 3
1 4 5 3 6 5 7
5
3 1 5 5 1
5 4 3 5 3
6
4 1 4 2 2 2
6 2 2 1 5 2
6
...

output:

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

result:

wrong answer 4th numbers differ - expected: '2', found: '1'

Subtask #6:

score: 0
Skipped

Dependency #5:

0%