Language: C++

#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <deque>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <cassert>
#include <iostream>
#include <stdio.h>
#include <time.h>
 
using namespace std;

typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define clr(a, b) memset((a), (b) ,sizeof(a))

#define N_MAX (1<<19)

struct segsst{
  int nn;
  long long dat1[(2 * N_MAX) - 1];
  long long dat2[(2 * N_MAX) - 1];

  void init(long long n1) {
    nn = 1;

    while (nn < n1)nn *= 2;

    for (long long i = 0; i < 2 * nn - 1; i++) {
      dat1[i] = 0;
      dat2[i] = 0;
    }
  }

  void add(long long a, long long b, long long x, long long k, long long l, long long r) {
    if (r <= a || b <= l)return;
    if (a <= l && r <= b) {
      dat2[k] += x;
      return;
    }
    add(a, b, x, k * 2 + 1, l, (l + r) / 2);
    add(a, b, x, k * 2 + 2, (l + r) / 2, r);

    dat1[k] = min(dat1[k * 2 + 1] + dat2[k * 2 + 1], dat1[k * 2 + 2] + dat2[k * 2 + 2]);
  }

  void add(a,b,x){
    add(a,b,x,0,0,nn);
  }

  long long query(long long a, long long b, long long k, long long l, long long r) {
    if (b <= l || r <= a)return INF;
    if (a <= l && r <= b) {
      return (dat1[k] + dat2[k]);
    }
    else {
      long long vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
      long long vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
      return min(vl,vr) + dat2[k];
    }
  }

  long long query(long long a, long long b) {
    return query(a,b,0,0,nn);
  }
}segsst1,segsst2;


int main(){
  segsst1.init(n+200);
  segsst2.init(n+200);
  segsst1.add(1,n,1);
  segsst2.add(1,n,1);
  ll n,q;
  cin>>n>>q;
  ll mn1 = n-1;
  ll mn2 = n-1;
  ll ans = 0;
  rep(i,0,q){
    ll a,b;
    cin>>a>>b;
    if(a==1){
      if(b<mn1){
        mn1 = b;
        ans += mn2-1;
        ll c = segsst2.query(1,2);
        segsst2.add(1,b,b-c);
      }
      else{
        ll c = segsst1.query(b,b+1);
        ans += c-1;
      }
    }
    else{
      if(b<mn2){
        mn2 = b;
        ans += mn1-1;
        ll c = segsst1.query(1,2);
        segsst1.add(1,b,b-c);
      }
      else{
        ll c = segsst2.query(b,b+1);
        ans += c-1;
      }
    }
  }
  cout << (n-2)*(n-2)-ans << endl;
  return 0;
}

Compiler output:
a.cc:69:12: error: 'a' has not been declared
   69 |   void add(a,b,x){
      |            ^
a.cc:69:14: error: 'b' has not been declared
   69 |   void add(a,b,x){
      |              ^
a.cc:69:16: error: 'x' has not been declared
   69 |   void add(a,b,x){
      |                ^
a.cc: In member function 'void segsst::add(int, int, int)':
a.cc:70:9: error: 'a' was not declared in this scope
   70 |     add(a,b,x,0,0,nn);
      |         ^
a.cc:70:11: error: 'b' was not declared in this scope; did you mean 'pb'?
   70 |     add(a,b,x,0,0,nn);
      |           ^
      |           pb
a.cc:70:13: error: 'x' was not declared in this scope
   70 |     add(a,b,x,0,0,nn);
      |             ^
a.cc: In member function 'long long int segsst::query(long long int, long long int, long long int, long long int, long long int)':
a.cc:74:33: error: 'INF' was not declared in this scope
   74 |     if (b <= l || r <= a)return INF;
      |                                 ^~~
a.cc: In function 'int main()':
a.cc:92:16: error: 'n' was not declared in this scope; did you mean 'yn'?
   92 |   segsst1.init(n+200);
      |                ^
      |                yn