QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#227182 | #7190. Chessboard | PPP# | WA | 0ms | 3744kb | C++17 | 3.7kb | 2023-10-27 01:01:34 | 2023-10-27 01:01:34 |
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 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;
par[a] = b;
}
bool was[4 * maxN];
int MP[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 = 0;
for (int x = 1; x <= m; x++) {
SZ1 = max(SZ1, info[2 * v][x][0]);
SZ1 = max(SZ1, info[2 * v][x][1]);
}
SZ1++;
int SZ2 = 0;
for (int x = 1; x <= m; x++) {
SZ2 = max(SZ2, info[2 * v + 1][x][0]);
SZ2 = max(SZ2, info[2 * v + 1][x][1]);
}
SZ2++;
for (int u = 0; u < SZ1 + SZ2; u++) {
par[u] = u;
}
for (int x = 1; x <= m; x++) {
if (tp[mid][x] == tp[mid + 1][x]) {
unite(info[2 * v][x][1], info[2 * v + 1][x][0] + SZ1);
}
}
for (int x = 1; x <= m; x++) {
was[get(info[2 * v][x][0])] = true;
was[get(info[2 * v + 1][x][1])] = true;
}
int sz = 0;
for (int u = 0; u < SZ1 + SZ2; u++) {
if (get(u) == u) {
if (!was[u]) {
cnt_other[v]++;
}
else {
MP[u] = sz;
sz++;
}
}
}
for (int x = 1; x <= m; x++) {
info[v][x][0] = MP[get(info[2 * v][x][0])];
info[v][x][1] = MP[get(info[v][x][1])];
}
}
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];
}
}
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() {
int SZ = 0;
for (int i = 1; i <= m; i++) {
SZ = max(SZ, info[1][i][0]);
SZ = max(SZ, info[1][i][1]);
}
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];
}
}
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: 3744kb
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: 3648kb
input:
1 1 1 0 0 0
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3632kb
input:
5 5 5 10111 11110 10010 00111 00101 4 1 5 4 12 11 12 13 13 9
output:
7 7 7 7 7
result:
wrong answer 2nd numbers differ - expected: '9', found: '7'