principal(括号匹配+多组查询)

时间:2023-03-08 19:08:13
principal(括号匹配+多组查询)

题目传送门:

把所有括号相匹配的段直接预处理出来就行了

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define re register
#define P pair<int,int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
const int N=1e6+;
const int mod=;
void read(int &a)
{
a=;
int d=;
char ch;
while(ch=getchar(),ch>''||ch<'')
if(ch=='-')
d=-;
a=ch-'';
while(ch=getchar(),ch>=''&&ch<='')
a=a*+ch-'';
a*=d;
}
void write(int x)
{
if(x<)
putchar(),x=-x;
if(x>)
write(x/);
putchar(x%+'');
}
int a[N],rmq[N],sta[N];
int main()
{
int n,m,T,cnt=;
read(n);
read(m);
read(T);
for(re int i=;i<=n;i++)
read(a[i]);
for(re int i=;i<=n;i++)
{
if(cnt==)
sta[++cnt]=i;
else if(a[sta[cnt]]/==a[i]/&&a[sta[cnt]]+==a[i])
cnt--;
else
sta[++cnt]=i;
rmq[i]=sta[cnt];
}
while(T--)
{
int l,r;
read(l);
read(r);
if(rmq[l-]==rmq[r])
puts("Yes");
else
puts("No");
}
return ;
}