UVA 1400 1400,uva1400

來源:互聯網
上載者:User

UVA 1400 1400,uva1400
UVA 1400 - "Ray, Pass me the dishes!"

題目連結

題意:給定一個序列,每次詢問一個[L,R]區間,求出這個區間的最大連續子序列和

思路:線段樹,每個節點維護3個值,最大連續子序列,最大連續首碼序列,最大連續尾碼序列,那麼每次pushup的時候,根據這3個序列去拼湊得到新的一個結點即可

代碼:

#include <cstdio>#include <cstring>#include <algorithm>using namespace std;#define lson(x) ((x<<1) + 1)#define rson(x) ((x<<1) + 2)#define MP(a, b) make_pair(a, b)typedef long long ll;typedef pair<int, int> Point;const int N = 500005;int n, m;ll a[N], sum[N];struct Node {    int l, r;    int prex, sufx;    Point sub;} node[4 * N];ll get(Point x) {    return sum[x.second] - sum[x.first - 1];}bool Max(Point a, Point b) {    long long sa = get(a);    long long sb = get(b);    if (sa != sb) return sa > sb;    return a < b;}Point Maxsub(Node a, Node b) {    Point ans;    if (Max(a.sub, b.sub)) ans = a.sub;    else ans = b.sub;    if (Max(MP(a.sufx, b.prex), ans)) ans = MP(a.sufx, b.prex);    return ans;}int Maxpre(Node a, Node b) {    Point ans = MP(a.l, a.prex);    if (Max(MP(a.l, b.prex), ans)) ans = MP(a.l, b.prex);    return ans.second;}int Maxsuf(Node a, Node b) {    Point ans = MP(b.sufx, b.r);    if (Max(MP(a.sufx, b.r), ans)) ans = MP(a.sufx, b.r);    return ans.first;}Node pushup(Node a, Node b) {    Node ans;    ans.l = a.l; ans.r = b.r;    ans.sub = Maxsub(a, b);    ans.prex = Maxpre(a, b);    ans.sufx = Maxsuf(a, b);    return ans;}void build(int l, int r, int x) {    if (l == r) {node[x].l = l; node[x].r = r;node[x].prex = node[x].sufx = l;node[x].sub = MP(l, l);return ;    }    int mid = (l + r) / 2;    build(l, mid, lson(x));    build(mid + 1, r, rson(x));    node[x] = pushup(node[lson(x)], node[rson(x)]);}Node Query(int l, int r, int x) {    if (l <= node[x].l && r >= node[x].r)return node[x];    int mid = (node[x].l + node[x].r) / 2;    Node ans;    if (l <= mid && r > mid)ans = pushup(Query(l, r, lson(x)), Query(l, r, rson(x)));    else if (l <= mid) ans = Query(l, r, lson(x));    else if (r > mid) ans = Query(l, r, rson(x));    return ans;}int main() {    int cas = 0;    while (~scanf("%d%d", &n, &m)) {for (int i = 1; i <= n; i++) {    scanf("%lld", &a[i]);    sum[i] = sum[i - 1] + a[i];}build(1, n, 0);printf("Case %d:\n", ++cas);int a, b;while (m--) {    scanf("%d%d", &a, &b);    Node ans = Query(a, b, 0);    printf("%d %d\n", ans.sub.first, ans.sub.second);}    }    return 0;}



1400*1400像素以上的jpg圖片

用這幾張裡面選吧,絕對吸引眼球,而且可以適合廣泛話題作封面都說得過去

唯美但是以綠色植物為主的風景恐怕作封面平淡些,除非找到真的極品

豎向的圖,只要標題或作品名字跟眼睛聯絡起來,這圖都可以用,眼睛或觀察聯絡到各類事物都不難

方形圖

帶思想性的主題可以配封面

旅遊、故事類等都可以



 
1400/40 用簡便方法計算

1400/40=(1200+200)/40=1200/40+200/40=30+5=35
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.