結果
| 問題 | No.776 A Simple RMQ Problem |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-12-23 00:31:23 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,112 bytes |
| 記録 | |
| コンパイル時間 | 167 ms |
| コンパイル使用メモリ | 25,216 KB |
| 実行使用メモリ | 9,168 KB |
| 最終ジャッジ日時 | 2024-09-25 10:20:49 |
| 合計ジャッジ時間 | 4,425 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 WA * 1 |
| other | WA * 26 |
コンパイルメッセージ
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);
| ~~~~~^~~~~~~~~~~~~~~~~
ソースコード
#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;
}