代码不开O2就对了?
查看原帖
代码不开O2就对了?
246331
mystic_qwq楼主2023/10/9 21:29

原题地址

事情是这样的,这道题开O2就错,不开O2就对

代码如下

#define G getchar()
static inline int r(){
  int i=0,c;
  while((c=G)<48);
  for(;c>47;c=G)i=(i<<1)+(i<<3)+(c^48);
  return i;
}main(){
  int q=r();
  while(q--){
    int n=r();
    int s[n+1],p[n+1],t[n+1],top=-1,x=0,q=0;
    s[n]=p[n]=t[n]=-1;
    for(int i=0;i<n;++i)s[i]=r();
    for(int i=0;i<n;++i)p[i]=r();
    while(q<n&&x<n){
      if(top==-1)t[++top]=s[x++];
      while(p[q]!=t[top])t[++top]=s[x++];
      while(p[q]==t[top])--top,++q;
    }
    if(q<n)puts("No");
    else puts("Yes");
  }
}
2023/10/9 21:29
加载中...