Language: C++

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

const int N = 2e6;

int x[2][N], lz[2][N];

void build(int v, int l, int r, int n) {
    if (l == r) {
        x[0][v] = x[1][v] = n;
        return;
    }
    int m = (l + r) / 2;
    build(2 * v, l, m, n);
    build(2 * v + 1, m + 1, r, n);
    x[0][v] = x[1][v] = n;
}
void push(int t, int v) {
    if (!lz[t][v]) {
        return;
    }
    x[t][v] = min(x[t][v], lz[t][v]);
    if (!lz[t][2 * v]) {
        lz[t][2 * v] = 1e9;
    }
    if (!lz[t][2 * v + 1]) {
        lz[t][2 * v + 1] = 1e9;
    }
    lz[t][2 * v] = min(lz[t][2 * v], x[t][v]);
    lz[t][2 * v + 1] = min(lz[t][2 * v + 1], x[t][v]);
    lz[t][v] = 0;
}
int find_min(int t, int v, int l, int r, int L, int R) {
    push(t, v);
    if (L <= l && r <= R) {
        return x[t][v];
    }
    if (r < L || R < l) {
        return 1e9;
    }
    int m = (l + r) / 2;
    return min(find_min(t, 2 * v, l, m, L, R),
               find_min(t, 2 * v + 1, m + 1, r, L, R));
}
void upd(int t, int v, int l, int r, int L, int R, int z) {
    if (L <= l && r <= R) {
        if (!lz[t][v] || z < lz[t][v]) {
            lz[t][v] = z;
            push(t, v);
        }
        return;
    }
    if (r < L || R < l) {
        return;
    }
    int m = (l + r) / 2;
    upd(t, 2 * v, l, m, L, R, z);
    upd(t, 2 * v + 1, m + 1, r, L, R, z);
    x[t][v] = min(x[t][2 * v], x[t][2 * v + 1]);
}

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll n, q; cin >> n >> q;
    build(1, 1, n, n);
    ll r = (ll)(n - 2) * (n - 2);
    while (q--) {
        int t, a; cin >> t >> a;
        int b = find_min(t - 1, 1, 1, n, a, a);
        r -= max(0, b - 2);
        if (b > 1) {
            upd(2 - t, 1, 1, n, 2, b, a);
        }
    }
    cout << max(0, r) << endl;
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:78:16: error: no matching function for call to 'max(int, ll&)'
   78 |     cout << max(0, r) << endl;
      |             ~~~^~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 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:78:16: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   78 |     cout << max(0, r) << endl;
      |             ~~~^~~~~~
/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:
/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:78:16: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   78 |     cout << max(0, r) << endl;
      |             ~~~^~~~~~