QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#592419 | #7181. Graph Cuts | rtgsp | WA | 0ms | 11928kb | C++20 | 5.7kb | 2024-09-26 22:24:17 | 2024-09-26 22:24:17 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
#define task ""
using namespace std;
const int maxn = 2e5 + 2, blocksize = 450, mod = 1e9 + 7;
int n, m, q, B[maxn], u[maxn], v[maxn], id[maxn], cnt = 0, x, sum[maxn], sumheavy[2][450][maxn], tot, totheavy[2][450], res;
bool in[maxn], ok[maxn], okheavy[2][450][maxn], off[maxn];
char t;
vector<int> heavy, adj[maxn], heavyadj[maxn];
int main()
{
//freopen(task".INP", "r", stdin);
//freopen(task".OUT", "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m;
for (int i = 1; i <= m; i++)
B[i] = (i - 1)/blocksize + 1;
for (int i = 1; i <= m; i++)
{
cin >> u[i] >> v[i];
adj[u[i]].push_back(i);
adj[v[i]].push_back(i);
}
for (int i = 1; i <= n; i++)
{
if (adj[i].size() > blocksize)
{
cnt++;
heavy.push_back(i);
id[i] = cnt;
for (int j : adj[i])
{
okheavy[1][cnt][j] ^= 1;
totheavy[1][cnt] += okheavy[1][cnt][j] - (okheavy[1][cnt][j] ^ 1);
sumheavy[1][cnt][B[j]] += okheavy[1][cnt][j] - (okheavy[1][cnt][j] ^ 1);
if (adj[u[j] ^ v[j] ^ i].size() > blocksize) heavyadj[i].push_back(j);
}
}
}
cin >> q;
while (q--)
{
cin >> t;
if (t != '?')
{
cin >> x;
in[x] ^= 1;
if (adj[x].size() <= blocksize)
{
for (int i : adj[x])
{
int y = u[i] ^ v[i] ^ x;
if (adj[y].size() <= blocksize)
{
if (!off[i])
{
ok[i] ^= 1;
tot += ok[i] - (ok[i] ^ 1);
sum[B[i]] += ok[i] - (ok[i] ^ 1);
}
}
else
{
if (!off[i])
{
cnt = id[x];
okheavy[0][cnt][i] ^= 1;
totheavy[0][cnt] += okheavy[0][cnt][i] - (okheavy[0][cnt][i] ^ 1);
sumheavy[0][cnt][B[i]] += okheavy[0][cnt][i] - (okheavy[0][cnt][i] ^ 1);
okheavy[1][cnt][i] ^= 1;
totheavy[1][cnt] += okheavy[1][cnt][i] - (okheavy[1][cnt][i] ^ 1);
sumheavy[1][cnt][B[i]] += okheavy[1][cnt][i] - (okheavy[1][cnt][i] ^ 1);
}
}
}
}
else
{
for (int i : heavyadj[x])
{
if (!off[i])
{
int y = u[i] ^ v[i] ^ x;
cnt = id[y];
okheavy[0][cnt][i] ^= 1;
totheavy[0][cnt] += okheavy[0][cnt][i] - (okheavy[0][cnt][i] ^ 1);
sumheavy[0][cnt][B[i]] += okheavy[0][cnt][i] - (okheavy[0][cnt][i] ^ 1);
okheavy[1][cnt][i] ^= 1;
totheavy[1][cnt] += okheavy[1][cnt][i] - (okheavy[1][cnt][i] ^ 1);
sumheavy[1][cnt][B[i]] += okheavy[1][cnt][i] - (okheavy[1][cnt][i] ^ 1);
}
}
}
}
else
{
res = 0;
for (int i = 1; i <= B[m]; i++)
{
if (res != 0 || sum[i] == 0) continue;
for (int j = (i - 1)*blocksize + 1; j <= min(m, i*blocksize); j++)
{
if (ok[j])
{
res = j;
break;
}
}
}
if (res != 0)
{
off[res] = true;
ok[res] ^= 1;
tot += ok[res] - (ok[res] ^ 1);
sum[B[res]] += ok[res] - (ok[res] ^ 1);
cout << 0 << '\n';
continue;
}
for (int x : heavy)
{
if (res != 0 || totheavy[in[x]][id[x]] == 0) continue;
for (int i = 1; i <= B[m]; i++)
{
if (res != 0 || sumheavy[in[x]][id[x]][i] == 0) continue;
for (int j = (i - 1)*blocksize + 1; j <= min(m, i*blocksize); j++)
if (okheavy[in[x]][id[x]][j])
{
res = j;
break;
}
if (res != 0)
{
off[res] = true;
okheavy[in[x]][id[x]][res] ^= 1;
totheavy[in[x]][id[x]] += okheavy[in[x]][id[x]][res] - (okheavy[in[x]][id[x]][res] ^ 1);
sumheavy[in[x]][id[x]][B[res]] += okheavy[in[x]][id[x]][res] - (okheavy[in[x]][id[x]][res] ^ 1);
int y = u[res] ^ v[res] ^ x;
if (adj[y].size() > blocksize)
{
okheavy[in[y]][id[y]][res] ^= 1;
totheavy[in[y]][id[y]] += okheavy[in[y]][id[y]][res] - (okheavy[in[y]][id[y]][res] ^ 1);
sumheavy[in[y]][id[y]][B[res]] += okheavy[in[y]][id[y]][res] - (okheavy[in[y]][id[y]][res] ^ 1);
}
break;
}
}
}
cout << 0 << '\n';
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 11928kb
input:
4 5 1 2 1 3 1 4 2 3 2 4 10 + 1 + 2 ? ? ? ? ? - 2 ? ?
output:
0 0 0 0 0 0 0
result:
wrong answer Edge exists, but not found