Submission #1255441

#TimeUsernameProblemLanguageResultExecution timeMemory
1255441kamradFurniture (JOI20_furniture)C++20
100 / 100
128 ms4488 KiB
#include <bits/stdc++.h>
using namespace std;

//#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma,tune=native")

using ll  = long long;
using ld  = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pi3 = pair<pii, int>;

#define IOS               ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define F                 first
#define S                 second
#define sz(x)             x.size()
#define all(x)            x.begin(), x.end()
#define pb                push_back
#define minr(a, b)        a = min(a, b);
#define maxr(a, b)        a = max(a, b);
#define shit              cout << "shit\n" << flush;
#define tl                while(1&1) continue;
#define rand(l, r)        uniform_int_distribution<int64_t>(l,r)(rng)
random_device device;     default_random_engine rng(device());

const int Mod    = 1e9 + 7; //998244353;
const int LG     = 64;
const int SQ     = 500;
const int Inf    = 2e9 + 10;
const int maxN   = 1e3 + 10;

int n, m;
int q;

int cnt[maxN<<1];

bool c[maxN][maxN];
bool pe[maxN][maxN];

void update(int x, int y) {
	if(!pe[x][y])
		return;
	pe[x][y] = false;
	cnt[x+y]--;

	if(pe[x-1][y] and !pe[x-1][y+1])
		update(x-1, y);
	if(pe[x][y-1] and !pe[x+1][y-1])
		update(x, y-1);
	if(pe[x+1][y] and !pe[x+1][y-1])
		update(x+1, y);
	if(pe[x][y+1] and !pe[x-1][y+1])
		update(x, y+1);
}

int main() {
	IOS;
	
	cin >> n >> m;
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) {
			pe[i][j] = true;
			cnt[i+j]++;
		}
	}
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) {
			cin >> c[i][j];
			if(c[i][j])
				update(i, j);
		}
	}

	cin >> q;
	while(q--) {
		int x, y;
		cin >> x >> y;
		if(!pe[x][y]) {
			cout << "1\n";
			continue;
		}
		
		if(cnt[x+y]-1 > 0) {
			update(x, y);
			cout << "1\n";
		}
		else {
			cout << "0\n";
		}
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...