zoukankan      html  css  js  c++  java
  • BZOJ 1537 Aut- The Bus

    BIT.

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #define maxn 100050
    using namespace std;
    long long n,m,k,hash[maxn],tot=0,t[maxn],f[maxn];
    struct pnt
    {
        long long x,y,w;
    }p[maxn];
    bool cmp(pnt x,pnt y)
    {
        if (x.x!=y.x) return x.x<y.x;
        return x.y<y.y;
    }
    long long find(long long x)
    {
        return lower_bound(hash+1,hash+tot+1,x)-hash;
    }
    long long lowbit(long long x) {return (x&(-x));}
    long long ask(long long x)
    {
        long long ret=0;
        for (long long i=x;i>=1;i-=lowbit(i))
            ret=max(ret,t[i]);
        return ret;
    }
    void modify(long long x,long long val)
    {
        for (long long i=x;i<=tot;i+=lowbit(i))
            t[i]=max(t[i],val);
    }
    int main()
    {
        scanf("%lld%lld%lld",&n,&m,&k);
        for (long long i=1;i<=k;i++)
        {
            scanf("%lld%lld%lld",&p[i].x,&p[i].y,&p[i].w);
            hash[++tot]=p[i].y;
        }    
        k++;p[k].x=n;p[k].y=m;p[k].w=0;hash[++tot]=m;
        sort(p+1,p+k+1,cmp);sort(hash+1,hash+tot+1);tot=unique(hash+1,hash+tot+1)-hash-1;
        for (long long i=1;i<=k;i++)
        {
            long long ret=find(p[i].y);
            f[i]=ask(ret)+p[i].w;modify(ret,f[i]);
        }
        printf("%lld
    ",f[k]);
        return 0;
    }
  • 相关阅读:
    [日常训练]大灾难
    [cf235D]Graph Game
    [日常训练]选课
    [日常训练]挂科
    [学习笔记]概率&期望
    [日常训练]yayamao的神题
    [学习笔记]原根
    LOJ#2132. 「NOI2015」荷马史诗
    LOJ#2131. 「NOI2015」寿司晚宴
    LOJ#2129. 「NOI2015」程序自动分析
  • 原文地址:https://www.cnblogs.com/ziliuziliu/p/5989832.html
Copyright © 2011-2022 走看看