Language: C++

#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
 
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
 
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define endl '\n'
#define x first
#define y second
#define int unsigned long long
#define double long double
#define pii pair<int, int>
#define pb push_back
#define vec vector
#define beg begin
#define dbg(x) cout << #x << " = " << x << endl;
 
template<class T> ostream& operator<<(ostream &str, vector<T> &a) {
    for (auto &i : a) {
        str << i << " ";
    }
    return str;
}
 
template<class T> istream& operator>>(istream &str, vector<T> &a) {
    for (auto &i : a) {
        str >> i;
    }
    return str;
}
 
template<class T> ostream& operator<<(ostream &str, pair<T, T> &a) {
    str << a.first << " " << a.second;
    return str;
}
 
template<class T> istream& operator>>(istream &str, pair<T, T> &a) {
    str >> a.first >> a.second;
    return str;
}
 
void solve(); signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
#endif
    srand(time(0));
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout.setf(ios::fixed); cout.precision(9);
    solve();
    return 0;
}
 
const int MOD = 998244353, MAXN = 1e6 + 10, INF = 1e18 + 10, BASE = 37;

void solve() {
	int n;
	cin >> n;
	vec<int> s(n), t(n), u(n), v(n);
	cin >> s >> t >> u >> v;

	vec<vec<int>> ans(n, vec<int>(n)); 
	for (int i = 0; i < n; ++i) {
	 	if (s[i] == 0) {
	 	 	for (int j = 0; j < n; ++j) {
	 	 	 	ans[i][j] |= u[i];
	 	 	}
	 	}
	}
	for (int j = 0; j < n; ++j) {
	 	if (t[j] == 0) {
	 	 	for (int i = 0; i < n; ++i) {
	 	 	 	ans[i][j] |= v[j];
	 	 	}
	 	}
	}

	for (int i = 0; i < n; ++i) {
	 	if (s[i] == 1) {
	 	    for (int j = 0; j < n; ++j) {
	 	     	if (t[j] == 1) {
	 	     	    for (int k = 0; k < 64; ++k) {
	 	     	     	if (((v[j] >> k) & 1ull) && ((u[i] >> k) & 1ull)) {
	 	     	     	 	ans[i][j] |= (1ull << k);
	 	     	     	}
	 	     	    }
	 	     	}	
	 	    }
	 	}	
	}
	for (int j = 0; j < n; ++j) {
	 	if (t[j] == 1) {
	 	 	for (int i = 0; i < n; ++i) {
	 	 	    if (s[i] == 1) {
	 	 	     	for (int k = 0; k < 64; ++k) {
	 	 	     	 	if (((v[j] >> k) & 1ull) && ((u[i] >> k) & 1ull)) {
	 	 	     	 	 	ans[i][j] |= (1ull << k);
	 	 	     	 	}
	 	 	     	}
	 	 	    }
	 	 	}	
	 	}
	}

	bool ok = true;
	for (int i = 0; i < n; ++i) {
		int num = ans[i][0];
	 	if (s[i] == 0) {
	 	 	for (int j = 1; j < n; ++j) {
	 	 	 	num &= ans[i][j];
	 	 	}
	 	}
	 	else {
	 	 	for (int j = 1; j < n; ++j) {
	 	 		num |= ans[i][j];
	 	 	}
	 	}
	 	if (num != u[i]) ok = false;
	}

	for (int j = 0; j < n; ++j) {
	    int num = ans[0][j];
	    if (t[j] == 0) {
	     	for (int i = 1; i < n; ++i) {
	     	 	num &= ans[i][j];
	     	}
	    }
	    else {
	     	for (int i = 1; i < n; ++i) {
	     	    num |= ans[i][j];
	     	}	
	    }
		if (num != v[j]) ok = false;
	}	

	if (!ok) {
	 	cout << -1 << endl;
	 	return;
	}  

	for (int i = 0; i < n; ++i) {
	 	for (int j = 0; j < n; ++j) {
	 	 	cout << ans[i][j] << " ";
	 	}
	 	cout << endl;
	}
}






Compiler output:
In file included from /usr/include/c++/14/string:43,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
                 from a.cc:7:
/usr/include/c++/14/bits/allocator.h: In destructor 'std::_Vector_base<long long unsigned int, std::allocator<long long unsigned int> >::_Vector_impl::~_Vector_impl()':
/usr/include/c++/14/bits/allocator.h:182:7: error: inlining failed in call to 'always_inline' 'std::allocator< <template-parameter-1-1> >::~allocator() noexcept [with _Tp = long long unsigned int]': target specific option mismatch
  182 |       ~allocator() _GLIBCXX_NOTHROW { }
      |       ^
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:
/usr/include/c++/14/bits/stl_vector.h:132:14: note: called from here
  132 |       struct _Vector_impl
      |              ^~~~~~~~~~~~