QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#592065#7181. Graph Cutsphuong2222WA 222ms17764kbC++145.9kb2024-09-26 20:27:282024-09-26 20:27:29

Judging History

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

  • [2024-09-26 20:27:29]
  • 评测
  • 测评结果:WA
  • 用时:222ms
  • 内存:17764kb
  • [2024-09-26 20:27:28]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using lli = long long;
const int maxN = 2e5 + 5;
const int maxB = 448;
const int maxB1 = 448;
vector<int> type1,type0,adj[maxN];
int type[maxN],deg[maxN],n,m,val[maxN],l[maxB1],r[maxB1],id[maxN];
int sum0[maxB1],val0[maxN],id0[maxN];
int val1[maxN],id1[maxN],id11[maxN];
int id01[maxB1][maxN],sum01[2][maxB1][maxB1],sumch[2][maxB1],val01[2][maxB1][maxN];
int del[maxN];
vector<int> type01[maxB1],vex1;
struct Tedge
{
    int x,y;
}
e[maxN];
void presolve()
{
    int cntb = 0;
    for (int i = 0;i < maxN;++i)
    {
        if (i % maxB == 0) l[++cntb] = i;
        if (i % maxB == (maxB - 1)) r[cntb] = i;
        id[i] = cntb;
        if (cntb == 100) break;
        //cerr << id[i] << "\n";
    }
}
void finddata()
{
    for (int i = 1;i <= n;++i)
    {
        type[i] = deg[i] > maxB;
        if (type[i])
        {
            id11[i] = vex1.size();
            vex1.push_back(i);
        }
    }
    for (int i = 1;i <= m;++i)
    {
        if (type[e[i].x] && type[e[i].y])
        {
            id1[i] = type1.size();
            type1.push_back(i);
        }
        if (type[e[i].x] == 0 && type[e[i].y] == 0)
        {
            id0[i] = type0.size();
            type0.push_back(i);
        }
    }
    for (int i = 1;i <= m;++i)
    {
        if (type[e[i].x] && !type[e[i].y])
        {
            id01[id11[e[i].x]][e[i].y] = type01[id11[e[i].x]].size();
            val01[1][id11[e[i].x]][type01[id11[e[i].x]].size()] = 1;
            sum01[1][id11[e[i].x]][id[type01[id11[e[i].x]].size()]]++;
            sumch[1][id11[e[i].x]]++;
            type01[id11[e[i].x]].push_back(i);
        }
        if (type[e[i].y] && !type[e[i].x])
        {
            id01[id11[e[i].y]][e[i].x] = type01[id11[e[i].y]].size();
            val01[1][id11[e[i].y]][type01[id11[e[i].y]].size()] = 1;
            sum01[1][id11[e[i].y]][id[type01[id11[e[i].y]].size()]]++;
            sumch[1][id11[e[i].y]]++;
            type01[id11[e[i].y]].push_back(i);
        }

    }
}
void input()
{
    cin >> n >> m;
    fill(deg + 1,deg + n + 1,0);
    fill(val + 1,val + n + 1,0);
    fill(id0 + 1,id0 + n + 1,-1);
    for (int i = 1;i <= m;++i)
    {
        cin >> e[i].x >> e[i].y;
        deg[e[i].x]++;deg[e[i].y]++;
        adj[e[i].x].push_back(i);
        adj[e[i].y].push_back(i);
    }
    presolve();
    finddata();
}
void query()
{
    for (int i : type1)
        if (val1[id1[i]] == 1 && del[i] == 0)
        {
            del[i] = 1;
            cout << i << "\n";
            return;
        }
    int cntb = (type0.size() + maxB - 1) / maxB;
    //cout << cntb << "A\n";
    for (int idb = 1;idb <= cntb;++idb)
    {

        if (sum0[idb] > 0)
        {
            for (int i = l[idb];i <= min(r[idb],int(type0.size()));++i)
                if (val0[i] == 1)
                {
                    del[type0[i]] = 1;
                    val0[i] = 0;
                    sum0[idb]--;
                    cout << type0[i] << "\n";
                    return;
                }
        }
    }
    for (int u : vex1)
    {
        if (sumch[val[u]][id11[u]] > 0)
        {
            int cntb = (type01[id11[u]].size() + maxB - 1) / maxB;
            for (int idb = 1;idb <= cntb;++idb)
            {
                if (sum01[val[u]][id11[u]][idb] > 0)
                {
                    for (int i = l[idb];i <= min(r[idb],int(type01[id11[u]].size()));++i)
                        if (val01[val[u]][id11[u]][i] == 1)
                        {
                            del[type01[id11[u]][i]] = 1;
                            val01[0][id11[u]][i] = 0;
                            val01[1][id11[u]][i] = 0;
                            cout << type01[id11[u]][i] << "\n";
                            return;
                        }
                }
            }
        }
    }
    cout << 0 << "\n";
}
void update(int u)
{
    //cerr << u << "a\n";
    val[u] ^= 1;
    if (type[u])
    {
        for (int i : type1)
            if (e[i].x == u || e[i].y == u) val1[id1[i]] ^= 1;
    }
    else
    {
        for (int i : adj[u])
        {

            if (del[i] == 1) continue;
            int v = e[i].x + e[i].y - u;
            if (!type[v])
            {
                val0[id0[i]] = (val0[id0[i]] ^ 1);
                if (val0[id0[i]] == 1) sum0[id[id0[i]]]++;
                else sum0[id[id0[i]]]--;
                //cout << sum0[id[id0[i]]] << "\n";
            }
            else
            {
                val01[1][id11[e[i].x]][id01[id11[e[i].x]][u]] ^= 1;
                val01[0][id11[e[i].x]][id01[id11[e[i].x]][u]] ^= 1;
                if (val01[1][id11[e[i].x]][id01[id11[e[i].x]][u]] == 1)
                {
                    sum01[1][id11[e[i].x]][id[id01[id11[e[i].x]][u]]]++;
                    sumch[1][id11[e[i].x]]++;
                }
                else
                {
                    sum01[1][id11[e[i].x]][id[id01[id11[e[i].x]][u]]]--;
                    sumch[1][id11[e[i].x]]--;
                }
                if (val01[0][id11[e[i].x]][id01[id11[e[i].x]][u]] == 1)
                {
                    sum01[0][id11[e[i].x]][id[id01[id11[e[i].x]][u]]]++;
                    sumch[0][id11[e[i].x]]++;
                }
                else
                {
                    sum01[0][id11[e[i].x]][id[id01[id11[e[i].x]][u]]]--;
                    sumch[0][id11[e[i].x]]--;
                }
            }
        }
    }
}
void solve()
{
    int q;
    cin >> q;
    while (q--)
    {
        char c;
        int u;
        cin >> c;
        if (c == '+' || c == '-') {cin >> u;update(u);}
        else query();
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("C.inp","r",stdin);
//    freopen("C.out","w",stdout);
    input();
    solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4 5
1 2
1 3
1 4
2 3
2 4
10
+ 1
+ 2
?
?
?
?
?
- 2
?
?

output:

2
3
4
5
0
1
0

result:

ok q=10

Test #2:

score: 0
Accepted
time: 0ms
memory: 15472kb

input:

0 0
0

output:


result:

ok q=0

Test #3:

score: 0
Accepted
time: 2ms
memory: 12692kb

input:

0 0
1
?

output:

0

result:

ok q=1

Test #4:

score: 0
Accepted
time: 6ms
memory: 16084kb

input:

1000 2000
1 50
1 88
331 1
1 352
1 497
2 32
2 282
550 2
989 2
334 3
3 665
4 38
4 69
4 343
4 451
589 4
917 4
89 5
5 162
675 5
681 6
7 22
127 7
7 592
7 672
787 7
8 310
107 9
9 137
184 9
9 244
378 9
446 9
9 658
883 9
65 10
75 10
414 10
10 468
686 10
245 11
269 11
11 386
403 11
493 11
394 12
493 12
565 1...

output:

1
4
5
8
9
10
12
14
16
18
19
25
27
29
33
38
39
40
42
47
48
49
50
56
58
59
62
63
67
69
70
71
73
75
79
81
82
83
84
87
89
91
94
97
101
103
104
106
107
108
109
110
113
114
115
118
120
121
122
125
126
129
130
131
132
133
134
135
137
145
147
148
34
149
152
153
154
155
156
157
159
160
163
167
171
105
173
17...

result:

ok q=100000

Test #5:

score: 0
Accepted
time: 222ms
memory: 17108kb

input:

447 99681
2 1
1 3
4 1
1 5
1 6
1 7
1 8
9 1
10 1
1 11
1 12
1 13
1 14
1 15
1 16
17 1
18 1
19 1
20 1
21 1
22 1
23 1
24 1
25 1
1 26
27 1
28 1
1 29
30 1
31 1
1 32
33 1
1 34
1 35
36 1
37 1
38 1
39 1
40 1
1 41
1 42
43 1
44 1
45 1
46 1
1 47
48 1
49 1
1 50
1 51
1 52
53 1
54 1
55 1
1 56
57 1
1 58
59 1
60 1
1 6...

output:

6

result:

ok q=100000

Test #6:

score: 0
Accepted
time: 181ms
memory: 17764kb

input:

447 99681
1 2
3 1
4 1
5 1
1 6
7 1
8 1
9 1
10 1
11 1
1 12
13 1
14 1
15 1
1 16
1 17
18 1
19 1
1 20
21 1
22 1
23 1
24 1
1 25
26 1
27 1
28 1
1 29
1 30
31 1
32 1
1 33
1 34
35 1
1 36
37 1
38 1
1 39
40 1
41 1
42 1
43 1
1 44
45 1
46 1
47 1
48 1
49 1
50 1
1 51
1 52
1 53
1 54
1 55
56 1
1 57
58 1
1 59
1 60
61 ...

output:

70
44
110
103
88
113
85
161
171
172
21
43
5
176
40
46
47
41
18
53
3
55
11
37
69
79
82
2
94
1
4
6
7
8
9
10
12
13
14
15
16
17
19
20
24
25
26
27
28
29
30
31
32
33
34
35
36
38
45
48
49
51
52
54
57
58
59
60
61
62
63
64
65
66
67
68
71
72
73
75
77
78
81
83
86
90
91
42
92
93
95
96
102
76
105
106
109
111
118...

result:

ok q=100000

Test #7:

score: 0
Accepted
time: 136ms
memory: 17672kb

input:

447 99681
1 2
3 1
1 4
1 5
6 1
7 1
8 1
1 9
10 1
11 1
1 12
1 13
1 14
15 1
16 1
17 1
18 1
1 19
1 20
21 1
1 22
23 1
1 24
25 1
1 26
1 27
1 28
29 1
1 30
1 31
32 1
1 33
34 1
1 35
36 1
37 1
1 38
39 1
40 1
1 41
42 1
1 43
44 1
45 1
46 1
47 1
48 1
49 1
50 1
51 1
1 52
53 1
54 1
55 1
56 1
57 1
58 1
59 1
60 1
61 ...

output:

180
25
1
91
101
107
137
13
54
57
61
71
72
78
23
40
93
37
103
124
126
138
139
145
150
151
154
160
168
8
175
102
68
158
34
77
94
118
185
159
186
106
128
26
162
172
62
90
21
184
7
20
120
188
82
92
112
33
59
130
144
152
173
174
181
189
191
161
192
193
196
205
211
45
89
142
35
153
127
163
166
212
221
222...

result:

ok q=100000

Test #8:

score: -100
Wrong Answer
time: 106ms
memory: 17472kb

input:

447 99681
2 1
1 3
4 1
1 5
6 1
1 7
1 8
1 9
10 1
1 11
12 1
1 13
14 1
15 1
1 16
1 17
18 1
1 19
20 1
21 1
22 1
1 23
24 1
1 25
26 1
27 1
28 1
29 1
30 1
1 31
32 1
33 1
34 1
35 1
1 36
37 1
38 1
39 1
40 1
1 41
42 1
43 1
1 44
45 1
1 46
1 47
48 1
1 49
50 1
51 1
52 1
1 53
1 54
1 55
1 56
57 1
1 58
59 1
60 1
1 6...

output:

0
84
93
27
111
120
127
141
20
151
152
177
189
191
217
220
235
240
241
292
188
264
294
309
203
290
303
330
369
30
32
99
375
379
118
169
202
259
312
320
353
414
417
29
302
378
396
428
441
342
465
156
286
472
47
155
1
2
3
4
5
6
7
8
9
10
12
13
14
15
16
17
18
19
21
22
23
24
25
26
28
31
33
34
35
36
37
38
...

result:

wrong answer Edge exists, but not found