QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#227224#7190. ChessboardPPPWA 0ms3692kbC++174.4kb2023-10-27 03:03:532023-10-27 03:03:54

Judging History

你现在查看的是最新测评结果

  • [2023-10-27 03:03:54]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3692kb
  • [2023-10-27 03:03:53]
  • 提交

answer

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
#pragma GCC optimize("O3")
#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];
    memset(CNT, 0, sizeof CNT);
    memset(id, -1, sizeof id);
    for (int u = 0; u < SZ1 + SZ2; u++) id[u] = u;
    for (int x = 1; x <= m; x++) {
        if (tp[mid][x] == tp[mid + 1][x]) {
            if (x > 1 && tp[mid][x] == tp[mid][x - 1] && tp[mid + 1][x] == tp[mid][x]) continue;
            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]]];
        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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3672kb

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: 3644kb

input:

1 1 1
0
0 0

output:

1

result:

ok 1 number(s): "1"

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 3692kb

input:

5 5 5
10111
11110
10010
00111
00101
4 1
5 4
12 11
12 13
13 9

output:

7
8
9
6
6

result:

wrong answer 2nd numbers differ - expected: '9', found: '8'