QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#855533#8704. 排队ChiFAN0 525ms33588kbC++143.7kb2025-01-12 22:57:332025-01-12 22:57:35

Judging History

This is the latest submission verdict.

  • [2025-01-12 22:57:35]
  • Judged
  • Verdict: 0
  • Time: 525ms
  • Memory: 33588kb
  • [2025-01-12 22:57:33]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
const int maxn = 3e5+114;
//2*i-1 father to u 2*i u to father
struct node{
    int l,r;//l:) r:(
    node(int L=0,int R=0){
        l=L,r=R;
    }
    node operator+(const node&x)const{
        node res=node();
        res=x;
        int del=min(r,x.l);
        res=node(l+x.l-del,r+x.r-del);
        return res;
    }
};
node tr[maxn];
int ls[maxn],rs[maxn],rk[maxn];
int fa[maxn];
int sz[maxn];
mt19937 rd(11245141);
set<int> E[maxn];
int root;
int q,tot;
void pushup(int cur){
    tr[cur]=node((cur%2)^1,cur%2);
    sz[cur]=1;
    if(ls[cur]!=0) tr[cur]=tr[ls[cur]]+tr[cur],sz[cur]+=sz[ls[cur]];
    if(rs[cur]!=0) tr[cur]=tr[cur]+tr[rs[cur]],sz[cur]+=sz[rs[cur]];
}
int merge(int u,int v){
    if(u==0||v==0) return u+v;
    if(rk[u]>rk[v]){
        rs[u]=merge(rs[u],v);
        fa[rs[u]]=u;
        pushup(u);
        return u;
    }else{
        ls[v]=merge(u,ls[v]);
        fa[ls[v]]=v;
        pushup(v);
        return v;
    }
}
void split(int cur,int k,int &l,int &r){
    if(cur==0){
        l=r=0;
        return ;
    }
    if(sz[ls[cur]]+1<=k){
        l=cur;
        fa[rs[l]]=0;
        split(rs[l],k-sz[ls[cur]]-1,rs[l],r);
        fa[rs[l]]=l;
        pushup(l);
    }else{
        r=cur;
        fa[ls[r]]=0;
        split(ls[r],k,l,ls[r]);
        fa[ls[r]]=r;
        pushup(r);
    }
}
int query(int cur){
    int ans=sz[ls[cur]];
    while(fa[cur]!=0){
        if(cur==rs[fa[cur]]) ans+=sz[ls[fa[cur]]]+1;
        cur=fa[cur];
    }
    return ans;
}
int siz(int u){
    //cout<<"siz"<<u<<' '<<(query(2*u)-query(2*u-1)-1)/2<<'\n';
    return (query(2*u)-query(2*u-1)-1)/2;
}
void ins(int u,int v,int w){
    if(E[u].lower_bound(v)==E[u].end()){
        int x=0,y=0;
        split(root,query(u*2),x,y);
        root=merge(x,merge(w,y));
    }else{
        int x=0,y=0;
        int nxt=(*E[u].lower_bound(v));
        split(root,query(nxt*2-1),x,y);
        root=merge(x,merge(w,y));
    }
    E[u].insert(v);
}
int del(int u,int v){
    //cout<<"Cut"<<u<<" "<<v<<'\n';
    int x=0,y=0,z=0;
    split(root,query(2*v-1),x,y);
    split(y,query(2*v)+1,y,z);
    root=merge(x,z);
    E[u].erase(v);
    return y;
}
int ask(int cur){
    int sum=query(cur);
    node res=tr[ls[cur]];
    while(fa[cur]!=0){
        if(cur==rs[fa[cur]]){
            res=(tr[ls[fa[cur]]]+(fa[cur]%2==1?node(0,1):node(1,0)))+res;
        }
        cur=fa[cur];
    }
    return (sum-res.l-res.r)/2;
}
void dfs(int u){
    if(u==0) return ;
    dfs(ls[u]);
    cout<<u<<' '<<ls[u]<<' '<<rs[u]<<' '<<tr[u].l<<' '<<tr[u].r<<'\n';
    dfs(rs[u]);
}
int link[maxn];
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    tot++;
    tr[1]=node(0,1);
    tr[2]=node(1,0);
    rk[1]=rd(),rk[2]=rd();
    sz[1]=sz[2]=1;
    root=merge(1,2);
    int c;
    cin>>c>>q;
    while(q--){
        int opt;
        cin>>opt;
        if(opt==1){
            int lst;
            cin>>lst;
            lst++;
            tot++;
            link[tot]=lst;
            tr[tot*2-1]=node(0,1),tr[tot*2]=node(1,0);
            rk[tot*2-1]=rd(),rk[tot*2]=rd();
            sz[tot*2-1]=sz[tot*2]=1;
            int w=merge(tot*2-1,tot*2);
            ins(lst,tot,w);
        }else if(opt==2){
            int x,y;
            cin>>x>>y;
            x++,y++;
            //cout<<"Cut"<<link[x]<<' '<<x<<'\n';
            int w=del(link[x],x);
            //cout<<"Del"<<w<<' '<<sz[w]<<'\n';
            ins(y,x,w);
        }else{
            int z;
            cin>>z;
            z++;
            cout<<(tot-ask(z*2-1)-siz(z))-1<<'\n';
        }
        //dfs(root);
        //cout<<"------------------\n";
    }
    return 0;
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

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

input:

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

output:

2
3
1
2

result:

ok 4 lines

Test #2:

score: 0
Wrong Answer
time: 7ms
memory: 23992kb

input:

0 485
1 0
2 1 0
2 1 0
3 1
3 1
1 0
1 1
3 3
2 3 2
2 2 1
2 2 1
2 2 0
3 1
3 1
3 1
1 0
2 3 0
1 2
3 3
1 3
2 3 2
1 1
2 2 0
1 3
2 3 0
2 1 0
1 1
2 8 6
2 3 0
3 3
2 4 1
1 4
3 2
1 0
1 5
1 4
2 3 2
2 7 4
3 5
1 7
1 8
2 7 5
3 14
3 2
2 6 2
3 13
1 0
3 11
1 13
3 1
3 4
1 4
2 15 0
2 15 9
2 17 16
3 13
1 17
2 17 12
3 3
3 ...

output:

1
1
3
3
3
3
2
7
1
3
6
2
13
2
11
13
16
19
5
12
18
17
13
7
25
16
24
13
37
28
34
13
15
20
40
38
30
31
47
29
45
9
29
12
21
3
17
20
15
42
47
34
7
10
13
16
11
17
12
7
70
31
8
27
46
7
76
69
27
36
2
48
27
64
64
19
23
19
22
77
75
29
42
90
74
84
16
33
70
12
69
3
22
42
66
4
23
49
29
86
66
70
27
75
61
13
48
93
...

result:

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

Subtask #2:

score: 0
Time Limit Exceeded

Test #5:

score: 19
Accepted
time: 215ms
memory: 31532kb

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
14
2
7
3
18
17
11
4
13
2
2
18
21
12
17
3
3
22
22
6
5
20
5
17
22
27
18
23
31
4
1
19
21
12
22
34
33
5
22
40
40
8
14
42
35
9
40
24
18
13
36
8
25
49
32
34
47
14
47
19
38
10
14
31
40
17
20
45
46
1
35
1
43
9
47
33
56
2
8
19
41
21
18
50
22
61
27
2
2
6
4
58
62
35
61
59
10...

result:

ok 179182 lines

Test #6:

score: 0
Time Limit Exceeded

input:

1 296745
1 0
3 1
3 1
1 0
1 0
3 2
1 0
3 4
1 4
1 0
1 4
3 5
1 0
1 0
1 0
1 0
1 8
1 4
1 0
1 0
1 8
3 9
1 0
1 8
1 4
1 0
1 0
1 0
1 0
3 3
1 0
1 7
1 0
1 0
1 7
1 9
1 3
3 15
1 0
1 3
1 10
3 16
1 0
1 0
1 0
3 10
1 10
1 0
1 0
3 11
1 0
1 0
3 29
1 0
3 26
3 16
1 0
1 0
1 0
1 0
1 0
1 1
1 0
1 5
1 1
3 21
3 36
3 42
3 23
3 ...

output:

1
1
2
1
4
5
21
9
19
16
17
24
11
28
21
12
7
19
19
55
37
55
24
47
1
62
37
44
39
59
30
85
48
5
8
46
61
74
39
34
67
12
58
1
107
83
87
60
12
93
119
81
37
51
112
25
125
55
98
94
9
71
46
33
121
64
4
128
144
128
100
10
133
25
170
107
179
19
19
9
2
144
192
110
28
172
115
101
162
108
48
83
6
169
171
18
194
40...

result:


Subtask #3:

score: 0
Time Limit Exceeded

Test #20:

score: 21
Accepted
time: 198ms
memory: 29916kb

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
8
11
1
2
1
8
6
11
9
3
2
4
4
9
3
15
13
12
4
9
4
12
10
6
2
4
10
9
16
2
15
13
13
7
3
3
11
21
7
5
4
2
10
5
15
20
6
17
12
5
24
4
15
13
7
10
17
6
19
9
19
19
12
3
18
16
21
19
26
12
25
21
19
10
14
24
8
8
14
16
32
8
14
33
30
14
4
1
20
21
37
22
25
7
18
27
28
35
37
18
33
4...

result:

ok 222965 lines

Test #21:

score: 21
Accepted
time: 197ms
memory: 30180kb

input:

2 297805
1 0
1 0
3 1
3 1
1 0
1 1
3 2
1 0
3 4
3 3
3 3
3 3
3 4
3 3
1 0
3 4
1 2
3 2
3 7
1 5
1 0
1 0
1 10
3 5
3 6
1 0
1 0
1 0
3 9
1 0
3 3
1 0
1 0
3 13
3 15
3 2
3 15
3 6
3 2
3 17
1 5
3 14
3 9
1 1
3 5
3 10
3 13
3 17
3 7
1 0
3 20
3 6
3 14
1 0
1 4
3 10
3 19
1 0
3 6
3 5
3 13
3 4
3 19
1 7
3 14
3 6
3 15
3 20
3...

output:

2
2
2
5
2
2
2
5
2
6
4
5
5
4
6
11
5
3
14
3
10
14
1
4
9
11
7
5
1
16
1
11
5
9
20
13
14
8
22
21
7
13
6
3
3
15
22
2
11
7
10
17
13
10
13
20
17
5
33
10
12
28
9
26
27
12
36
18
2
22
2
24
35
34
4
4
12
34
35
8
18
14
1
38
33
10
35
10
7
5
27
54
47
7
42
16
12
15
46
45
18
24
29
28
51
50
40
42
16
46
22
9
28
46
4
1
...

result:

ok 197988 lines

Test #22:

score: 0
Time Limit Exceeded

input:

2 292846
1 0
3 1
3 1
1 1
1 1
1 3
1 0
1 0
1 5
1 7
3 2
3 4
1 8
1 1
1 6
1 8
1 7
1 1
1 10
1 9
3 6
1 5
1 6
3 7
1 3
1 3
1 5
1 6
1 4
1 6
1 1
1 6
1 9
1 5
3 23
1 7
1 8
1 3
1 1
1 4
3 8
1 6
1 1
1 8
1 2
1 5
1 3
1 5
1 9
3 25
1 10
1 6
1 9
3 44
1 7
3 26
1 1
1 7
1 5
1 9
3 34
1 9
1 3
1 6
1 0
1 6
1 0
1 9
3 53
1 10
1 ...

output:

1
1
8
7
1
6
27
14
28
23
4
3
2
57
9
34
43
87
64
13
1
63
88
2
83
38
89
101
97
82
57
115
145
57
34
57
15
147
126
107
108
140
37
91
177
16
135
205
227
171
152
88
31
95
21
231
40
20
273
201
128
82
98
147
115
169
238
129
58
179
114
268
324
39
163
132
251
230
65
16
295
299
15
272
28
312
255
358
315
229
193...

result:


Subtask #4:

score: 0
Wrong Answer

Test #35:

score: 0
Wrong Answer
time: 525ms
memory: 33588kb

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
8
10
10
8
6
11
15
6
11
11
4
4
19
7
15
5
26
26
23
11
29
30
5
14
16
13
11
10
11
27
25
3
34
39
37
6
2
41
8
27
29
18
16
10
30
53
30
3
2
55
24
19
34
8
32
45
9
54
64
59
42
23
32
18
27
7
71
27
6
24
19
50
4
54
83
81
20
34
24
24
64
80
55
103
64
23
54
63
93
97
22
95
97
22
56
...

result:

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

Subtask #5:

score: 0
Skipped

Dependency #1:

0%