日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

2019杭电多校 Snowy Smile hdu6638 (线段树最大子段和)

發布時間:2023/12/20 编程问答 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 2019杭电多校 Snowy Smile hdu6638 (线段树最大子段和) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題意:散落一些點,有正負價值,框一個矩形,使得矩形中的價值總和最大

題解:先把y離散化,之后x排序后依次插入點,枚舉每一種不同的x坐標作為上邊界,枚舉下邊界,線段樹更新最大子段和

#include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<algorithm> #include<cmath> #include<queue> #include<list> #include<math.h> #include<vector> #include<stack> #include<string> #include<stdio.h>using namespace std; typedef long long LL; const int MAXN = 2e3 + 10;const int maxn=5e4 + 10;struct T{LL x,y,w;T(){}T(LL x,LL y,LL w) : x(x),y(y),w(w){} }a[MAXN];struct Segtree{int l,r;LL lx,rx,mx,sum; }st[MAXN << 2];bool cmp(T a,T b) {return a.x < b.x; } LL b[MAXN];void pushup(int o) {st[o].sum = st[o << 1].sum + st[o << 1 | 1].sum;st[o].lx = max(st[o << 1].lx,st[o << 1].sum + st[o << 1 | 1].lx);st[o].rx = max(st[o << 1 | 1].rx,st[o << 1 | 1].sum + st[o << 1].rx);st[o].mx = max(max(st[o << 1].mx,st[o << 1 | 1].mx),st[o << 1].rx + st[o << 1 | 1].lx); } void build(int o,int l,int r) {st[o].l = l; st[o].r = r;st[o].sum = st[o].mx = st[o].lx = st[o].rx = 0;if(l == r){return;}int m = (l + r) >> 1;build(o << 1, l, m);build(o << 1 | 1, m + 1, r); } void insert(int o,int x,int w) {if(st[o].l == st[o].r){st[o].sum = st[o].lx = st[o].rx = st[o].mx = st[o].mx + w;return;}int m = (st[o].l + st[o].r) >> 1;if(x <= m) insert(o << 1,x,w);else insert(o << 1 | 1,x,w);pushup(o); } int main() {int t;scanf("%d",&t);while(t--){int n;scanf("%d",&n);for(int i = 1; i <= n; i++){LL x,y,w;scanf("%lld %lld %lld",&x,&y,&w);a[i] = T(x,y,w);b[i] = y;}sort(b + 1,b + n + 1);int k = unique(b + 1,b + n + 1) - b - 1;for(int i = 1; i <= n; i++){int y = lower_bound(b + 1,b + k + 1,a[i].y) - b;a[i].y = y;}sort(a + 1,a + n + 1,cmp);LL ans = 0;for(int i = 1; i <= n; i++){if(i != 1 && a[i].x == a[i - 1].x)continue;build(1,1,k);for(int j = i; j <= n; j++){if(j != i && a[j].x != a[j - 1].x)ans = max(ans,st[1].mx);insert(1,a[j].y,a[j].w);}ans = max(ans,st[1].mx);}cout << ans << endl;} }

?

轉載于:https://www.cnblogs.com/smallhester/p/11319701.html

總結

以上是生活随笔為你收集整理的2019杭电多校 Snowy Smile hdu6638 (线段树最大子段和)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。