Language: C++

#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template<typename T>
using pque = priority_queue<T, vector<T>, greater<T>>;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

using ul = unsigned long long;
constexpr int N = 512;
int s[2][N];
ul u[2][N], a[N][N] = {};

void prt(int n){
	REP(i, n){
		REP(j, n){
			printf("%llu ", a[i][j]);
		}
		printf("\n");
	}
}

enum Quantifier {
	ALL, EXISTS,
};
pair<Quantififer, bool> get_constraints(bool p, bool q){
	if(!p && !q) return {EXISTS, 0};
	if( p && !q) return {ALL, 0};
	if( p &&  q) return {EXISTS, 1};
	if(!p &&  q) return {ALL, 1};
	exit(1);  // unreachable
}

bool b[N][N];
bool c[N], d[N];
vector<int> f, g;
void rev(){
	REP(i, N) REP(j, i) swap(b[i][j], b[j][i]);
	swap(c, d);
	swap(f, g);
}
#define REV for(int h = 0; h < 2; rev(), h++)

int main(){
	int n; scanf("%d", &n);
	REP(h, 2) REP(i, n) scanf("%d", s[h]+i);
	REP(h, 2) REP(i, n) scanf("%llu", u[h]+i);
	REP(k, 64){
		ul m = 1uLL << k;

		REV {
			f.clear();
			REP(i, n){
				auto [q, v] = get_constraints(s[h][i], u[h][i] & m);
				if(q == ALL) REP(j, n) b[i][j] = c[i].second;
				else{
					c[i] = v;
					f.emplace(i);
				}
			}
		}

		REV {
			if((int)f.size() != 1) continue;
			int ii = f[0];
			for(int j : g){
				bool ex = false;
				REP(i, n) if(i != ii) ex |= b[i][j] == d[j];
				if(ex) b[ii][j] = c[i0];
				else b[ii][j] = d[j];
			}
			f.clear();
		}

		REP(i, (int)f.size()){
			REP(j, (int)g.size()){
				b[f[i]][g[j]] = (i+j)%2;
			}
		}

		REP(i, n) REP(j, n) if(b[i][j]) a[i][j] |= m;
	}

	REV {
		REP(i, n){
			ul p[2] = {~0ull, 0};
			REP(j, n){
				p[0] &= a[i][j];
				p[1] |= a[i][j];
			}
			if(p[s[h][i]] != u[h][i]) {
#ifdef LOCAL_DEBUG
				prt(n);
#endif
				printf("-1\n");
				return 0;
			}
		}
	}
	prt(n);
}




Compiler output:
a.cc:42:6: error: 'Quantififer' was not declared in this scope; did you mean 'Quantifier'?
   42 | pair<Quantififer, bool> get_constraints(bool p, bool q){
      |      ^~~~~~~~~~~
      |      Quantifier
a.cc:42:23: error: template argument 1 is invalid
   42 | pair<Quantififer, bool> get_constraints(bool p, bool q){
      |                       ^
a.cc: In function 'int get_constraints(bool, bool)':
a.cc:43:39: error: cannot convert '<brace-enclosed initializer list>' to 'int' in return
   43 |         if(!p && !q) return {EXISTS, 0};
      |                                       ^
a.cc:44:36: error: cannot convert '<brace-enclosed initializer list>' to 'int' in return
   44 |         if( p && !q) return {ALL, 0};
      |                                    ^
a.cc:45:39: error: cannot convert '<brace-enclosed initializer list>' to 'int' in return
   45 |         if( p &&  q) return {EXISTS, 1};
      |                                       ^
a.cc:46:36: error: cannot convert '<brace-enclosed initializer list>' to 'int' in return
   46 |         if(!p &&  q) return {ALL, 1};
      |                                    ^
a.cc: In function 'int main()':
a.cc:70:38: error: cannot decompose non-array non-class type 'int'
   70 |                                 auto [q, v] = get_constraints(s[h][i], u[h][i] & m);
      |                                      ^~~~~~
a.cc:71:71: error: request for member 'second' in 'c[i]', which is of non-class type 'bool'
   71 |                                 if(q == ALL) REP(j, n) b[i][j] = c[i].second;
      |                                                                       ^~~~~~
a.cc:74:50: error: no matching function for call to 'std::vector<int>::emplace(int&)'
   74 |                                         f.emplace(i);
      |                                         ~~~~~~~~~^~~
In file included from /usr/include/c++/14/vector:66,
                 from /usr/include/c++/14/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_vector.h:1348:9: note: candidate: 'template<class ... _Args> std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::emplace(const_iterator, _Args&& ...) [with _Args = {_Args ...}; _Tp = int; _Alloc = std::allocator<int>]'
 1348 |         emplace(const_iterator __position, _Args&&... __args)
      |         ^~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1348:9: note:   template argument deduction/substitution failed:
a.cc:74:51: note:   cannot convert 'i' (type 'int') to type 'std::vector<int>::const_iterator'
   74 |                                         f.emplace(i);
      |                                                   ^
a.cc:85:53: error: 'i0' was not declared in this scope; did you mean 'ii'?
   85 |                                 if(ex) b[ii][j] = c[i0];
      |                                                     ^~
      |                                                     ii