Language: C++

#include <set>
#include <map>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

#define pb push_back
#define mp make_pair
#define x first
#define y second

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;

template <class T>
void read(T &x)
{
	char ch;
	for (ch=getchar();(ch<'0'||ch>'9')&&ch!='-';) ch=getchar();
	x=0;int t=1;if (ch=='-') {ch=getchar();t=-1;}
	for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	x*=t;
}

const int N=100010;

struct node
{
	int l,r;
}a[N];

char b[N];
int h[N];
pii w[N],s[N];
map<pii,int> g;
int head[N],tail[N],fa[N*3],d[N],next[N*2];
bool ok[N];

int find(int x)
{
	if (x!=fa[x]) fa[x]=find(fa[x]);
	return fa[x];
}

int main()
{
	srand(time(0));
	#ifndef ONLINE_JUDGE
		//freopen("input.txt","r",stdin);
		//freopen("output.txt","w",stdout);
	#endif
	scanf("%s",b+1);int n=strlen(b+1);
	int m,m0=0;scanf("%d",&m);memset(h,0,sizeof(h));
	for (int i=1;i<=m;i++)
	{
		int l,r;scanf("%d%d",&l,&r);h[l]++;h[r+1]--;
		if (l+r==n+1) continue;
		if (r<=(n+1)/2) {a[++m0].l=l;a[m0].r=min(r,n/2);continue;}
		if (l>=(n+1)/2) {a[++m0].l=n-r+1;a[m0].r=n-max(l,(n+1)/2+1)+1;continue;}
		if (l+r<=n) {a[++m0].l=l;a[m0].r=n-r;} else {a[++m0].l=n-r+1;a[m0].r=l-1;}
	}
	for (int i=1;i<=n;i++) h[i]+=h[i-1];
	for (int i=1;i<=n/2;i++) if (h[i]==0&&h[n+1-i]==0&&b[i]!=b[n+1-i]) {puts("NO");return 0;}
	for (int i=1;i<=m0;i++) {w[i].x=rand();w[i].y=rand();}
	for (int i=1;i<=m0;i++)
	{
		s[a[i].l].x^=w[i].x;s[a[i].r+1].x^=w[i].x;
		s[a[i].r].y^=w[i].y;s[a[i].r+1].y^=w[i].y;
	}
	for (int i=1;i<=n/2;i++)
	{
		s[i].x^=s[i-1].x;s[i].y^=s[i-1].y;
		if (!g[s[i]])
			g[s[i]]=b[i]-b[n+1-i]+35;
		else
			if (g[s[i]]!=b[i]-b[n+1-i]+35) {puts("NO");return 0;}
	}
	for (int i=1;i<=n/2+1;i++) head[i]=0;
	for (int i=2;i<=2*m0+2+n/2;i++) fa[i]=i;
	for (int i=1;i<=n/2+1;i++) d[i]=(i==n/2+1 ? 0 : b[i]-b[n+1-i])-(i==0 ? 0: b[i-1]-b[n+2-i]);
	for (int i=1;i<=m0;i++)
	{
		fa[2*i]=2*m0+1+a[i].l;fa[2*i+1]=2*m0+2+a[i].r;
		if (head[a[i].l]) next[2*i]=head[a[i].l]; else tail[a[i].l]=2*i;head[a[i].l]=2*i;
		if (head[a[i].r+1]) next[2*i+1]=head[a[i].r+1]; else tail[a[i].r+1]=2*i+1;head[a[i].r+1]=2*i+1;
	}
	memset(ok,0,sizeof(ok));
	for (int i=1;i<=n/2+1;i++)
	{
		while (head[i]&&ok[head[i]/2]) head[i]=next[head[i]];
		if (head[i]==0&&d[i]) {puts("NO");return 0;}
		ok[head[i]/2]=1;int x=find(head[i]^1)-m0*2-1;fa[i+m0*2+1]=x*m0*2+1;
		d[x]+=d[i];next[tail[i]]=head[x];head[x]=head[i];
	}
	puts("YES");
	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:92:35: error: reference to 'next' is ambiguous
   92 |                 if (head[a[i].l]) next[2*i]=head[a[i].l]; else tail[a[i].l]=2*i;head[a[i].l]=2*i;
      |                                   ^~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:66,
                 from /usr/include/c++/14/bits/stl_tree.h:63,
                 from /usr/include/c++/14/set:62,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:44:34: note:                 'int next [200020]'
   44 | int head[N],tail[N],fa[N*3],d[N],next[N*2];
      |                                  ^~~~
a.cc:93:37: error: reference to 'next' is ambiguous
   93 |                 if (head[a[i].r+1]) next[2*i+1]=head[a[i].r+1]; else tail[a[i].r+1]=2*i+1;head[a[i].r+1]=2*i+1;
      |                                     ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:44:34: note:                 'int next [200020]'
   44 | int head[N],tail[N],fa[N*3],d[N],next[N*2];
      |                                  ^~~~
a.cc:98:56: error: reference to 'next' is ambiguous
   98 |                 while (head[i]&&ok[head[i]/2]) head[i]=next[head[i]];
      |                                                        ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:44:34: note:                 'int next [200020]'
   44 | int head[N],tail[N],fa[N*3],d[N],next[N*2];
      |                                  ^~~~
a.cc:101:28: error: reference to 'next' is ambiguous
  101 |                 d[x]+=d[i];next[tail[i]]=head[x];head[x]=head[i];
      |                            ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:44:34: note:                 'int next [200020]'
   44 | int head[N],tail[N],fa[N*3],d[N],next[N*2];
      |                                  ^~~~