QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#227221 | #7190. Chessboard | PPP | WA | 0ms | 3760kb | C++17 | 4.3kb | 2023-10-27 03:01:18 | 2023-10-27 03:01:19 |
Judging History
answer
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
#pragma GCC optimize("Ofast, unroll-loops", "omit-frame-pointer","inline")
#pragma GCC option("arch=native", "no-zero-upper")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2")
#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;
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 + SZ2; u++) {
id[u] = u;
CNT[u] = u;
}
for (int x = 1; x <= m; x++) {
if (tp[mid][x] == tp[mid + 1][x]) {
int P = info[2 * v][x][1];
int Q = info[2 * v + 1][x][0] + SZ1;
if (CNT[P] > 0 && EDGE[P][CNT[P] - 1] == Q) continue;
EDGE[P][CNT[P]] = Q;
EDGE[Q][CNT[Q]] = P;
CNT[P]++;
CNT[Q]++;
}
}
ITER++;
for (int x = 1; x <= m; x++) {
int u = info[2 * v][x][1];
if (id[u] == u && inter[u] != ITER) {
int topQ = 0;
Q[topQ++] = u;
inter[u] = ITER;
for (int z = 0; z < topQ; z++) {
int vert = Q[z];
for (int p = 0; p < CNT[vert]; p++) {
if (id[EDGE[vert][p]] == EDGE[vert][p] && EDGE[vert][p] != u) {
id[EDGE[vert][p]] = u;
Q[topQ++] = EDGE[vert][p];
}
}
}
}
}
ITER++;
for (int x = 1; x <= m; x++) {
inter[id[info[2 * v][x][0]]] = ITER;
inter[id[info[2 * v + 1][x][1] + SZ1]] = ITER;
}
int sz = 0;
int CMP = 0;
for (int u = 0; u < SZ1 + SZ2; u++) {
if (id[u] == u) {
if (inter[u] != ITER) {
CMP++;
}
else {
MP[u] = sz;
sz++;
}
}
}
cnt_other[v] += CMP;
for (int x = 1; x <= m; x++) {
info[v][x][0] = MP[id[info[2 * v][x][0]]];
}
for (int x = 1; x <= m; x++) {
info[v][x][1] = MP[id[info[2 * v + 1][x][1] + SZ1]];
}
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: 0
Wrong Answer
time: 0ms
memory: 3760kb
input:
2 2 2 01 10 5 5 0 0
output:
3 3
result:
wrong answer 1st numbers differ - expected: '2', found: '3'