Submission #1057987

# Submission time Handle Problem Language Result Execution time Memory
1057987 2024-08-14T07:51:05 Z 정희우(#11078) Telephone Plans (CCO24_day2problem3) C++17
11 / 25
67 ms 856 KB
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>

using namespace std;
using lint = long long;
using vint = vector<int>;
using pii = pair<int,int>;

const int MAX_N=2010;
const int MAX_Q=6010;

int in,n,q;
set<int> edge[MAX_N];
int check[MAX_N];
lint sum[MAX_Q],sump[MAX_Q];

int f(int v)
{
    check[v]=1;
    int r=1;
    for(auto v0 : edge[v])
        if(!check[v0])
            r+=f(v0);
    return r;
}

lint cnt()
{
    fill(check,check+n+1,0);
    lint r=0;
    for(int i=1;i<=n;i++)
        if(!check[i])
        {
            lint c=f(i);
            r+=c*(c-1)/2;
        }
    return r;
}

int main()
{
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin >> in >> n >> q;
    lint lasta=0,lc=0;
    for(int i=1;i<=q;i++)
    {
        int o;
        lint x,y,t;
        cin >> o;
        if(o==1)
        {
            cin >> x >> y;
            if(in)x^=lasta,y^=lasta;
            edge[x].insert(y);
            edge[y].insert(x);
        }
        if(o==2)
        {
            cin >> x >> y;
            if(in)x^=lasta,y^=lasta;
            edge[x].erase(y);
            edge[y].erase(x);
        }
        if(o<=2)
        {
            lint c=cnt();
            sum[i]=c;
            sump[i]=sump[i-1]+max(0LL,c-lc);
            lc=c;
        }
        if(o==3)
        {
            cin >> t;
            if(in)t^=lasta;
            int j=max(0LL,i-t);
            sum[i]=sum[i-1];sump[i]=sump[i-1];
            lasta=sum[j]+sump[i]-sump[j];
            cout << lasta << '\n';
        }
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 420 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 58 ms 852 KB Output is correct
30 Correct 49 ms 852 KB Output is correct
31 Correct 34 ms 732 KB Output is correct
32 Correct 40 ms 788 KB Output is correct
33 Correct 39 ms 600 KB Output is correct
34 Correct 41 ms 604 KB Output is correct
35 Correct 33 ms 804 KB Output is correct
36 Correct 39 ms 804 KB Output is correct
37 Correct 36 ms 724 KB Output is correct
38 Correct 35 ms 836 KB Output is correct
39 Correct 49 ms 604 KB Output is correct
40 Correct 28 ms 604 KB Output is correct
41 Correct 35 ms 604 KB Output is correct
42 Correct 55 ms 856 KB Output is correct
43 Correct 30 ms 600 KB Output is correct
44 Correct 67 ms 848 KB Output is correct
45 Correct 36 ms 600 KB Output is correct
46 Correct 49 ms 792 KB Output is correct
47 Correct 50 ms 604 KB Output is correct
48 Correct 36 ms 604 KB Output is correct
49 Correct 44 ms 684 KB Output is correct
50 Correct 1 ms 604 KB Output is correct
51 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 420 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 49 ms 792 KB Output is correct
30 Correct 50 ms 848 KB Output is correct
31 Correct 46 ms 604 KB Output is correct
32 Correct 45 ms 700 KB Output is correct
33 Correct 54 ms 796 KB Output is correct
34 Correct 57 ms 600 KB Output is correct
35 Correct 34 ms 600 KB Output is correct
36 Correct 34 ms 604 KB Output is correct
37 Correct 60 ms 600 KB Output is correct
38 Correct 33 ms 820 KB Output is correct
39 Correct 59 ms 824 KB Output is correct
40 Correct 29 ms 604 KB Output is correct
41 Correct 31 ms 828 KB Output is correct
42 Correct 33 ms 856 KB Output is correct
43 Correct 29 ms 732 KB Output is correct
44 Correct 49 ms 636 KB Output is correct
45 Correct 48 ms 604 KB Output is correct
46 Correct 42 ms 772 KB Output is correct
47 Correct 41 ms 600 KB Output is correct
48 Correct 52 ms 604 KB Output is correct
49 Correct 35 ms 748 KB Output is correct
50 Correct 2 ms 600 KB Output is correct
51 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 58 ms 852 KB Output is correct
30 Correct 49 ms 852 KB Output is correct
31 Correct 34 ms 732 KB Output is correct
32 Correct 40 ms 788 KB Output is correct
33 Correct 39 ms 600 KB Output is correct
34 Correct 41 ms 604 KB Output is correct
35 Correct 33 ms 804 KB Output is correct
36 Correct 39 ms 804 KB Output is correct
37 Correct 36 ms 724 KB Output is correct
38 Correct 35 ms 836 KB Output is correct
39 Correct 49 ms 604 KB Output is correct
40 Correct 28 ms 604 KB Output is correct
41 Correct 35 ms 604 KB Output is correct
42 Correct 55 ms 856 KB Output is correct
43 Correct 30 ms 600 KB Output is correct
44 Correct 67 ms 848 KB Output is correct
45 Correct 36 ms 600 KB Output is correct
46 Correct 49 ms 792 KB Output is correct
47 Correct 50 ms 604 KB Output is correct
48 Correct 36 ms 604 KB Output is correct
49 Correct 44 ms 684 KB Output is correct
50 Correct 1 ms 604 KB Output is correct
51 Correct 1 ms 604 KB Output is correct
52 Runtime error 0 ms 604 KB Execution killed with signal 11
53 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 420 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 49 ms 792 KB Output is correct
30 Correct 50 ms 848 KB Output is correct
31 Correct 46 ms 604 KB Output is correct
32 Correct 45 ms 700 KB Output is correct
33 Correct 54 ms 796 KB Output is correct
34 Correct 57 ms 600 KB Output is correct
35 Correct 34 ms 600 KB Output is correct
36 Correct 34 ms 604 KB Output is correct
37 Correct 60 ms 600 KB Output is correct
38 Correct 33 ms 820 KB Output is correct
39 Correct 59 ms 824 KB Output is correct
40 Correct 29 ms 604 KB Output is correct
41 Correct 31 ms 828 KB Output is correct
42 Correct 33 ms 856 KB Output is correct
43 Correct 29 ms 732 KB Output is correct
44 Correct 49 ms 636 KB Output is correct
45 Correct 48 ms 604 KB Output is correct
46 Correct 42 ms 772 KB Output is correct
47 Correct 41 ms 600 KB Output is correct
48 Correct 52 ms 604 KB Output is correct
49 Correct 35 ms 748 KB Output is correct
50 Correct 2 ms 600 KB Output is correct
51 Correct 1 ms 604 KB Output is correct
52 Runtime error 0 ms 604 KB Execution killed with signal 11
53 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 420 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 49 ms 792 KB Output is correct
30 Correct 50 ms 848 KB Output is correct
31 Correct 46 ms 604 KB Output is correct
32 Correct 45 ms 700 KB Output is correct
33 Correct 54 ms 796 KB Output is correct
34 Correct 57 ms 600 KB Output is correct
35 Correct 34 ms 600 KB Output is correct
36 Correct 34 ms 604 KB Output is correct
37 Correct 60 ms 600 KB Output is correct
38 Correct 33 ms 820 KB Output is correct
39 Correct 59 ms 824 KB Output is correct
40 Correct 29 ms 604 KB Output is correct
41 Correct 31 ms 828 KB Output is correct
42 Correct 33 ms 856 KB Output is correct
43 Correct 29 ms 732 KB Output is correct
44 Correct 49 ms 636 KB Output is correct
45 Correct 48 ms 604 KB Output is correct
46 Correct 42 ms 772 KB Output is correct
47 Correct 41 ms 600 KB Output is correct
48 Correct 52 ms 604 KB Output is correct
49 Correct 35 ms 748 KB Output is correct
50 Correct 2 ms 600 KB Output is correct
51 Correct 1 ms 604 KB Output is correct
52 Runtime error 0 ms 604 KB Execution killed with signal 11
53 Halted 0 ms 0 KB -