Language: C++

#include <algorithm>
#include <cassert>
#include <cstring>
#include <iostream>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define TRACE(x) cout << #x << " = " << x << endl
#define _ << " _ " <<

typedef long long llint;

const int MAX = 100100;

char s[MAX];
vector<int> v[MAX], g[MAX];

int main(void) {
  scanf("%s", s);
  int M;
  scanf("%d", &M);
  vector<int> a(M), b(M);
  REP(i, M) {
    scanf("%d %d", &a[i], &b[i]);
    --a[i], --b[i];
  }
  
  int N = strlen(s);
  if (N % 2) {
    int mid = N / 2;
    rotate(s + mid, s + mid + 1, s + N);
    N--;

    REP(i, M) {
      if (a[i] > mid) a[i]--;
      if (b[i] >= mid) b[i]--;
    }
  }

  assert(N % 2 == 0);
  int m = N / 2;
  REP(i, M) {
    if (a[i] > b[i]) continue;
    
    if (a[i] < m && b[i] >= m) {
      int na = m + (m - a[i]);
      int nb = m - (b[i] - m) - 1;

      if (na <= b[i]) {
        a[i] = na;
      } else if (nb >= a[i]) {
        b[i] = nb;
      } else {
        continue;
      }
    }

    if (a[i] >= m) {
      int nb = m - (a[i] - m) - 1;
      int na = m - (b[i] - m) - 1;
      a[i] = na;
      b[i] = nb;
    }

    assert(0 <= a[i] && a[i] <= b[i] && b[i] < m);
    v[a[i]].push_back(b[i]);
    //    TRACE(a[i] _ b[i]);
  }

  vector<int> p_inc(m+1, 0);
  int cur_inc = 0;
  REP(i, m) {
    int need = (s[i] - s[N-i-1] + 26) % 26;
    assert(0 <= need && need < 26);
    cur_inc += p_inc[i];
    cur_inc %= 26;
    if (cur_inc < 0) cur_inc += 26;

    need = (need - cur_inc + 26) % 26;

    if (v[i].size() > 0) {
      sort(v[i].begin(), v[i].end());
      v[i].erase(unique(v[i].begin(), v[i].end()), v[i].end());
      for (int j = 1; j < (int)v[i].size(); ++j) {
        v[v[i][j-1] + 1].push_back(v[i][j]);
      }

      int j = v[i][0];
      cur_inc += need;
      p_inc[j+1] -= need;
    } else {
      if (need != 0) {
        puts("NO");
        return 0;
      }
    }
  }

  puts("YES");
  return 0;
}


Compiler output:
a.cc:18:1: error: 'vector' does not name a type
   18 | vector<int> v[MAX], g[MAX];
      | ^~~~~~
a.cc: In function 'int main()':
a.cc:24:3: error: 'vector' was not declared in this scope
   24 |   vector<int> a(M), b(M);
      |   ^~~~~~
a.cc:5:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
    4 | #include <iostream>
  +++ |+#include <vector>
    5 | 
a.cc:24:10: error: expected primary-expression before 'int'
   24 |   vector<int> a(M), b(M);
      |          ^~~
a.cc:26:21: error: 'a' was not declared in this scope
   26 |     scanf("%d %d", &a[i], &b[i]);
      |                     ^
a.cc:26:28: error: 'b' was not declared in this scope
   26 |     scanf("%d %d", &a[i], &b[i]);
      |                            ^
a.cc:37:11: error: 'a' was not declared in this scope
   37 |       if (a[i] > mid) a[i]--;
      |           ^
a.cc:38:11: error: 'b' was not declared in this scope
   38 |       if (b[i] >= mid) b[i]--;
      |           ^
a.cc:45:9: error: 'a' was not declared in this scope
   45 |     if (a[i] > b[i]) continue;
      |         ^
a.cc:45:16: error: 'b' was not declared in this scope
   45 |     if (a[i] > b[i]) continue;
      |                ^
a.cc:47:9: error: 'a' was not declared in this scope
   47 |     if (a[i] < m && b[i] >= m) {
      |         ^
a.cc:47:21: error: 'b' was not declared in this scope
   47 |     if (a[i] < m && b[i] >= m) {
      |                     ^
a.cc:60:9: error: 'a' was not declared in this scope
   60 |     if (a[i] >= m) {
      |         ^
a.cc:62:21: error: 'b' was not declared in this scope; did you mean 'nb'?
   62 |       int na = m - (b[i] - m) - 1;
      |                     ^
      |                     nb
In file included from /usr/include/c++/14/cassert:44,
                 from a.cc:2:
a.cc:67:17: error: 'a' was not declared in this scope
   67 |     assert(0 <= a[i] && a[i] <= b[i] && b[i] < m);
      |                 ^
a.cc:67:33: error: 'b' was not declared in this scope
   67 |     assert(0 <= a[i] && a[i] <= b[i] && b[i] < m);
      |                                 ^
a.cc:68:5: error: 'v' was not declared in this scope
   68 |     v[a[i]].push_back(b[i]);
      |     ^
a.cc:72:10: error: expected primary-expression before 'int'
   72 |   vector<int> p_inc(m+1, 0);
      |          ^~~
a.cc:77:16: error: 'p_inc' was not declared in this scope
   77 |     cur_inc += p_inc[i];
      |                ^~~~~
a.cc:83:9: error: 'v' was not declared in this scope
   83 |     if (v[i].size() > 0) {
      |         ^