2018-04-28 18:14:05

#include<cstdio>
#include<queue>
#include<iostream>
#include<cstdlib>
#define neko 1000010
#define f(i,a,b) for(register int i=(a);i<=(b);i=-(~(i)))
#define rf(i,a,b) for(register int i=(a);i>=(b);i=~(-(i)))
int n,m,q,t;
typedef int arr[neko];
struct node
{
int v,next;
}e[neko];
{
e[++t].v=y;
}
namespace solve
{
using namespace std;
void contraction()
{
int now=1;
f(i,1,n){L[i]=now;if(key[i])now=i+1;}now=n;
rf(i,n,1){R[i]=now;if(key[i-1])now=i-1;}
}
bool check(int pos,int now)
{
if(!key[pos])return 1;
if(key[pos]>=L[now]&&key[pos]<=R[now])return 1;
return 0;
}
void monotonestack()
{
bool flag;int x;
queue<int>q;rf(i,n,1)if(!dgr[i])q.push(i);
while(!q.empty())
{
x=q.front(),q.pop();
flag=1;
while(flag)
{
flag=0;
while(L[x]>1&&check(L[x]-1,x))L[x]=L[L[x]-1],flag=1;
while(R[x]<n&&check(R[x],x))R[x]=R[R[x]+1],flag=1;
}travel(i,x,v)if(!(--dgr[v]))q.push(v);
}
}
}
char getc()
{
static char buf[1048576],*p1=buf,*p2=buf;
}
{
char c=getc();x=0;
while(!isdigit(c))c=getc();
while(isdigit(c))x=(x<<1)+(x<<3)+(c^'0'),c=getc();
}
int main()
{
int x,y;
solve::contraction(),solve::monotonestack();
f(i,1,q)
{
if(x>y&&L[x]<=y)putchar('Y'),putchar('E'),putchar('S'),putchar('\n');
else if(x<=y&&R[x]>=y)putchar('Y'),putchar('E'),putchar('S'),putchar('\n');
else putchar('N'),putchar('O'),putchar('\n');
}
}
• star
首页