zoukankan      html  css  js  c++  java
  • GYM 101889F(树状数组)

    bit扫描坐标套路题,注意有重复的点,莽WA了。

    const int maxn = 1e5 + 5;
    struct node {
        ll B, F, D;
    
        bool operator < (const node &rhs) const {
            if (B != rhs.B) return B > rhs.B;
            return F < rhs.F;
        }
    }a[maxn];
    int n, tot;
    ll c[maxn], ans;
    struct BIT {
        ll t[maxn];
    
        void Modify(int x, ll val) {
            for (; x; x -= x&-x)
                t[x] = max(t[x], val);
        }
    
        ll Query(int x) {
            ll ret = 0;
            for (; x <= tot; x += x&-x)
                ret = max(t[x], ret);
            return ret;
        }
    }T;
    
    int main() {
        read(n);
        rep(i, 1, n) {
            read(a[i].B);
            read(a[i].F);
            read(a[i].D);
            c[++tot] = a[i].F;
        }
    
        sort(c + 1, c + tot + 1);
        tot = unique(c + 1, c + 1 + tot) - c - 1;
        rep(i, 1, n) {
            a[i].F = lower_bound(c + 1, c + 1 + tot, a[i].F) - c;
        }
        sort(a + 1, a + 1 + n);
    
        ll tmp = 0;
        rep(i, 1, n) {
            if (a[i].B == a[i - 1].B && a[i].F == a[i - 1].F)
                tmp += a[i].D;
            else    tmp = T.Query(a[i].F + 1) + a[i].D;
            ans = max(ans, tmp);
            T.Modify(a[i].F, tmp);
        }
        writeln(ans);
        return 0;
    }
    
  • 相关阅读:
    scala-for高级用法
    scala-for
    numpy每行,没列中的最小值
    NLP
    sql-server笔记-sql
    openlayers加载geoserver的WMS服务出现点标注显示不全
    oracle删除表
    idea-debug
    python-windows安装相关问题
    mybatis-oracle 新增序列
  • 原文地址:https://www.cnblogs.com/AlphaWA/p/10673953.html
Copyright © 2011-2022 走看看