zoukankan      html  css  js  c++  java
  • [补]2019HDU杭电多校第六场E

    又是红小豆写不出的矩阵问题

    参考于:https://blog.csdn.net/qq_40942372/article/details/98778632

      

    HDU-6638 Snowy Smile

      话说第七场才是打得心凉凉)

      场上枚举点wa了几发之后发现不能这样搞啊,然后就没有然后了。

      线段树维护动态最大子段和和看起来很聪明的亚子的枚举边界

    #include<iostream>
    #include<cstdio>
    #include<algorithm>
    #include<cmath>
    using namespace std;
    typedef long long LL;
    int t, n;
    int x[2005], y[2005];
    struct node
    {
        int x, y;
        LL w;
    }po[2005];
    
    struct st
    {
    #define ls i<<1
    #define rs i<<1|1
    
        struct node
        {
            LL pe, sr, ma, su;
        }p[2005 << 2];
    
        void puu(int i)
        {
            p[i].pe = max(p[ls].pe, p[ls].su + p[rs].pe);
            p[i].sr = max(p[rs].sr, p[ls].sr + p[rs].su);
            p[i].ma = max(p[ls].ma, max(p[rs].ma, p[ls].sr + p[rs].pe));
            p[i].su = p[rs].su + p[ls].su;
    
        }
    
        void build(int l, int r, int i)
        {
            p[i].pe = p[i].sr = p[i].su = p[i].ma = 0;
            if (l == r) return;
            int mid = (l + r) >> 1;
            build(l, mid, ls);
            build(mid + 1, r, rs);
        }
    
        void upd(int l, int r, int i, int x, LL w)
        {
            if (l == r) {
                p[i].su += w;
                p[i].ma = max(0ll, p[i].su);
                p[i].sr = max(0ll, p[i].su);
                p[i].pe = max(0ll, p[i].su);
                return;
            }
            int mid = (l + r) >> 1;
            if (mid < x)upd(mid + 1, r, rs, x, w);
            else upd(l, mid, ls, x, w);
            puu(i);
        }
    
        LL qy(int i, int l, int r, int ql, int qr)
        {
            return max(p[i].pe, max(p[i].sr, p[i].ma));
        }
    
    }seg;
    
    bool cmp(const node& a, const node& b) { if (a.y == b.y)return a.x < b.x; return a.y < b.y; }
    
    int main()
    {
        po[0].y = -0x3f3f3f3f;
        scanf("%d", &t);
        while (t--) {
            scanf("%d", &n);
            for (int i = 1; i <= n; i++) {
                scanf("%d%d%lld", &x[i], &y[i], &po[i].w);
                po[i].x = x[i];
                po[i].y = y[i];
            }
            sort(x + 1, x + n + 1);
            int nx = unique(x + 1, x + n + 1) - x - 1;
            sort(y + 1, y + n + 1);
            int ny = unique(y + 1, y + n + 1) - y - 1;
            sort(po + 1, po + 1 + n, cmp);
            for (int i = 1; i <= n; i++) {
                po[i].x = lower_bound(x + 1, x + nx + 1, po[i].x) - x;
                po[i].y = lower_bound(y + 1, y + ny + 1, po[i].y) - y;
            }
            LL ans = 0ll;
            for (int i = 1; i <= n; i++) {
                while (po[i].y == po[i - 1].y)i++;
                seg.build(1, nx, 1);
                for (int j = i; j <= n; j++) {
                    seg.upd(1, nx, 1, po[j].x, po[j].w);
                    while (j < n && po[j + 1].y == po[j].y) {
                        j++;
                        seg.upd(1, nx, 1, po[j].x, po[j].w);
                    }
                    ans = max(ans, seg.qy(1, 1, nx, 1, nx));
                }
            }
            cout << ans << endl;
        }
    
        return 0;
    }
    Snowy Smile

      怎么说。。最近感觉到需要暂停一下了,能量峰型还是好难转每日任务型啊┓( ´∀` )┏

  • 相关阅读:
    强化学习
    训练深度神经网络失败的罪魁祸首是退化
    wod2vec&fasttext&doc2vec#ida2vec
    leetcode动态规划之最长回文子串
    数据增强
    【认证与授权】Spring Security自定义页面
    【认证与授权】Spring Security的授权流程
    【认证与授权】Spring Security系列之认证流程解析
    【认证与授权】Spring Security系列之初体验
    【认证与授权】2、基于session的认证方式
  • 原文地址:https://www.cnblogs.com/non-/p/11346475.html
Copyright © 2011-2022 走看看