QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#620679#9419. Normal Friendsucup-team004AC ✓2393ms80860kbC++237.9kb2024-10-07 20:20:302024-10-07 20:20:31

Judging History

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

  • [2024-10-07 20:20:31]
  • 评测
  • 测评结果:AC
  • 用时:2393ms
  • 内存:80860kb
  • [2024-10-07 20:20:30]
  • 提交

answer

#include <bits/stdc++.h>

using i64 = long long;
using u64 = unsigned long long;
using u32 = unsigned;

constexpr int N = 7E5;

struct Node {
    int p;
    int ch[2];
    int rev;
    int flip;
    int val1;
    int sum1;
    int val2;
    int sum2;
    Node() : p(0), ch {0, 0}, rev(0), flip(0), val1(0), sum1(0), val2(0), sum2(0) {}
} t[2 * N];

int tlc[N], trc[N];
int fl[N];

int tot = 0;

void reverse(int o) {
    if (o) {
        std::swap(t[o].ch[0], t[o].ch[1]);
        t[o].rev ^= 1;
    }
}
void flip(int o) {
    if (o) {
        t[o].flip ^= 1;
        if (o < N) {
            std::swap(t[o].val1, t[o].val2);
            std::swap(t[o].sum1, t[o].sum2);
        }
    }
}
void push(int o) {
    if (t[o].rev) {
        reverse(t[o].ch[0]);
        reverse(t[o].ch[1]);
        t[o].rev = 0;
    }
    if (t[o].flip) {
        if (o > N) {
            fl[o - N] ^= 1;
            flip(t[o].ch[0]);
            flip(t[o].ch[1]);
        } else {
            flip(t[o].ch[0]);
            flip(t[o].ch[1]);
        }
        t[o].flip = 0;
    }
}
void pull(int o) {
    t[o].sum1 = t[t[o].ch[0]].sum1 + t[o].val1 + t[t[o].ch[1]].sum1;
    t[o].sum2 = t[t[o].ch[0]].sum2 + t[o].val2 + t[t[o].ch[1]].sum2;
}
bool isroot(int o) {
    return t[o].p == 0 || (t[t[o].p].ch[0] != o && t[t[o].p].ch[1] != o);
}
int pos(int o) {
    return t[t[o].p].ch[1] == o;
}
void pushAll(int o) {
    if (!isroot(o)) {
        pushAll(t[o].p);
    }
    push(o);
}
void rotate(int o) {
    int q = t[o].p;
    int x = !pos(o);
    t[q].ch[!x] = t[o].ch[x];
    if (t[o].ch[x]) {
        t[t[o].ch[x]].p = q;
    }
    t[o].p = t[q].p;
    if (!isroot(q)) {
        t[t[q].p].ch[pos(q)] = o;
    }
    t[o].ch[x] = q;
    t[q].p = o;
    pull(q);
}
void splay(int o) {
    pushAll(o);
    while (!isroot(o)) {
        if (!isroot(t[o].p)) {
            if (pos(o) == pos(t[o].p)) {
                rotate(t[o].p);
            } else {
                rotate(o);
            }
        }
        rotate(o);
    }
    pull(o);
}

int select1(int o, int x) {
    push(o);
    if (x <= t[t[o].ch[0]].sum1) {
        return select1(t[o].ch[0], x);
    }
    x -= t[t[o].ch[0]].sum1;
    if (x <= t[o].val1) {
        return o;
    }
    x -= t[o].val1;
    return select1(t[o].ch[1], x);
}

int select2(int o, int x) {
    push(o);
    if (x <= t[t[o].ch[0]].sum2) {
        return select2(t[o].ch[0], x);
    }
    x -= t[t[o].ch[0]].sum2;
    if (x <= t[o].val2) {
        return o;
    }
    x -= t[o].val2;
    return select2(t[o].ch[1], x);
}

std::pair<int, int> split2(int o, int x) {
    if (x == 0) {
        return {0, o};
    }
    o = select2(o, x);
    splay(o);
    int p = t[o].ch[1];
    t[o].ch[1] = 0;
    t[p].p = 0;
    pull(o);
    return {o, p};
}

int findFirst(int o) {
    while (t[o].ch[0]) {
        push(o);
        o = t[o].ch[0];
    }
    return o;
}

int findLast(int o) {
    while (t[o].ch[1]) {
        push(o);
        o = t[o].ch[1];
    }
    return o;
}

int merge(int a, int b) {
    if (!a) {
        return b;
    }
    if (!b) {
        return a;
    }
    a = findLast(a);
    splay(a);
    t[a].ch[1] = b;
    t[b].p = a;
    pull(a);
    return a;
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    int n, m;
    std::cin >> n >> m;
    
    std::vector<int> mid(n);
    mid[0] = n;
    for (int i = 1; i < n; i++) {
        std::cin >> mid[i];
    }
    
    int cur = n + 1;
    int i = 0;
    
    auto dfs = [&](auto &&dfs, int l, int r) -> int {
        if (r - l == 1) {
            t[r + N].val1 = 1;
            t[r + N].val2 = 1;
            pull(r + N);
            return r;
        }
        int m = mid[i++];
        assert(l < m && m < r);
        int o = ++cur;
        
        int lc = dfs(dfs, l, m);
        int rc = dfs(dfs, m, r);
        
        t[o].val1 = 1;
        t[o].ch[1] = rc;
        t[rc].p = o;
        pull(o);
        
        tlc[o] = lc + N;
        t[tlc[o]].ch[1] = tlc[rc];
        if (tlc[rc]) {
            t[tlc[rc]].p = tlc[o];
        }
        pull(tlc[o]);
        
        t[o + N].val1 = t[tlc[o]].sum1 + 1;
        t[o + N].val2 = 1;
        pull(o + N);
        
        return o;
    };
    int rt = dfs(dfs, 0, n + 1);
    
    for (int i = 0; i < m; i++) {
        int x;
        std::cin >> x;
        x++;
        
        int o = rt;
        std::vector<int> stk;
        while (true) {
            int p = findFirst(o);
            splay(p);
            if (fl[p]) {
                std::swap(tlc[p], trc[p]);
                flip(tlc[p]);
                flip(trc[p]);
                flip(p);
                fl[p] = 0;
            }
            if (x <= t[tlc[p]].sum1) {
                int q = select1(tlc[p], x);
                splay(q);
                tlc[p] = q;
                x -= t[t[q].ch[0]].sum1;
                int r = select1(o, t[t[q].ch[0]].sum2 + 1);
                splay(r);
                stk.push_back(r);
                o = q - N;
            } else {
                x -= t[tlc[p]].sum1;
                if (x == 1) {
                    break;
                } else {
                    x--;
                    int q = select1(trc[p], t[trc[p]].sum1 - x + 1);
                    splay(q);
                    trc[p] = q;
                    x -= t[t[q].ch[1]].sum1;
                    int r = select2(o, t[t[q].ch[0]].sum2 + 1);
                    splay(r);
                    stk.push_back(r);
                    o = q - N;
                }
            }
        }
        
        while (!stk.empty()) {
            splay(o);
            o = findFirst(o);
            splay(o);
            
            int q = stk.back();
            stk.pop_back();
            splay(q);
            int p = findFirst(q);
            splay(p);
            splay(q);
            
            int r = t[q].ch[1];
            t[q].ch[1] = 0;
            t[r].p = 0;
            pull(q);
            r = findFirst(r);
            splay(r);
            
            std::tie(tlc[p], tlc[r]) = split2(tlc[p], t[q].sum1);
            std::tie(trc[p], trc[r]) = split2(trc[p], t[q].sum2);
            
            if (t[q].val1) {
                t[q].val1 = 0;
                t[q].val2 = 1;
                t[q].ch[1] = o;
                t[o].p = q;
                pull(q);
                
                int s = findLast(tlc[p]);
                splay(s);
                tlc[p] = t[s].ch[0];
                t[tlc[p]].p = 0;
                t[s].ch[0] = 0;
                
                int u = r + N;
                push(u);
                t[u].val1 = t[tlc[r]].sum1 + 1 + t[trc[r]].sum1;
                t[u].ch[0] = trc[p];
                if (trc[p]) {
                    t[trc[p]].p = u;
                }
                pull(u);
                trc[p] = u;
            } else {
                t[q].val2 = 0;
                t[q].val1 = 1;
                t[q].ch[1] = o;
                t[o].p = q;
                pull(q);
                
                int s = findLast(trc[p]);
                splay(s);
                trc[p] = t[s].ch[0];
                t[trc[p]].p = 0;
                t[s].ch[0] = 0;
                
                int u = r + N;
                push(u);
                t[u].val1 = t[tlc[r]].sum1 + 1 + t[trc[r]].sum1;
                t[u].ch[0] = tlc[p];
                if (tlc[p]) {
                    t[tlc[p]].p = u;
                }
                pull(u);
                tlc[p] = u;
            }
            
            tlc[p] = merge(tlc[p], tlc[o]);
            trc[p] = merge(trc[p], trc[o]);
        }
        
        std::cout << t[tlc[rt]].sum2 << "\n";
        reverse(tlc[rt]);
        flip(tlc[rt]);
    }
    
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 3ms
memory: 57056kb

input:

3 3
2 1
2
3
2

output:

1
1
2

result:

ok 3 number(s): "1 1 2"

Test #2:

score: 0
Accepted
time: 11ms
memory: 57504kb

input:

5000 4999
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 10...

output:

3048
3984
678
4440
880
3442
3828
2259
42
3007
1279
4590
275
4436
427
2660
4479
3354
717
1778
2530
2292
1403
4220
2765
3279
4177
4634
4937
3241
996
800
816
380
590
4942
1211
1770
699
2033
4152
4468
4384
3845
4685
1617
3420
3374
5
4693
2201
2656
2985
43
203
2244
4607
904
2053
4854
791
988
3995
139
206...

result:

ok 4999 numbers

Test #3:

score: 0
Accepted
time: 24ms
memory: 55552kb

input:

5000 4999
4999 4998 4997 4996 4995 4994 4993 4992 4991 4990 4989 4988 4987 4986 4985 4984 4983 4982 4981 4980 4979 4978 4977 4976 4975 4974 4973 4972 4971 4970 4969 4968 4967 4966 4965 4964 4963 4962 4961 4960 4959 4958 4957 4956 4955 4954 4953 4952 4951 4950 4949 4948 4947 4946 4945 4944 4943 4942 ...

output:

1
3000
1
103
103
103
103
103
1
1
127
127
362
127
458
103
25
1
1
868
1704
1208
1
415
617
321
308
444
468
641
268
268
831
617
308
421
421
424
444
784
808
784
136
435
328
444
54
900
326
702
900
271
444
246
629
475
444
455
768
557
315
544
689
589
125
588
588
488
488
589
562
43
458
1
44
392
28
319
878
30...

result:

ok 4999 numbers

Test #4:

score: 0
Accepted
time: 21ms
memory: 55716kb

input:

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

output:

4
7
9
8
13
9
8
9
9
9
8
10
12
9
13
14
12
9
20
18
10
9
11
15
10
7
10
16
16
18
18
12
12
9
13
18
12
24
20
4
18
16
14
11
12
6
9
10
14
21
20
24
24
21
19
18
17
17
18
16
22
12
4
11
14
11
15
21
18
13
13
14
13
16
22
11
18
6
12
17
11
16
10
16
11
26
14
6
10
9
16
17
19
20
16
12
15
16
10
12
17
21
24
16
24
27
28
2...

result:

ok 4999 numbers

Test #5:

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

input:

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

output:

1198
1994
1537
984
532
1026
579
666
942
2092
1876
251
637
2513
2098
1018
1930
785
1131
1127
1186
106
1
1870
1051
1677
1027
2321
2221
1398
1463
1078
1112
2218
151
50
198
1975
276
2520
300
224
684
1797
28
1369
1271
952
320
2390
183
1127
5
710
2145
2033
1571
90
1068
983
2208
1476
758
350
1877
37
130
11...

result:

ok 5000 numbers

Test #6:

score: 0
Accepted
time: 23ms
memory: 56116kb

input:

4999 5000
4997 4994 4993 4990 4988 4986 4983 4981 4979 4977 4975 4973 4970 4969 4966 4963 4962 4960 4958 4955 4953 4952 4951 4950 4947 4944 4943 4941 4939 4937 4934 4933 4931 4928 4926 4924 4923 4920 4918 4915 4914 4913 4912 4909 4908 4907 4906 4905 4903 4902 4899 4898 4897 4895 4894 4891 4888 4887 ...

output:

2
1
1
1101
1079
216
3
2
1727
943
272
1148
425
1551
1726
19
169
1670
1726
1458
929
1624
848
416
331
279
298
112
76
78
236
79
356
418
994
416
75
12
75
417
430
89
77
122
8
2
239
442
443
443
475
319
229
141
104
96
178
418
441
545
156
39
51
148
149
151
356
133
82
226
102
233
139
168
287
287
261
88
263
28...

result:

ok 5000 numbers

Test #7:

score: 0
Accepted
time: 20ms
memory: 56160kb

input:

5000 4999
4838 2657 1015 947 364 87 18 16 6 5 4 2 1 3 8 7 14 11 10 9 13 12 15 17 55 47 30 22 21 20 19 26 23 24 25 28 27 29 43 40 36 31 34 33 32 35 38 37 39 42 41 44 45 46 53 50 49 48 51 52 54 83 56 72 64 62 57 58 59 60 61 63 67 66 65 71 69 68 70 78 74 73 75 77 76 81 80 79 82 84 85 86 231 195 162 107...

output:

4
8
10
15
12
26
36
22
9
16
14
12
16
14
30
30
33
36
36
26
29
23
18
22
16
21
6
15
12
9
14
13
22
35
29
47
42
34
32
23
32
26
19
21
12
25
9
22
11
36
17
30
44
14
12
32
44
12
41
24
28
15
12
9
16
30
26
25
23
23
13
24
24
17
15
13
29
41
43
9
21
39
36
46
31
4
14
33
27
31
7
28
8
6
14
21
23
28
38
44
30
49
30
23
...

result:

ok 4999 numbers

Test #8:

score: 0
Accepted
time: 2033ms
memory: 61088kb

input:

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

output:

14
19
18
18
18
23
29
27
35
31
37
29
15
36
12
44
27
37
27
32
9
42
33
19
29
54
38
17
19
11
49
45
51
56
55
19
15
60
37
11
40
42
20
51
72
55
43
67
51
51
81
74
12
29
21
47
66
32
33
46
56
39
74
24
19
43
25
19
17
45
66
56
60
51
50
50
47
37
48
41
42
38
37
17
41
44
46
20
39
38
47
50
48
51
54
68
49
63
19
69
5...

result:

ok 300000 numbers

Test #9:

score: 0
Accepted
time: 2053ms
memory: 61068kb

input:

300000 300000
195514 59559 33882 13127 10574 5470 4110 2816 2236 1643 223 116 99 72 44 10 7 4 2 1 3 5 6 8 9 38 37 28 21 12 11 19 14 13 16 15 18 17 20 25 23 22 24 27 26 35 33 29 32 30 31 34 36 40 39 43 42 41 59 50 48 47 46 45 49 56 55 53 52 51 54 57 58 67 63 60 62 61 64 66 65 71 69 68 70 76 74 73 75 ...

output:

13
11
30
19
20
20
23
22
21
28
28
30
26
21
14
31
38
33
28
26
24
32
41
19
32
34
41
33
16
19
21
22
32
28
25
28
37
41
45
31
13
42
46
34
38
30
20
32
30
39
33
30
29
26
45
25
17
29
28
23
44
25
43
34
27
22
33
44
36
37
42
34
54
47
32
28
30
25
30
35
27
33
42
20
22
37
38
36
28
25
31
37
42
46
46
29
36
43
23
35
...

result:

ok 300000 numbers

Test #10:

score: 0
Accepted
time: 2036ms
memory: 61476kb

input:

299999 300000
291066 20684 19223 6298 4767 3310 847 109 22 15 14 1 9 7 6 2 5 3 4 8 13 12 10 11 20 18 16 17 19 21 53 38 24 23 36 35 27 26 25 29 28 30 33 32 31 34 37 51 48 40 39 46 43 42 41 44 45 47 50 49 52 106 62 60 55 54 57 56 59 58 61 69 65 64 63 67 66 68 86 70 72 71 80 74 73 77 75 76 78 79 84 81 ...

output:

15
14
17
43
9
39
48
25
17
45
39
22
39
33
42
37
25
54
22
5
24
16
34
32
29
36
45
28
28
18
35
34
42
22
33
54
37
30
38
27
35
25
51
40
48
37
27
45
47
36
20
28
41
48
34
49
48
22
40
30
39
44
30
71
31
41
67
45
42
43
29
63
74
63
43
24
32
22
26
25
24
45
42
23
39
51
35
43
38
37
35
52
34
59
59
40
51
49
45
23
50...

result:

ok 300000 numbers

Test #11:

score: 0
Accepted
time: 2091ms
memory: 61408kb

input:

300000 299999
61923 22527 2457 886 497 181 112 23 6 3 2 1 4 5 11 9 8 7 10 18 16 12 13 15 14 17 19 22 21 20 60 28 27 26 25 24 32 30 29 31 54 49 41 39 37 35 34 33 36 38 40 45 44 42 43 48 46 47 52 50 51 53 57 56 55 59 58 80 76 66 64 61 62 63 65 67 71 68 70 69 75 74 73 72 78 77 79 100 94 81 92 88 87 83 ...

output:

15
27
28
29
36
24
14
34
29
18
18
21
23
20
24
25
35
28
21
24
21
29
22
25
16
29
28
32
36
25
12
11
20
28
36
33
22
28
40
17
30
25
16
23
34
36
33
31
33
23
37
36
23
43
42
37
42
44
28
38
34
16
18
31
35
38
42
44
37
33
35
46
44
43
17
18
43
36
34
40
32
30
36
24
25
44
25
35
62
64
44
22
43
17
40
17
41
35
58
21
...

result:

ok 299999 numbers

Test #12:

score: 0
Accepted
time: 28ms
memory: 61680kb

input:

100000 100000
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:

95
95
96
96
98
96
98
96
96
96
96
98
98
99
99
95
99
96
97
98
98
95
97
96
95
96
95
98
95
98
98
96
99
97
97
99
96
99
96
98
96
95
97
96
97
96
98
97
97
98
95
96
98
99
98
99
95
96
99
99
98
98
99
96
95
99
97
97
99
95
98
95
98
97
95
98
97
95
97
96
95
97
98
98
96
97
99
99
99
95
99
95
97
96
99
96
96
96
96
95
...

result:

ok 100000 numbers

Test #13:

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

input:

100000 100000
99999 99998 99997 99996 99995 99994 99993 99992 99991 99990 99989 99988 99987 99986 99985 99984 99983 99982 99981 99980 99979 99978 99977 99976 99975 99974 99973 99972 99971 99970 99969 99968 99967 99966 99965 99964 99963 99962 99961 99960 99959 99958 99957 99956 99955 99954 99953 9995...

output:

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

result:

ok 100000 numbers

Test #14:

score: 0
Accepted
time: 52ms
memory: 58152kb

input:

99999 100000
50000 25000 12500 6250 3125 1563 782 391 196 98 49 25 13 7 4 2 1 3 6 5 10 9 8 12 11 19 16 15 14 18 17 22 21 20 24 23 37 31 28 27 26 30 29 34 33 32 36 35 43 40 39 38 42 41 46 45 44 48 47 74 62 56 53 51 50 52 55 54 59 58 57 61 60 68 65 64 63 67 66 71 70 69 73 72 86 80 77 76 75 79 78 83 82...

output:

15
15
16
17
15
16
15
15
17
16
14
13
15
15
14
14
14
13
13
13
15
16
14
15
14
14
15
15
15
14
13
13
13
13
12
12
14
12
12
14
12
13
14
14
13
12
12
14
14
12
11
11
11
14
13
10
10
8
9
9
9
9
9
9
9
10
10
8
9
9
10
10
10
10
10
9
9
9
10
9
10
9
10
10
10
9
8
10
9
11
9
10
9
10
10
9
10
11
11
9
11
9
8
11
10
11
12
11
1...

result:

ok 100000 numbers

Test #15:

score: 0
Accepted
time: 51ms
memory: 61192kb

input:

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

output:

98
97
99
100
99
99
99
100
98
96
95
97
97
99
99
99
99
97
97
100
98
95
99
100
100
99
95
95
99
100
100
99
99
99
99
97
100
99
100
100
100
100
100
99
99
100
98
98
98
98
98
97
99
100
96
97
97
97
99
100
94
98
99
94
93
100
100
99
99
99
99
93
93
94
93
100
100
95
97
99
97
98
99
100
100
97
96
100
99
95
96
96
9...

result:

ok 99999 numbers

Test #16:

score: 0
Accepted
time: 47ms
memory: 61200kb

input:

100000 99999
99997 99995 99992 99990 99989 99986 99984 99982 99981 99980 99977 99976 99975 99973 99970 99967 99966 99963 99960 99957 99954 99951 99948 99945 99942 99941 99940 99939 99936 99934 99933 99931 99928 99925 99923 99921 99920 99917 99916 99915 99914 99913 99911 99910 99909 99906 99904 99903...

output:

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

result:

ok 99999 numbers

Test #17:

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

input:

100000 100000
95196 42764 36221 6229 3689 2406 118 51 31 1 16 6 2 5 4 3 12 11 7 10 9 8 14 13 15 26 25 23 18 17 21 19 20 22 24 27 30 28 29 40 32 34 33 37 36 35 39 38 47 44 43 42 41 45 46 50 49 48 112 76 54 53 52 65 57 56 55 59 58 62 60 61 64 63 73 72 69 68 66 67 71 70 75 74 95 94 83 79 77 78 82 81 80...

output:

17
30
31
31
33
32
32
29
33
34
36
41
39
39
40
40
40
40
39
39
39
39
39
38
38
39
40
39
38
38
39
37
39
39
39
41
41
40
40
41
39
40
44
45
45
44
45
45
44
44
44
45
45
45
45
44
44
45
45
45
45
44
45
46
45
44
44
45
45
45
45
45
45
45
45
45
44
45
45
45
45
46
45
45
46
47
46
46
46
47
46
46
46
47
45
46
47
46
47
46
...

result:

ok 100000 numbers

Test #18:

score: 0
Accepted
time: 2296ms
memory: 79940kb

input:

300000 300000
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:

231883
189126
222427
159733
265923
226191
122928
139479
210336
106873
163228
58754
119326
297184
277033
278399
66122
140398
34169
19708
156224
56272
2899
270046
218801
130842
131338
186068
189893
201079
244887
262010
4736
74736
183359
242279
64921
156956
284547
126337
295299
255552
228029
80745
5181...

result:

ok 300000 numbers

Test #19:

score: 0
Accepted
time: 2393ms
memory: 80860kb

input:

300000 300000
299999 299998 299997 299996 299995 299994 299993 299992 299991 299990 299989 299988 299987 299986 299985 299984 299983 299982 299981 299980 299979 299978 299977 299976 299975 299974 299973 299972 299971 299970 299969 299968 299967 299966 299965 299964 299963 299962 299961 299960 299959...

output:

1
1
149995
147345
62983
149995
56542
83889
47921
26475
149995
118431
50391
65570
141444
55767
84364
36380
149995
19101
85128
146961
51813
80934
54308
54308
80934
1261
13509
1
31996
30924
32521
19129
19129
27048
46507
40186
91269
28468
16673
22729
43399
19129
84383
31848
8709
12443
12309
12309
19129
...

result:

ok 300000 numbers

Test #20:

score: 0
Accepted
time: 1934ms
memory: 61008kb

input:

299999 300000
150000 75000 37500 18750 9375 4688 2344 1172 586 293 147 74 37 19 10 5 3 2 1 4 8 7 6 9 15 13 12 11 14 17 16 18 28 24 22 21 20 23 26 25 27 33 31 30 29 32 35 34 36 56 47 42 40 39 38 41 45 44 43 46 52 50 49 48 51 54 53 55 65 61 59 58 57 60 63 62 64 70 68 67 66 69 72 71 73 111 93 84 79 77 ...

output:

10
17
11
25
22
25
27
25
11
30
15
22
21
20
29
29
14
20
19
20
25
22
28
36
29
29
28
27
33
28
17
34
15
34
39
11
11
22
20
26
28
19
40
22
35
19
10
14
10
19
13
30
30
26
26
20
33
36
29
32
18
15
16
25
27
29
31
24
29
23
33
12
34
36
40
42
34
19
28
37
14
33
36
18
27
16
30
22
36
36
22
19
19
37
30
30
29
30
28
24
...

result:

ok 300000 numbers

Test #21:

score: 0
Accepted
time: 1480ms
memory: 70888kb

input:

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

output:

30746
54459
77717
32257
66050
52814
98683
132280
130853
26640
30175
18778
46888
14228
96772
117368
15629
9851
48603
127951
92046
56060
137831
112290
109730
114920
144605
3994
10568
78965
7576
54817
123059
84057
28123
138984
148847
136432
69190
59864
41067
29515
118303
45091
136828
123865
23453
10382...

result:

ok 299999 numbers

Test #22:

score: 0
Accepted
time: 2200ms
memory: 70972kb

input:

300000 299999
299997 299995 299992 299989 299987 299985 299982 299980 299978 299977 299976 299975 299972 299969 299968 299965 299962 299959 299956 299955 299954 299952 299951 299948 299945 299942 299941 299940 299938 299936 299935 299934 299931 299929 299926 299924 299923 299921 299918 299915 299913...

output:

2
1
3
5097
18544
16429
2
57217
31690
33092
31691
31691
31690
2775
31691
31690
31691
20657
21032
46183
20655
31449
25765
8423
25311
11195
17051
25313
14443
25312
20789
25312
1526
14335
31692
31690
10428
20454
14332
27897
23376
2
6941
19879
2384
14139
2018
1526
6575
6574
716
12545
5652
1230
9816
7231
...

result:

ok 299999 numbers

Test #23:

score: 0
Accepted
time: 2041ms
memory: 60924kb

input:

300000 300000
173719 41788 1457 1370 1096 473 340 1 187 166 88 11 4 2 3 7 6 5 9 8 10 15 12 14 13 38 17 16 37 24 21 18 20 19 23 22 27 26 25 32 29 28 30 31 36 33 35 34 47 40 39 44 41 43 42 46 45 74 59 55 49 48 53 52 51 50 54 56 57 58 71 64 60 61 63 62 69 66 65 67 68 70 73 72 87 75 80 76 79 77 78 83 81...

output:

12
23
9
20
23
13
16
19
22
29
19
22
33
33
29
33
25
30
29
26
29
29
34
26
18
45
24
30
31
33
29
12
14
24
24
17
35
45
37
32
41
29
41
28
31
38
38
34
38
47
28
32
31
26
16
41
30
15
15
29
16
30
59
36
53
39
51
26
27
28
31
25
26
33
26
18
23
30
35
21
26
36
17
17
40
29
32
33
39
47
35
28
33
42
28
51
60
48
34
32
5...

result:

ok 300000 numbers

Extra Test:

score: 0
Extra Test Passed