Cattle week off season to play the piano 11TG B-

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

Title Description

Spring hope to hear and yarn play the piano!
In order to prevent the occurrence of mutation, Pi piano magic changed
with N piano keys, each key has a pitch, timbre, spring Hedo three attributes
and a plurality of yarn required successively tapping keys, these keys Xi of the spring and the larger, the more satisfactory the Greek spring
However, due to the magic Pi change, after a key is Qiaoxia, the tone pitch or key and all keys will be less than its broken (i.e., can no longer be broken tap)
Pi wondered in this case, the yarn can play the piano and the greatest hope of spring and

Enter a description:

The first row of a number, N is the number of buttons 
next three rows per N lines represent bonds of the i-th pitch, timbre, spring Hedo

Output Description:

A line number, for the greatest degree of hope and spring
Example 1

Entry

copy
3
1 1 2
1 3 5
2 1 7

Export

copy
9

Remarks:

20%  N≤10N\leq 10N10
50% N≤1000N\leq 1000N1000
% 90 N≤105N \ ^ 10. 5 Leq N . 1 0 . 5 
100% N≤106N \ ^ Leq 10. 6 N . 1 0 . 6, the number of inputs are all positive integers and ≤108 \ ^ 10. 8 Leq . 1 0 8

the EMM positive solutions to this problem Fenwick tree? ? ? (But I always like tree line and never hate discrete so I wrote a qvq dynamic prescription segment tree
most simple dynamic prescription segment tree single point to modify the interval to check the value of the operation
changed to finally 90pts emmm tree line of constant or large a ride on logINF and 1 million were also less tolerant
to note that that is beginning to take root 0 emmmm
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
#define int long long
using namespace std;

const int maxn=1000005;
const int INF=2147483647;

struct node{
    int w;
    signed son[2];
}tr[maxn<<3];

struct qvq{
    int x,y,w;
}a[maxn];
inline int max(int x,int y) {
    return x>y?x:y;
}

inline bool cmp(qvq x,qvq y) {
    if (x.x==y.x) return x.y<y.y;
    return x.x<y.x;
}

int cnt;
inline void add(signed &now,int l,int r,int loc,int w) {
    if (!now) now=++cnt;
    tr[now].w=max(w,tr[now].w);
    if (l==r) return;
    int mid=l+r>>1;
    if (loc<=mid) add(tr[now].son[0],l,mid,loc,w);
    if (mid+1<=loc) add(tr[now].son[1],mid+1,r,loc,w);
}

inline int query(signed now,int l,int r,int x,int y) {
    if (!now) return 0;
    if (x<=l && r<=y) return tr[now].w;
    int ans=0,mid=l+r>>1;
    if (x<=mid) ans=max(ans,query(tr[now].son[0],l,mid,x,y));
    if (mid+1<=y) ans=max(ans,query(tr[now].son[1],mid+1,r,x,y));
    return ans;
}

signed main(){
    int n;
    scanf("%lld",&n);
    for (int i=1;i<=n;i++) 
        scanf("%lld%lld%lld",&a[i].x,&a[i].y,&a[i].w);
    sort(a+1,a+n+1,cmp);
    int ans=0;
    for (int i=1;i<=n;i++) {
        signed rt=0;
        if (i>1) rt=1;
        int val=query(rt,1,INF,1,a[i].y)+a[i].w;
        ans=max(ans,val);
        add(rt,1,INF,a[i].y,val);
    }
    printf("%lld",ans);
} 

 

 

Guess you like

Origin www.cnblogs.com/YoOXiii/p/11347846.html