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

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

  • 相关阅读:
    摄影/秋日花展(二)
    cordova android
    Java Web Services (2)
    7、索引
    洛谷——P1164 小A点菜
    洛谷——P1616 疯狂的采药
    洛谷——P1910 L国的战斗之间谍
    洛谷——P1095 守望者的逃离
    codevs——T1169 传纸条
    计算机硬件历史
  • 原文地址:https://www.cnblogs.com/non-/p/11346475.html
Copyright © 2011-2022 走看看