Language: C++

#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
#include <vector>
#include <queue>
#include <numeric>
using namespace std;

const int64_t MOD = 1000000007;

int main() {
	int n,m;
	cin >> n >> m;
	vector<int64_t> a, b;
	for (int i = 0; i < n; ++i) {
		int64_t ai;
		cin >> ai;
		a.push_back(ai);
	}
	for (int i = 0; i < m; ++i) {
		int64_t bi;
		cin >> bi;
		b.push_back(bi);
	}
	sort(a.rbegin(), a.rend());
	sort(b.rbegin(), b.rend());
	vector<vector<int64_t>> field(n, vector<int64_t>(m, 0));
	if (a[0] != n * m || b[0] != n * m) {
		cout << "0" << endl;
		return 0;
	}
	int w, h;
	w = h = 1;
	int64_t filled = 1;
	int64_t pat = 1;
	int64_t plc = n * m - 1;
	for(int64_t plc=n*m-1; plc>0 ; plc--){
		int64_t next_ylim;
		if (h == n) next_ylim = -1;
		else next_ylim = a[h];
		int64_t next_xlim;
		if (w == m) next_xlim = -1;
		else next_xlim = b[w];
		if (plc > max(next_ylim, next_xlim)) {
			int64_t cpat = max(w*h - filled, 0LL);
			pat = (pat * cpat) % MOD;
			filled++;
		}
		else if (plc == next_ylim && plc > next_xlim) {
			h++;
			pat = (pat*w) % MOD;
			filled++;
		}
		else if (plc == next_xlim && plc > next_ylim) {
			w++;
			pat = (pat*h) % MOD;
			filled++;
		}
		else if (plc == next_xlim && plc == next_ylim) {
			filled++;
			w++;
			h++;
		}
		else {
			pat = 0;
		}
		if (pat == 0) break;
	}
	cout << pat << endl;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:47:43: error: no matching function for call to 'max(int64_t, long long int)'
   47 |                         int64_t cpat = max(w*h - filled, 0LL);
      |                                        ~~~^~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/vector:62,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:47:43: note:   deduced conflicting types for parameter 'const _Tp' ('long int' and 'long long int')
   47 |                         int64_t cpat = max(w*h - filled, 0LL);
      |                                        ~~~^~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:3:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:47:43: note:   mismatched types 'std::initializer_list<_Tp>' and 'long int'
   47 |                         int64_t cpat = max(w*h - filled, 0LL);
      |                                        ~~~^~~~~~~~~~~~~~~~~~~