QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#850085#8704. 排队hhoppitree0 94ms6844kbC++171.8kb2025-01-09 20:14:212025-01-09 20:14:22

Judging History

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

  • [2025-01-09 20:14:22]
  • 评测
  • 测评结果:0
  • 用时:94ms
  • 内存:6844kb
  • [2025-01-09 20:14:21]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

const int N = 3e5 + 5;

mt19937 rnd;

struct Node {
    int ls, rs, fa, mn, siz;
    unsigned int key;
} p[N];

int rt;

void pushup(int k) {
    p[k].mn = min({p[p[k].ls].mn, p[p[k].rs].mn, k});
    p[k].siz = p[p[k].ls].siz + p[p[k].rs].siz + 1;
}

void split(int k, int x, int &a, int &b) {
    if (!k) {
        a = b = 0;
        return;
    }
    if (p[p[k].ls].siz + 1 <= x) {
        a = k, p[p[k].rs].fa = 0, split(p[k].rs, x - (p[p[x].ls].siz + 1), p[a].rs, b);
        if (p[k].rs) p[p[k].rs].fa = k;
    } else {
        b = k, p[p[k].ls].fa = 0, split(p[k].ls, x, a, p[b].ls);
        if (p[k].ls) p[p[k].ls].fa = k;
    }
    pushup(k);
}

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

int rnk(int x) {
    int res = p[p[x].ls].siz + 1;
    while (x != rt) {
        if (p[p[x].fa].rs == x) res += p[p[p[x].fa].ls].siz + 1;
        x = p[x].fa;
    }
    return res;
}

signed main() {
    int n, m = 0; scanf("%*d%d", &n);
    p[0].mn = n + 1;
    for (int i = 1; i <= n; ++i) {
        int opt, x; scanf("%d%d", &opt, &x);
        if (opt == 1) {
            ++m, p[m].mn = m, p[m].siz = 1, p[m].key = rnd();
            if (x) x = rnk(x);
            int a, b;
            split(rt, x, a, b);
            rt = merge(merge(a, m), b);
        } else if (opt == 2) {
            int y; scanf("%d", &y);
        } else {
            printf("%d\n", rnk(x));
        }
    }
    return 0;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

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

input:

0 8
1 0
1 1
1 2
3 2
2 2 0
3 1
3 2
3 3

output:

2
1
2
3

result:

wrong answer 2nd lines differ - expected: '3', found: '1'

Subtask #2:

score: 0
Wrong Answer

Test #5:

score: 0
Wrong Answer
time: 75ms
memory: 6844kb

input:

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

output:

1
1
1
1
1
1
3
3
1
3
4
5
7
4
1
4
3
7
9
2
7
3
9
13
8
4
17
2
2
12
9
8
17
3
3
12
26
6
5
24
5
10
22
13
16
7
10
4
1
16
18
23
22
33
24
5
19
10
10
12
35
10
25
27
14
38
24
23
7
12
18
15
33
39
13
38
37
25
49
33
39
27
54
9
11
41
42
1
35
1
56
33
35
45
48
2
12
33
50
11
67
36
11
56
18
2
2
6
4
48
69
27
57
48
40
18...

result:

wrong answer 19th lines differ - expected: '14', found: '9'

Subtask #3:

score: 0
Wrong Answer

Test #20:

score: 0
Wrong Answer
time: 80ms
memory: 5708kb

input:

2 298235
1 0
1 1
3 2
1 0
1 3
3 4
3 3
3 3
3 2
3 4
3 2
3 3
1 2
3 3
1 4
1 2
1 1
3 5
3 8
1 5
1 9
3 10
3 8
3 10
3 5
3 8
3 5
1 2
1 9
3 5
3 7
3 12
3 3
1 6
3 4
3 3
3 11
3 8
3 9
3 7
3 6
3 4
1 12
1 11
3 13
3 13
1 11
3 16
3 6
3 14
3 9
3 5
3 13
1 9
1 17
3 16
3 13
3 5
3 15
3 8
3 4
3 13
1 18
3 15
3 16
3 19
3 4
1 ...

output:

2
2
1
1
4
2
4
1
1
8
5
10
5
10
8
5
8
9
7
12
1
2
1
9
6
11
8
3
2
4
4
13
3
16
11
10
4
15
4
10
16
6
2
4
17
16
11
2
13
8
8
7
3
3
18
20
7
5
4
2
24
5
16
12
6
21
23
5
24
4
17
8
7
26
23
6
15
20
15
15
24
3
16
18
15
16
26
25
23
15
17
28
8
14
9
9
8
21
23
9
28
23
13
28
4
1
23
29
25
25
21
7
32
24
24
16
17
13
27
4
...

result:

wrong answer 19th lines differ - expected: '8', found: '7'

Subtask #4:

score: 0
Wrong Answer

Test #35:

score: 0
Wrong Answer
time: 94ms
memory: 6540kb

input:

3 299743
1 0
1 1
3 1
1 2
3 2
1 0
3 3
3 2
3 1
3 2
2 2 1
3 3
3 3
3 4
3 1
3 2
3 2
2 1 0
3 2
3 1
3 1
1 0
3 2
1 2
1 1
3 2
2 5 2
1 6
1 0
2 5 2
1 7
3 8
3 5
3 5
2 7 5
2 9 4
3 5
3 8
2 6 2
2 3 0
2 2 0
1 1
2 3 1
1 8
2 7 0
3 3
1 12
2 13 9
1 5
2 2 1
2 14 13
1 12
2 1 0
2 12 10
2 15 12
1 0
1 6
3 6
2 3 2
2 17 6
3 4...

output:

1
2
4
3
2
3
4
4
1
2
3
3
3
2
2
4
5
10
2
2
2
10
9
12
5
3
4
15
16
22
23
11
5
12
12
15
10
4
5
9
20
21
11
8
18
8
17
27
42
36
4
38
30
34
14
32
4
4
36
19
8
4
6
3
55
21
25
4
52
19
37
27
40
51
7
44
18
40
33
7
31
2
20
66
65
11
37
83
48
81
75
45
62
87
2
10
10
73
68
54
41
33
100
27
42
44
97
45
45
45
12
80
17
11...

result:

wrong answer 18th lines differ - expected: '8', found: '10'

Subtask #5:

score: 0
Skipped

Dependency #1:

0%