結果

問題 No.776 A Simple RMQ Problem
ユーザー pekempeypekempey
提出日時 2018-12-23 00:31:23
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,112 bytes
コンパイル時間 1,010 ms
コンパイル使用メモリ 24,936 KB
実行使用メモリ 8,784 KB
最終ジャッジ日時 2023-10-26 02:16:57
合計ジャッジ時間 4,861 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,796 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:64:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   64 |     scanf("%d %d", &n, &q);
      |     ~~~~~^~~~~~~~~~~~~~~~~
main.cpp:67:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   67 |         scanf("%d", &a);
      |         ~~~~~^~~~~~~~~~
main.cpp:72:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   72 |         scanf("%s", s);
      |         ~~~~~^~~~~~~~~
main.cpp:75:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   75 |             scanf("%d %d %d %d", &a, &b, &c, &d);
      |             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:91:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   91 |             scanf("%d %d", &k, &v);
      |             ~~~~~^~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>

#define N 131072

int min(int x, int y) {
    return x < y ? x : y;
}

int max(int x, int y) {
    return x > y ? x : y;
}

struct F {
    long long ans;
    long long sum;
    long long rmax;
    long long lmax;
} dat[N * 2];

struct F merge(F a, F b) {
    struct F res;
    res.sum = a.sum + b.sum;
    res.lmax = max(a.lmax, a.sum + b.lmax);
    res.rmax = max(b.rmax, b.sum + a.rmax);
    res.ans = max(max(a.ans, b.ans), a.rmax + b.lmax);
    return res;
}

void update(int k, int v) {
    k += N;
    dat[k].sum = v;
    dat[k].lmax = v;
    dat[k].rmax = v;
    dat[k].ans = v;
    while (k > 1) {
        k >>= 1;
        dat[k] = merge(dat[k * 2], dat[k * 2 + 1]);
    }
}

struct F query(int l, int r) {
    l += N;
    r += N;
    struct F ansl, ansr;
    ansl.sum = 0;
    ansl.lmax = -2e18;
    ansl.rmax = -2e18;
    ansl.ans = -2e18;
    ansr.sum = 0;
    ansr.lmax = -2e18;
    ansr.rmax = -2e18;
    ansr.ans = -2e18;
    while (l < r) {
        if (l & 1) ansl = merge(ansl, dat[l++]);
        if (r & 1) ansr = merge(dat[--r], ansr);
        l >>= 1;
        r >>= 1;
    }
    return merge(ansl, ansr);
}

int main(void) {
    int n, q;
    scanf("%d %d", &n, &q);
    for (int i = 0; i < n; i++) {
        int a;
        scanf("%d", &a);
        update(i, a);
    }
    while (q--) {
        char s[4];
        scanf("%s", s);
        if (s[0] == 'm') {
            int a, b, c, d;
            scanf("%d %d %d %d", &a, &b, &c, &d);
            a--;
            c--;
            int l = max(a, c);
            int r = min(b, d);
            long long ans = -2e18;
            if (l < r) {
                ans = max(ans, query(a, l).rmax + query(l, d).lmax);
                ans = max(ans, query(a, r).rmax + query(r, d).lmax);
                ans = max(ans, query(l, r).ans);
            } else {
                ans = max(ans, query(a, b).rmax + query(c, d).lmax + query(b, c).sum);
            }
            printf("%lld\n", ans);
        } else {
            int k, v;
            scanf("%d %d", &k, &v);
            update(k - 1, v);
        }
    }
    return 0;
}

0