Submission #553123

# Submission time Handle Problem Language Result Execution time Memory
553123 2022-04-24T17:35:42 Z cheetose Furniture (JOI20_furniture) C++17
0 / 100
6 ms 9372 KB
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y0 y12
#define y1 y22
#define INF 987654321987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset((a),0,sizeof(a))
#define MEM_1(a) memset((a),-1,sizeof(a))
#define ALL(a) a.begin(),a.end()
#define COMPRESS(a) sort(ALL(a));a.resize(unique(ALL(a))-a.begin())
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<ld, ld> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<ld> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const int MOD = 1000000007;
ll POW(ll a, ll b, ll MMM = MOD) { ll ret = 1; for (; b; b >>= 1, a = (a*a) % MMM)if (b & 1)ret = (ret*a) % MMM; return ret; }
int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 };
int ddx[] = { -1,-2,1,-2,2,-1,2,1 }, ddy[] = { -2,-1,-2,1,-1,2,1,2 };

int a[1005][1005];
int p[2][1111111];
set<int> LR[1005],UD[1005];
int n,m;
inline int z(int x,int y){return x*(m+2)+y;}
int f(int i,int x){return x==p[i][x]?x:p[i][x]=f(i,p[i][x]);}
void merge(int i,int x,int y){p[i][f(i,x)]=f(i,y);}
int main(){
	iota(p[0],p[0]+1111111,0);
	iota(p[1],p[1]+1111111,0);
	scanf("%d%d",&n,&m);
	LR[0].insert(1);
	LR[n+1].insert(m);
	UD[0].insert(1);
	UD[m+1].insert(n);
	fup(i,1,n,1){
		fup(j,1,m,1){
			scanf("%d",a[i]+j);
			if(a[i][j]){
				LR[i].insert(j);
				UD[j].insert(i);
			}
		}
	}
	fup(i,1,n,1){
		fup(j,0,1,1){
			merge(j,z(i,m+1),z(0,1));
			merge(j,z(i,0),z(1,0));
		}
		a[i][0]=a[i][m+1]=1;
	}
	fup(i,1,m,1){
		fup(j,0,1,1){
			merge(j,z(0,i),z(0,1));
			merge(j,z(n+1,i),z(1,0));
		}
		a[0][i]=a[n+1][i]=1;
	}
	fup(x,1,n+1,1){
		for(int y:LR[x]){
			auto it=LR[x-1].upper_bound(y);
			if(it!=LR[x-1].begin()){
				it--;
				merge(0,z(x,y),z(x-1,*it));
			}
			if(x!=n+1){
				fup(k,0,7,1){
					int nx=x+dx[k],ny=y+dy[k];
					if(a[nx][ny]){
						merge(0,z(x,y),z(nx,ny));
					}
				}
			}
		}
	}
	fup(y,1,m+1,1){
		for(int x:UD[y]){
			auto it=UD[y-1].upper_bound(x);
			if(it!=UD[y-1].begin()){
				it--;
				merge(1,z(x,y),z(*it,y-1));
			}
			if(y!=m+1){
				fup(k,0,7,1){
					int nx=x+dx[k],ny=y+dy[k];
					if(a[nx][ny]){
						merge(1,z(x,y),z(nx,ny));
					}
				}
			}
		}
	}
	int q;
	scanf("%d",&q);
	while(q--){
		int x,y;
		scanf("%d%d",&x,&y);
		bool ok=1;
		int t=0;
		fup(k,0,7,1){
			int nx=x+dx[k],ny=y+dy[k];
			if(a[nx][ny]){
				if(f(0,z(0,1))==f(0,z(nx,ny)))t|=1;
				if(f(0,z(1,0))==f(0,z(nx,ny)))t|=2;
			}
		}
		auto it=LR[x-1].upper_bound(y);
		if(it!=LR[x-1].begin()){
			it--;
			int nx=x-1,ny=*it;
			if(f(0,z(0,1))==f(0,z(nx,ny)))t|=1;
			if(f(0,z(1,0))==f(0,z(nx,ny)))t|=2;
		}
		it=LR[x+1].lower_bound(y);
		if(it!=LR[x+1].end()){
			int nx=x+1,ny=*it;
			if(f(0,z(0,1))==f(0,z(nx,ny)))t|=1;
			if(f(0,z(1,0))==f(0,z(nx,ny)))t|=2;
		}
		if(t==3)ok=0;
		t=0;
		fup(k,0,7,1){
			int nx=x+dx[k],ny=y+dy[k];
			if(a[nx][ny]){
				if(f(1,z(0,1))==f(1,z(nx,ny)))t|=1;
				if(f(1,z(1,0))==f(1,z(nx,ny)))t|=2;
			}
		}
		it=UD[y-1].upper_bound(x);
		if(it!=UD[y-1].begin()){
			it--;
			int nx=*it,ny=y-1;
			if(f(1,z(0,1))==f(1,z(nx,ny)))t|=1;
			if(f(1,z(1,0))==f(1,z(nx,ny)))t|=2;
		}
		it=UD[y+1].lower_bound(x);
		if(it!=UD[y+1].end()){
			int nx=*it,ny=y+1;
			if(f(1,z(0,1))==f(1,z(nx,ny)))t|=1;
			if(f(1,z(1,0))==f(1,z(nx,ny)))t|=2;
		}
		if(t==3)ok=0;
		printf("%d\n",ok);
		if(ok){
			a[x][y]=1;
			fup(k,0,7,1){
				int nx=x+dx[k],ny=y+dy[k];
				if(a[nx][ny]){
					merge(0,z(x,y),z(nx,ny));
					merge(1,z(x,y),z(nx,ny));
				}
			}
			it=LR[x-1].upper_bound(y);
			if(it!=LR[x-1].begin()){
				it--;
				int nx=x-1,ny=*it;
				merge(0,z(x,y),z(nx,ny));
			}
			it=LR[x+1].lower_bound(y);
			if(it!=LR[x+1].end()){
				int nx=x+1,ny=*it;
				merge(0,z(x,y),z(nx,ny));
			}
			it=UD[y-1].upper_bound(x);
			if(it!=UD[y-1].begin()){
				it--;
				int nx=*it,ny=y-1;
				merge(1,z(x,y),z(nx,ny));
			}
			it=UD[y+1].lower_bound(x);
			if(it!=UD[y+1].end()){
				int nx=*it,ny=y+1;
				merge(1,z(x,y),z(nx,ny));
			}
			LR[x].insert(y);
			UD[y].insert(x);
		}
	}
}

Compilation message

furniture.cpp: In function 'int main()':
furniture.cpp:10:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
furniture.cpp:58:2: note: in expansion of macro 'fup'
   58 |  fup(i,1,n,1){
      |  ^~~
furniture.cpp:10:30: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
furniture.cpp:59:3: note: in expansion of macro 'fup'
   59 |   fup(j,1,m,1){
      |   ^~~
furniture.cpp:10:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
furniture.cpp:67:2: note: in expansion of macro 'fup'
   67 |  fup(i,1,n,1){
      |  ^~~
furniture.cpp:10:30: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
furniture.cpp:68:3: note: in expansion of macro 'fup'
   68 |   fup(j,0,1,1){
      |   ^~~
furniture.cpp:10:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
furniture.cpp:74:2: note: in expansion of macro 'fup'
   74 |  fup(i,1,m,1){
      |  ^~~
furniture.cpp:10:30: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
furniture.cpp:75:3: note: in expansion of macro 'fup'
   75 |   fup(j,0,1,1){
      |   ^~~
furniture.cpp:10:30: warning: unnecessary parentheses in declaration of 'x' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
furniture.cpp:81:2: note: in expansion of macro 'fup'
   81 |  fup(x,1,n+1,1){
      |  ^~~
furniture.cpp:10:30: warning: unnecessary parentheses in declaration of 'k' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
furniture.cpp:89:5: note: in expansion of macro 'fup'
   89 |     fup(k,0,7,1){
      |     ^~~
furniture.cpp:10:30: warning: unnecessary parentheses in declaration of 'y' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
furniture.cpp:98:2: note: in expansion of macro 'fup'
   98 |  fup(y,1,m+1,1){
      |  ^~~
furniture.cpp:10:30: warning: unnecessary parentheses in declaration of 'k' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
furniture.cpp:106:5: note: in expansion of macro 'fup'
  106 |     fup(k,0,7,1){
      |     ^~~
furniture.cpp:10:30: warning: unnecessary parentheses in declaration of 'k' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
furniture.cpp:122:3: note: in expansion of macro 'fup'
  122 |   fup(k,0,7,1){
      |   ^~~
furniture.cpp:10:30: warning: unnecessary parentheses in declaration of 'k' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
furniture.cpp:144:3: note: in expansion of macro 'fup'
  144 |   fup(k,0,7,1){
      |   ^~~
furniture.cpp:10:30: warning: unnecessary parentheses in declaration of 'k' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
furniture.cpp:168:4: note: in expansion of macro 'fup'
  168 |    fup(k,0,7,1){
      |    ^~~
furniture.cpp:53:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   53 |  scanf("%d%d",&n,&m);
      |  ~~~~~^~~~~~~~~~~~~~
furniture.cpp:60:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |    scanf("%d",a[i]+j);
      |    ~~~~~^~~~~~~~~~~~~
furniture.cpp:116:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  116 |  scanf("%d",&q);
      |  ~~~~~^~~~~~~~~
furniture.cpp:119:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  119 |   scanf("%d%d",&x,&y);
      |   ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 9372 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 9372 KB Output isn't correct
2 Halted 0 ms 0 KB -