# 【BZOJ5288】【HNOI2018】游戏（乱搞？）

## 题解

O(n2)$O(n^2)$的做法应该很容易想

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<map>
using namespace std;
#define ll long long
#define RG register
#define MAX 1001000
{
int x=0,t=1;char ch=getchar();
while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
if(ch=='-')t=-1,ch=getchar();
while(ch>='0'&&ch<='9')x=x*10+ch-48,ch=getchar();
return x*t;
}
int n,m,Q;
int L[MAX],R[MAX],K[MAX];
{
void Calc(int x)
{
int l=x,r=x,len=0;
while(233)
{
len=r-l;
while(l>1&&(!K[l-1]||(l<=K[l-1]&&K[l-1]<=r)))--l;
while(r<n&&(!K[r]||(l<=K[r]&&K[r]<=r)))++r;
if(r-l==len)break;
}
L[x]=l;R[x]=r;
}
void Solve()
{
for(int i=1;i<=n;++i)Calc(i);
while(Q--)
{
if(L[S]<=T&&T<=R[S])puts("YES");
else puts("NO");
}
}
}
namespace pf
{
void Calc1(int x)
{
int l=x,r=x,len=0;
while(233)
{
len=r-l;
while(l>1&&(!K[l-1]||(l<=K[l-1]&&K[l-1]<=r)))r=max(r,L[l-1]),l=L[l-1];
while(r<n&&(!K[r]||(l<=K[r]&&K[r]<=r)))++r;
if(r-l==len)break;
}
L[x]=l;R[x]=r;
}
void Calc2(int x)
{
int l=x,r=x,len=0;
while(233)
{
len=r-l;
while(l>1&&(!K[l-1]||(l<=K[l-1]&&K[l-1]<=r)))
{
--l;
//if(L[l])r=max(r,R[l]),l=L[l];
}
while(r<n&&(!K[r]||(l<=K[r]&&K[r]<=r)))l=min(l,R[r+1]),r=R[r+1];
if(r-l==len)break;
}
L[x]=l;R[x]=r;
}
void Solve()
{
//for(int i=1;i<=n/2;++i)Calc1(i);
for(int i=n;i>=1;--i)Calc2(i);
while(Q--)
{
if(L[S]<=T&&T<=R[S])puts("YES");
else puts("NO");
}
}
}

int main()
{
//freopen("game.in","r",stdin);
//freopen("game.out","w",stdout);
}