Language: C++

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const int inf = 1e9+2;

int N;
vector<int> v;
vector<ll> can;
vector<P> pre;

int need(int l, int r, int th) {
	if (r-l == 1) {
		if (v[l] >= 0) {
			return v[l] >= th ? 0 : inf;
		}
		else {
			return 1;
		}
	}
	else {
//		assert( (r - l) % 3 == 0 );
		int d = (r - l) / 3;
		vector<int> a(3);
		for (int i = 0; i < 3; ++i) {
			a[i] = need(l + d * i, l + d * (i+1), th);
		}
		sort(a.begin(), a.end());
		return a[0] + a[1];
	}
}
signed main() {
	int M; cin >> N >> M;
	for (int i = 0; i < M; ++i) {
		int D, p; cin >> D >> p; --p;
		pre.push_back( P(D, p) );
	}
	for (int i = 0; i < N-M; ++i) {
		int D; cin >> D;
		pre.push_back( P(D, -1) );
	}

	int tN; for (tN = 1; tN < N; tN *= 3);
	for (int i = 0; i < N; ++i) {
		if (pre[i].second >= 0) {
			pre[i].second += (tN - N) / 2 * 3;
			if (pre[i].second > tN) {
				pre[i].second = (pre[i].second-tN) * 3 + 2;
			}
		}
	}
	for (int i = 0; i < (tN-N)/2; ++i) {
		pre.push_back( P(0, i*3) );
		pre.push_back( P(inf, i*3+1) );
	}
	sort( pre.begin(), pre.end() );

	N = tN; v = vector<ll>(N, -1);
	for (int i = 0; i < (int)pre.size(); ++i) {
		if (pre[i].second >= 0) {
			v[pre[i].second] = pre[i].first;
		}
		else {
			can.push_back(pre[i].first);
		}
	}
	sort(can.begin(), can.end());

	ll l = 1, r = inf;
	for (int t = 0; t < 100; ++t) {
		int m = (l + r) / 2;
		int rest = (int)can.size() - (int)(lower_bound( can.begin(), can.end(), m ) - can.begin());
		if ( need(0, N, m) <= rest ) {
			l = m;
		}
		else {
			r = m;
		}
	}
	cout << l << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:61:37: error: no match for 'operator=' (operand types are 'std::vector<int>' and 'std::vector<long long int>')
   61 |         N = tN; v = vector<ll>(N, -1);
      |                                     ^
In file included from /usr/include/c++/14/vector:72,
                 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/vector.tcc:210:5: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _Alloc>&) [with _Tp = int; _Alloc = std::allocator<int>]'
  210 |     vector<_Tp, _Alloc>::
      |     ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/vector.tcc:211:42: note:   no known conversion for argument 1 from 'std::vector<long long int>' to 'const std::vector<int>&'
  211 |     operator=(const vector<_Tp, _Alloc>& __x)
      |               ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
In file included from /usr/include/c++/14/vector:66:
/usr/include/c++/14/bits/stl_vector.h:766:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::vector<_Tp, _Alloc>&&) [with _Tp = int; _Alloc = std::allocator<int>]'
  766 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:766:26: note:   no known conversion for argument 1 from 'std::vector<long long int>' to 'std::vector<int>&&'
  766 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |                 ~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_vector.h:788:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::initializer_list<_Tp>) [with _Tp = int; _Alloc = std::allocator<int>]'
  788 |       operator=(initializer_list<value_type> __l)
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:788:46: note:   no known conversion for argument 1 from 'std::vector<long long int>' to 'std::initializer_list<int>'
  788 |       operator=(initializer_list<value_type> __l)
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~