QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#227238 | #7190. Chessboard | PPP | WA | 0ms | 3776kb | C++17 | 4.3kb | 2023-10-27 04:16:30 | 2023-10-27 04:16:30 |
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 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;
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];
memset(CNT, 0, sizeof CNT);
memset(id, -1, sizeof id);
memset(MP, -1, sizeof MP);
int ANS = SZ1 + SZ2;
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;
if (CNT[P] > 0 && EDGE[P][CNT[P] - 1] == Q) continue;
if (CNT[Q] > 0 && EDGE[Q][CNT[Q] - 1] == P) continue;
EDGE[P][CNT[P]] = Q;
EDGE[Q][CNT[Q]] = P;
CNT[P]++;
CNT[Q]++;
}
}
int CMP = 0;
for (int u = 0; u < SZ1; u++) {
if (id[2 * u] == -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) {
ANS--;
id[EDGE[vert][p]] = 2 * u;
Q[topQ++] = EDGE[vert][p];
}
}
}
}
}
if (v == 1) {
SZ[v] = 0;
cnt_other[v] += ANS;
return;
}
for (int u = 0; u < SZ2; u++) {
if (id[2 * u + 1] == -1) {
++CMP;
id[2 * u + 1] = 2 * u + 1;
}
}
ITER++;
int sz = 0;
for (int x = 1; x <= m; x++) {
if (MP[id[info[2 * v][x][0]] * 2] == -1) {
CMP--;
MP[id[info[2 * v][x][0] * 2]] = sz;
sz++;
}
info[v][x][0] = MP[id[info[2 * v][x][0] * 2]];
if (MP[id[info[2 * v + 1][x][1] * 2 + 1]] == -1) {
CMP--;
MP[id[info[2 * v + 1][x][0]] * 2 + 1] = sz;
sz++;
}
info[v][x][1] = MP[id[info[2 * v + 1][x][1] * 2 + 1]];
}
cnt_other[v] += CMP;
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;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3656kb
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: 3776kb
input:
5 5 5 10111 11110 10010 00111 00101 4 1 5 4 12 11 12 13 13 9
output:
8 8 9 7 7
result:
wrong answer 1st numbers differ - expected: '7', found: '8'