"Topic link"
http://uoj.ac/problem/180
Test instructions
Given two X 1: n Permutation AB, if ai<ai+1 can exchange AI and ai+1, ask if it is possible to convert a to B.
Ideas
A[i] Indicates where I appears in A, B[i] indicates where I appears in B.
If I<j is satisfied and no a[i]<a[j]&&b[i]>a[j] is present, output yes, otherwise output No.
It can be judged by maintaining the maximum value in a tree-like array.
Prove
Code
1#include <Set>2#include <cmath>3#include <queue>4#include <vector>5#include <cstdio>6#include <cstring>7#include <iostream>8#include <algorithm>9 #defineTrav (u,i) for (int i=front[u];i;i=e[i].nxt)Ten #definefor (A,B,C) for (int a= (b); a<= (c); a++) One using namespacestd; A -typedefLong Longll; - Const intN = 2e5+Ten; the - ll Read () { - CharC=GetChar (); -ll f=1, x=0; + while(!IsDigit (c)) { - if(c=='-') f=-1; C=GetChar (); + } A while(IsDigit (c)) atx=x*Ten+c-'0', c=GetChar (); - returnx*F; - } - - intA[n],b[n],x[n]; - intN; in - intC[n]; to voidUpdintXintv) + { - for(; x<=n;x+=x&-x) thec[x]=Max (c[x],v); * } $ intQueryintx)Panax Notoginseng { - intres=0; the for(; x;x-=x&-x) +res=Max (res,c[x]); A returnRes; the } + - intMain () $ { $n=read (); -for (I,1, N) { -x[i]=read (); thea[x[i]]=i; - }Wuyifor (I,1, N) { thex[i]=read (); -b[x[i]]=i; Wu } -for (I,1, N) { About intx=query (A[i]); $ if(b[i]<x) {Puts ("NO");return 0; } - upd (A[i],b[i]); - } -Puts"YES"); A return 0; +}
p.s. Uoj Bar
"UR #12" out-of-Lab offensive warfare (BIT)