Dried fish sister small embedding

Links: https://ac.nowcoder.com/acm/contest/992/B
Source: Cattle-off network

Time limit: C / C ++ 1 second, 2 seconds languages other
space restrictions: C / C ++ 32768K, other languages 65536k
64bit the IO the Format: LLD%

Title Description

Before a fire animation very "dry matter little sister buried" in everyone playing the game for a small Coke buried very deep impression.
Now Ernie sauce will bury small pleasures hidden in all the water separated from the top of the furniture.
Small resorted to burying ground tactical air 1080 ° turn on a roll jump to any furniture, she believes, as long as she tumbling fast enough, Ernie sauce to keep up with her.
 
1. To get a dream start, buried a small set of skills so that she can start a fall on any furniture.
2. Small buried home furniture in order to give each furniture can not jump jump, Ernie sauce to avoid pursuit, small buried after tumbling to a furniture above, can only continue to roll forward.
3. Start small gravity-sensing system buried not roll from a higher to a lower furniture furniture.
4. Since the value of the joy happy water on each of furniture has a corresponding, IQ == 250 selects a small embedded happy maximum sum value of the route.
So, happy little sum value of the final will be buried obtained is how much?

Enter a description:

The first line of an integer n (0 <n <= 200000 ), represents the number of buried small home furniture. 

The second line n integers, for each integer ai, 0 <= ai <= 10 ^ 9, represents the height of the i-th furniture.

The third row of n integer, for each integer vi, 0 <= vi <= 10 ^ 9, the value represents the happy happy water on the i-th furniture.

Output Description:

An integer representing the total value is smaller happy buried obtained.
Example 1

Entry

copy
6
2 1 1 3 3 4
3 1 1 1 1 1

Export

copy
6

Explanation

Route: 2-> 3-> 3-> 4 

Answer: 3 + 1 + 1 + 1
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+7;
int n;
ll c[maxn];
ll a[maxn],val[maxn],t[maxn];
ll lowbit(int x){
    return x&(-x);
}
ll query(int pos){
    ll cur=0;
    while(pos>=1){
        cur=max(cur,c[pos]);
        pos-=lowbit(pos);
    }
    return cur;
}
void update(int pos,ll val){
    while(pos<=n){
        c[pos]=max(c[pos],val);
        pos+=lowbit(pos);
    }
}
int main(){
    //freopen("1.txt","r",stdin);
    scanf("%d",&n);
    for(register int i=1;i<=n;++i){
        scanf("%lld",a+i);
        t[i]=a[i];
    }
    for(register int i=1;i<=n;++i){
        scanf("%lld",val+i);
    }
    sort(t+1,t+1+n);
    int cnt=unique(t+1,t+1+n)-t-1;
    for(int i=1;i<=n;++i){
        a[i]=lower_bound(t+1,t+1+cnt,a[i])-t;
    }
    for(register int i=1;i<=n;++i){
        val[i]+=query(a[i]);
        update(a[i],val[i]);
    }
    ll ans=0;
    for(register int i=1;i<=n;++i){
        ans=max(ans,val[i]);
    }
    printf("%lld\n",ans);
    return 0;
}
View Code

 

Guess you like

Origin www.cnblogs.com/czy-power/p/11257671.html