"UR #12" out-of-Lab offensive warfare (BIT)

Source: Internet
Author: User

"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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.