QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#227199 | #7190. Chessboard | PPP# | WA | 0ms | 3780kb | C++17 | 4.8kb | 2023-10-27 01:32:39 | 2023-10-27 01:32:39 |
Judging History
answer
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
typedef long long ll;
typedef double ld;
int n, m;
const int maxN = 205;
int cnt_other[4 * maxN];
int info[4 * maxN][maxN][2];
int tp[maxN][maxN];
int q;
int par[4 * maxN];
int rnk[4 * maxN];
int get(int x) {
if (x == par[x]) return x;
return par[x] = get(par[x]);
}
void unite(int a, int b) {
a = get(a);
b = get(b);
if (a == b) return;
if (rnk[b] < rnk[a]) swap(a, b);
if (rnk[b] == rnk[a]) rnk[b]++;
par[a] = b;
}
int MP[4 * maxN];
int SZ[4 * maxN];
int EDGE[2 * maxN][2 * maxN];
int CNT[4 * maxN];
int id[4 * maxN];
int Q[4 * maxN];
int ITER = 0;
int inter[4 * maxN];
void merge(int v, int l, int mid, int r) {
cnt_other[v] = cnt_other[2 * v] + cnt_other[2 * v + 1];
int SZ1 = SZ[2 * v];
int SZ2 = SZ[2 * v + 1];
for (int u = 0; u < SZ1; u++) {
CNT[2 * u] = 0;
id[2 * u] = -1;
}
for (int u = 0; u < SZ2; u++) {
CNT[2 * u + 1] = 0;
id[2 * u + 1] = -1;
}
for (int x = 1; x <= m; x++) {
if (tp[mid][x] == tp[mid + 1][x]) {
int P = info[2 * v][x][1] * 2;
int Q = info[2 * v + 1][x][0] * 2 + 1;
EDGE[P][CNT[P]] = Q;
EDGE[Q][CNT[Q]] = P;
CNT[P]++;
CNT[Q]++;
}
}
int CMP = 0;
for (int x = 1; x <= m; x++) {
if (id[info[2 * v][x][1] * 2] == -1) {
int u = info[2 * v][x][1];
++CMP;
int topQ = 0;
Q[topQ++] = 2 * u;
id[2 * u] = 2 * u;
for (int z = 0; z < topQ; z++) {
int vert = Q[z];
for (int p = 0; p < CNT[vert]; p++) {
if (id[EDGE[vert][p]] == -1) {
id[EDGE[vert][p]] = 2 * u;
Q[topQ++] = EDGE[vert][p];
}
}
}
}
}
ITER++;
for (int x = 1; x <= m; x++) {
if (id[info[2 * v][x][0] * 2] == -1) {
++CMP;
id[info[2 * v][x][0] * 2] = info[2 * v][x][0] * 2;
}
inter[id[info[2 * v][x][0] * 2]] = ITER;
if (id[info[2 * v + 1][x][1] * 2 + 1] == -1) {
++CMP;
id[info[2 * v + 1][x][1] * 2 + 1] = info[2 * v + 1][x][1] * 2 + 1;
}
inter[id[info[2 * v + 1][x][1] * 2 + 1]] = ITER;
}
int sz = 0;
for (int j = 0; j < 2 * SZ1; j += 2) {
if (inter[j] == ITER) {
CMP--;
MP[j] = sz;
sz++;
}
}
for (int j = 1; j < 2 * SZ2; j += 2) {
if (inter[j] == ITER) {
CMP--;
MP[j] = sz;
sz++;
}
}
cnt_other[v] += CMP;
for (int x = 1; x <= m; x++) {
info[v][x][0] = MP[id[info[2 * v][x][0] * 2]];
info[v][x][1] = MP[id[info[2 * v + 1][x][1] * 2 + 1]];
}
SZ[v] = sz;
}
void build(int v, int tl, int tr) {
if (tl == tr) {
cnt_other[v] = 0;
int sz = 0;
for (int j = 1; j <= m; j++) {
if (j == 1 || tp[tl][j] != tp[tl][j - 1]) {
info[v][j][0] = info[v][j][1] = sz;
sz++;
} else {
info[v][j][0] = info[v][j][1] = info[v][j - 1][0];
}
}
SZ[v] = sz;
return;
}
int tm = (tl + tr) / 2;
build(2 * v, tl, tm);
build(2 * v + 1, tm + 1, tr);
merge(v, tl, tm, tr);
}
int calc() {
return SZ[1] + cnt_other[1];
}
void upd(int v, int tl, int tr, int pos) {
if (tl == tr) {
cnt_other[v] = 0;
int sz = 0;
for (int j = 1; j <= m; j++) {
if (j == 1 || tp[tl][j] != tp[tl][j - 1]) {
info[v][j][0] = info[v][j][1] = sz;
sz++;
} else {
info[v][j][0] = info[v][j][1] = info[v][j - 1][0];
}
}
SZ[v] = sz;
return;
}
int tm = (tl + tr) / 2;
if (pos <= tm) {
upd(2 * v, tl, tm, pos);
} else {
upd(2 * v + 1, tm + 1, tr, pos);
}
merge(v, tl, tm, tr);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
#ifdef DEBUG
freopen("input.txt", "r", stdin);
#endif
cin >> n >> m >> q;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
char c;
cin >> c;
if (c == '1') tp[i][j] = 1;
}
}
build(1, 1, n);
int op = calc();
while (q--) {
int x, y;
cin >> x >> y;
x ^= op;
y ^= op;
tp[x][y] ^= 1;
upd(1, 1, n, x);
op = calc();
cout << op << '\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3600kb
input:
2 2 2 01 10 5 5 0 0
output:
2 1
result:
ok 2 number(s): "2 1"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3668kb
input:
1 1 1 0 0 0
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3628kb
input:
5 5 5 10111 11110 10010 00111 00101 4 1 5 4 12 11 12 13 13 9
output:
7 9 9 8 8
result:
ok 5 number(s): "7 9 9 8 8"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3644kb
input:
5 5 5 00010 10000 11110 00001 01011 5 2 7 1 3 5 1 1 4 4
output:
5 6 5 6 6
result:
ok 5 number(s): "5 6 5 6 6"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3696kb
input:
5 5 5 10010 10100 11100 11100 01000 0 4 1 7 1 1 4 0 7 6
output:
4 4 5 5 4
result:
ok 5 number(s): "4 4 5 5 4"
Test #6:
score: 0
Accepted
time: 0ms
memory: 3624kb
input:
5 5 5 00101 01011 00010 11000 01010 9 12 7 7 13 9 3 4 11 11
output:
6 8 7 9 7
result:
ok 5 number(s): "6 8 7 9 7"
Test #7:
score: -100
Wrong Answer
time: 0ms
memory: 3780kb
input:
5 5 5 10101 00111 00100 10100 01000 10 12 9 11 6 4 10 12 10 12
output:
7 7 6 6 6
result:
wrong answer 1st numbers differ - expected: '8', found: '7'