[Uoj #180] [UR #12] defensive warfare outside the lab (tree array)

Source: Internet
Author: User

Description

The hour hand points to 12 o'clock midnight, the appointed day--February 28 has finally arrived. With a gunshot, the Volt-flea king led his flea army to surround Dr. Picks's laboratory.

Of course, Dr. Picks will not sit idly by, and he has long led his monkeys to build many fortified fortifications outside the laboratory.

After investigation by the Flea Scout, the Flea king found that Dr. Picks's fortifications hadn weak point, so he divided his flea army intoNTeams, and intend to allow them to attack each weak point separately. But because of the battlefield chaos, thisNThe position of the branch team was disrupted, and after the team was re-located, the Flea king found the first I "> I-position squad number is A i "> Ai (apparently A ">a is an arrangement ).

After calculation, the flea king found that let i " > i locations with squad number B i ">Bi , his army can play the maximum combat effectiveness (guaranteed B " > b is also an arrangement ).

The flea King can give orders to change the order of the squad, and every time, he will quote an integer i i ( 1 & #x2264; I &lt; N ) "> (1≤i<n). If the i "> I-position squad number is greater than i + 1 " > i+1-position squad, then the two teams will exchange order, otherwise this command will be ignored .

Now the Flea King wanted his army to be the most powerful, and he wanted to know if there was a sequence of instructions that would allow the squad to be arranged in the form of B.

But because the squad was so large, the flea king did not see the answer. So he sent fleas to kidnap you--the most famous folk scientist around here to help him figure out the answer to the question.

Solution

#include <iostream>#include<cstdlib>#include<cstdio>#include<cstring>#defineMAXN 100005using namespacestd;intN,X,A[MAXN],B[MAXN],C[MAXN];intLowbit (intx) {returnx&-x;}voidAddintPosintx) {     while(pos<=N) c[pos]=max (c[pos],x), pos+=Lowbit (POS);}intQueryintPOS) {    intres=0;  while(pos>0) Res=max (Res,c[pos]), pos-=Lowbit (POS); returnRes;} intMain () {scanf ("%d",&N);  for(intI=1; i<=n;i++) {scanf ("%d", &x); a[x]=i;}  for(intI=1; i<=n;i++) {scanf ("%d", &x); b[x]=i;}  for(intI=1; i<=n;i++) {x=query (A[i]); if(X>b[i]) {printf ("no\n");return 0;}    Add (A[i],b[i]); } printf ("yes\n"); return 0;} 

[Uoj #180] [UR #12] defensive warfare outside the lab (tree array)

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.