QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#497967#8809. Telephone Plansbachbeo20070 8ms36368kbC++172.6kb2024-07-29 21:04:132024-07-29 21:04:14

Judging History

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

  • [2024-07-29 21:04:14]
  • 评测
  • 测评结果:0
  • 用时:8ms
  • 内存:36368kb
  • [2024-07-29 21:04:13]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int maxn = 5e5+5;
#define int long long

int sub,n,q;
int p[3*maxn],total,lst;

int vis[maxn],T;
int c[maxn],sz[2*maxn],cnt;
set<int> g[maxn];
set<int>::iterator ptr[maxn];

void add(int x,int y){
    if(sz[c[x]]>sz[c[y]]) swap(x,y);
    total+=sz[c[x]]*sz[c[y]];

    queue<int> q;
    q.push(x);vis[x]=++T;
    while(!q.empty()){
        int u=q.front();q.pop();
        c[u]=c[y];sz[c[y]]++;
        for(int v:g[u]) if(vis[v]!=T){q.push(v);vis[v]=T;}
    }
    g[x].insert(y);
    g[y].insert(x);
}

bool cmp(int x,int y){
    queue<int> qx,qy;
    qx.push(x);qy.push(y);
    vis[x]=vis[y]=++T;
    ptr[x]=g[x].begin();
    ptr[y]=g[y].begin();

    while(true){
        while(!qx.empty()){
            int u=qx.front();
            while(ptr[u]!=g[u].end() && vis[*ptr[u]]==T) ptr[u]++;
            if(ptr[u]==g[u].end()) qx.pop();
            else{
                int v=*ptr[u];
                ptr[v]=g[v].begin();
                vis[v]=T;qx.push(v);
            }
        }
        if(qx.empty()) return false;
        while(!qy.empty()){
            int u=qy.front();
            while(ptr[u]!=g[u].end() && vis[*ptr[u]]==T) ptr[u]++;
            if(ptr[u]==g[u].end()) qy.pop();
            else{
                int v=*ptr[u];
                ptr[v]=g[v].begin();
                vis[v]=T;qy.push(v);
            }
        }
        if(qy.empty()) return true;
    }
    return true;
}

int del(int x,int y){
    g[x].erase(y);
    g[y].erase(x);
    if(cmp(x,y)) swap(x,y);

    cnt++;
    queue<int> q;
    q.push(x);vis[x]=++T;
    while(!q.empty()){
        int u=q.front();q.pop();
        c[u]=cnt;sz[cnt]++;
        for(int v:g[u]) if(vis[v]!=T){q.push(v);vis[v]=T;}
    }
    assert(sz[c[y]]>=2*sz[cnt]);
    sz[c[y]]-=sz[cnt];
    int val=sz[cnt]*sz[c[y]];
    total-=val;
    return val;
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    cin >> sub >> n >> q;
    cnt=n;
    for(int i=1;i<=n;i++) c[i]=i,sz[i]=1;
    for(int i=1;i<=q;i++){
        int op;cin >> op;
        if(op==1){
            int x,y;cin >> x >> y;
            if(sub) x^=lst,y^=lst;
            add(x,y);
        }
        else if(op==2){
            int x,y;cin >> x >> y;
            if(sub) x^=lst,y^=lst;
            p[i-1]+=del(x,y);
        }
        else{
            int t;cin >> t;
            if(sub) t^=lst;
            lst=total+p[i-1]-(i>t?p[i-t-1]:0);
            cout << lst << '\n';
        }
        p[i]=p[i-1];
    }
}

详细

Subtask #1:

score: 0
Runtime Error

Test #1:

score: 3
Accepted
time: 8ms
memory: 33872kb

input:

0
1 147
3 0
3 0
3 1
3 1
3 0
3 5
3 5
3 1
3 1
3 4
3 8
3 2
3 10
3 13
3 10
3 8
3 8
3 0
3 16
3 3
3 1
3 20
3 2
3 10
3 16
3 13
3 17
3 12
3 22
3 7
3 8
3 2
3 12
3 32
3 12
3 31
3 2
3 0
3 21
3 24
3 28
3 32
3 9
3 18
3 26
3 11
3 45
3 35
3 14
3 34
3 49
3 31
3 43
3 11
3 21
3 50
3 4
3 11
3 31
3 51
3 28
3 26
3 18
3 ...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

result:

ok 147 lines

Test #2:

score: 3
Accepted
time: 4ms
memory: 36368kb

input:

0
2 10
1 1 2
3 1
3 1
3 2
3 3
3 3
3 3
2 1 2
3 2
3 3

output:

1
1
1
1
1
1
1
1

result:

ok 8 lines

Test #3:

score: 0
Runtime Error

input:

0
30 150
1 14 10
3 1
1 14 6
1 3 6
3 4
3 4
1 2 3
3 0
3 5
1 2 9
1 11 9
3 8
1 19 11
3 6
1 8 19
3 14
3 10
1 27 8
3 15
1 27 28
1 28 20
3 0
3 3
1 20 7
1 7 23
3 13
3 5
1 24 23
3 0
3 28
1 24 13
3 5
3 32
3 1
3 13
1 30 13
3 25
1 30 16
1 15 16
3 22
1 29 15
3 13
1 29 25
1 25 1
1 1 18
3 17
3 8
3 10
1 26 18
3 46
...

output:


result:


Subtask #2:

score: 0
Runtime Error

Test #29:

score: 2
Accepted
time: 4ms
memory: 34160kb

input:

1
1 147
3 0
3 0
3 1
3 1
3 3
3 0
3 6
3 6
3 0
3 2
3 0
3 5
3 12
3 1
3 2
3 10
3 13
3 15
3 3
3 12
3 20
3 18
3 10
3 12
3 2
3 12
3 14
3 26
3 12
3 24
3 7
3 7
3 6
3 29
3 32
3 16
3 23
3 14
3 25
3 13
3 13
3 31
3 20
3 26
3 0
3 40
3 23
3 28
3 35
3 1
3 31
3 2
3 34
3 37
3 3
3 39
3 17
3 4
3 41
3 11
3 16
3 48
3 10
3...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

result:

ok 147 lines

Test #30:

score: 2
Accepted
time: 4ms
memory: 33392kb

input:

1
2 10
1 1 2
3 1
3 1
3 1
3 1
3 1
3 2
3 6
2 0 3
3 2

output:

1
1
1
1
1
1
1
1

result:

ok 8 lines

Test #31:

score: 0
Runtime Error

input:

1
30 150
1 21 13
3 1
1 9 20
3 2
3 2
1 18 11
1 18 0
3 6
3 9
3 8
1 12 9
3 8
3 7
1 10 9
3 5
3 24
3 26
3 28
1 6 16
3 6
3 14
1 15 23
3 21
3 48
1 60 47
3 53
3 37
1 35 53
3 56
1 57 59
1 59 37
3 63
3 95
3 94
1 92 79
3 65
1 90 81
1 95 81
3 75
3 111
3 118
3 100
1 124 98
1 101 98
3 121
3 132
3 137
3 153
1 141 ...

output:


result:


Subtask #3:

score: 0
Skipped

Dependency #1:

0%

Subtask #4:

score: 0
Skipped

Dependency #2:

0%

Subtask #5:

score: 0
Skipped

Dependency #3:

0%

Subtask #6:

score: 0
Skipped

Dependency #4:

0%

Subtask #7:

score: 0
Skipped

Dependency #6:

0%