Language: C++

#include<bits/stdc++.h>

using namespace std;
#define int long long

typedef long long int64;
const int64 INF = 1LL << 58;

int H, W, N;
vector< int > y, x, c;
int64 uku[100000], ku[100000];
map< pair< int, int >, int64 > hashed;
map< pair< int, int >, int64 > hashed2;


void E()
{
  puts("No");
  exit(0);
}

signed main()
{

  cin >> H >> W;
  cin >> N;

  y.resize(N), x.resize(N), c.resize(N);
  vector< int > qs, qa;
  for(int i = 0; i < N; i++) {
    cin >> y[i] >> x[i] >> c[i];
    --y[i], --x[i];
    qs.push_back(y[i]);
    qa.push_back(x[i]);
  }
  sort(begin(qs), end(qs));
  qs.erase(unique(begin(qs), end(qs)), end(qs));
  sort(begin(qa), end(qa));
  qa.erase(unique(begin(qa), end(qa)), end(qa));

  for(int i = 0; i < N; i++) {
    x[i] = lower_bound(begin(qa), end(qa), x[i]) - begin(qa);
    y[i] = lower_bound(begin(ya), end(ya), y[i]) - begin(ya);
    hashed[{y[i], x[i]}] = c[i];
  }

  vector< int > idx(y.size());
  iota(begin(idx), end(idx), 0);
  sort(begin(idx), end(idx), [=](int a, int b)
  {
    return (make_pair(y[a], x[a]) < make_pair(y[b], x[b]));
  });


  fill_n(uku, 100000, INF);

  for(int i = 1; i < N; i++) {
    int a = idx[i - 1], b = idx[i];
    if(y[a] == y[b] && x[b] - x[a] == 1) {
      if(uku[x[a]] != INF && uku[x[a]] != c[b] - c[a]) E();
      uku[x[a]] = c[b] - c[a];
    }
  }

  for(int i = 0; i < N; i++) {
    if(x[i] - 1 >= 0) {
      if(uku[x[i] - 1] < INF) {
        int64 val = c[i] - uku[x[i] - 1];
        if(val < 0) E();
        if(hashed.count({y[i], x[i] - 1}) && hashed[{y[i], x[i] - 1}] != val) E();
        hashed[{y[i], x[i] - 1}] = val;

        x.push_back(x[i] - 1);
        y.push_back(y[i]);
        c.push_back(val);
      }
    }
    if(x[i] + 1 < W) {
      if(uku[x[i]] < INF) {
        int64 val = c[i] + uku[x[i]];
        if(val < 0) E();
        if(hashed.count({y[i], x[i] + 1}) && hashed[{y[i], x[i] + 1}] != val) E();
        hashed[{y[i], x[i] + 1}] = val;
        x.push_back(x[i] + 1);
        y.push_back(y[i]);
        c.push_back(val);
      }
    }
  }


  idx.resize(y.size());
  iota(begin(idx), end(idx), 0);
  swap(x, y);
  swap(W, H);
  for(auto k : hashed) hashed2[{k.first.second, k.first.first}] = k.second;
  swap(hashed, hashed2);
  fill_n(uku, 100000, INF);

  sort(begin(idx), end(idx), [=](int a, int b)
  {
    return (make_pair(y[a], x[a]) < make_pair(y[b], x[b]));
  });


  for(int i = 1; i < y.size(); i++) {
    int a = idx[i - 1], b = idx[i];
    if(y[a] == y[b] && x[b] - x[a] == 1) {
      if(uku[x[a]] != INF && uku[x[a]] != c[b] - c[a]) E();
      uku[x[a]] = c[b] - c[a];
    }
  }

  for(int i = 0; i < y.size(); i++) {
    if(x[i] - 1 >= 0) {
      if(uku[x[i] - 1] < INF) {
        int64 val = c[i] - uku[x[i] - 1];
        if(val < 0) E();
        if(hashed.count({y[i], x[i] - 1}) && hashed[{y[i], x[i] - 1}] != val) E();
        hashed[{y[i], x[i] - 1}] = val;
      }
    }
    if(x[i] + 1 < W) {
      if(uku[x[i]] < INF) {
        int64 val = c[i] + uku[x[i]];
        if(val < 0) E();
        if(hashed.count({y[i], x[i] + 1}) && hashed[{y[i], x[i] + 1}] != val) E();
        hashed[{y[i], x[i] + 1}] = val;
      }
    }
  }

  throw (0);
  puts("Yes");

}


Compiler output:
a.cc: In function 'int main()':
a.cc:43:30: error: 'ya' was not declared in this scope; did you mean 'qa'?
   43 |     y[i] = lower_bound(begin(ya), end(ya), y[i]) - begin(ya);
      |                              ^~
      |                              qa