In this problem. How can I solve it using dsu ?
Have this the code already dsu ?
#include <iostream>
#include <vector>
using namespace std;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vb> vmb;
typedef vector<vi> vmi;
int main()
{
int n, q;
cin >> n >> q;
vmb f(3, vb(n + 2, false));
int delta = 0;
while (q--)
{
int r, c;
cin >> r >> c;
f[r][c].flip();
if (r == 1)
delta += (f[1][c] ? +1 : -1) * (f[2][c - 1] || f[2][c] || f[2][c + 1]);
else
{
delta += (f[2][c] ? +1 : -1) * (f[1][c] && !f[2][c - 1] && !f[2][c + 1]);
delta += (f[2][c] ? +1 : -1) * (f[1][c - 1] && !f[2][c - 1] && !f[2][max(c - 2, 0)]);
delta += (f[2][c] ? +1 : -1) * (f[1][c + 1] && !f[2][c + 1] && !f[2][min(c + 2, n + 1)]);
}
cout << (delta == 0 ? "Yes\n" : "No\n");
}
return 0;
}