답안 #569607

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
569607 2022-05-27T14:41:26 Z OttoTheDino Furniture (JOI20_furniture) C++17
0 / 100
2 ms 724 KB
#include <bits/stdc++.h>
using namespace std;

#define rep(i,s,e)                  for (int i = s; i <= e; ++i)
#define rrep(i,s,e)                 for (int i = s; i >= e; --i)
#define pb                          push_back
#define pf                          push_front
#define fi                          first
#define se                          second
#define all(a)                      a.begin(), a.end()
#define len(a)                      (int)a.size()
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;

const int mx = 1e3;

int ftree[mx+1][mx+1][2];

void upd (int tp, int p, int x, int val) {
    x++;
    while (x <= mx) {
        ftree[x][p][tp] += val;
        x += x&(-x);
    }
}

int pref (int tp, int p, int x) {
    int sum = 0;
    while (x>0) {
        sum += ftree[x][p][tp];
        x -= x&(-x);
    }
    return sum;
}

int query (int tp, int p, int l, int r) {
    l++, r++;
    return pref(tp, p, r)-pref(tp, p, l-1);
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n, m; cin >> n >> m;

    bool c[n+1][m+1] = {};

    rep (i,0,n-1) {
        rep (j,0,m-1) {
            cin >> c[i][j];
            c[i][j] ^= 1;
        }
    }

    rrep (i,n-1,0) {
        rrep (j,m-1,0) {
            bool b = 0;
            if (j<m-1) b |= c[i][j+1];
            if (i<n-1) b |= c[i+1][j];
            if (i==n-1 && j==m-1) b = 1;
            c[i][j] &= b;
            if (c[i][j]) {
                upd (0, j, i, 1);
                upd (1, i, j, 1);
            }
        }
    }

    int Q; cin >> Q;
    while (Q--) {
        int x, y; cin >> x >> y;
        x--, y--;
        if ((y==m-1 || query(0,y+1,0,x-1)==0) && (x==n-1 || query(1,x+1,0,y-1)==0)) cout << "0\n";
        else {
            cout << "1\n";
            if (!c[x][y]) continue;
            queue<ii> q;
            q.push({x,y});
            while (len(q)) {
                int i = q.front().fi, j = q.front().se;
                q.pop();
                if (i!=x || j!=y) {
                    if (!c[i][j] || c[i+1][j] || c[i][j+1]) continue;
                }
                c[i][j] = 0;
                upd (0, j, i, -1);
                upd (1, i, j, -1);
                if (i && c[i-1][j]) q.push({i-1,j});
                if (j && c[i][j-1]) q.push({i,j-1});
            }
        }
    }

   return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 724 KB Output is correct
2 Incorrect 2 ms 724 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 724 KB Output is correct
2 Incorrect 2 ms 724 KB Output isn't correct
3 Halted 0 ms 0 KB -