求助玄学 RE

P4513 小白逛公园

ScottSuperb @ 2023-01-10 12:05:26

真调不出来了/oh

#include <bits/stdc++.h>

using namespace std;

#define BUF_SIZE 1048576
#define getchar() gc()
#define putchar(x) pc(x)
static char buf[BUF_SIZE], *p1 = buf, *p2 = buf, obuf[BUF_SIZE], *p3 = obuf;
inline void fls() { fwrite(obuf, p3 - obuf, 1, stdout), p3 = obuf; }
inline void ffls() { fls(), fflush(stdout); }
inline char gc() {
  return p1 == p2 &&
                 (p2 = (p1 = buf) + fread(buf, 1, BUF_SIZE, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
inline void pc(char x) {
  if (p3 - obuf >= BUF_SIZE) fls();
  *p3++ = x;
}

#define ll int
#define isi(n) (n >= '0' && n <= '9')
inline ll read() {
  ll x = 0;
  char ch = getchar(), sign = '+';
  while (!isi(ch)) sign = ch, ch = getchar();
  do x = x * 10 + (ch ^ 48), ch = getchar();
  while (isi(ch));
  return sign == '-' ? -x : x;
}
inline void write(ll x, char l = '\n') {
  if (x) {
    char n[20];
    int cnt = 0;
    if (x < 0) putchar('-'), x = -x;
    do n[cnt++] = x % 10 ^ 48, x /= 10;
    while (x);
    do putchar(n[--cnt]);
    while (cnt);
  } else
    putchar('0');
  putchar(l);
}

const int SIZE = 500000;
struct node {
  int l, r, sum, ls, rs, ms;
} t[SIZE << 2];
void merge(node& p, node& l, node& r) {
  p.sum = l.sum + r.sum, p.ls = max(l.ls, l.sum + r.ls),
  p.rs = max(r.rs, r.sum + l.rs), p.ms = max(max(l.ms, r.ms), l.rs + r.ls);
}
void build(int p, int l, int r) {
  t[p].l = l, t[p].r = r;
  if (l == r) {
    t[p].sum = t[p].ls = t[p].rs = t[p].ms = read();
    return;
  }
  int mid = (l + r) >> 1;
  build(p << 1, l, mid);
  build(p << 1 | 1, mid + 1, r);
  merge(t[p], t[p << 1], t[p << 1 | 1]);
}
void change(int p, int x, int v) {
  if (t[p].l == t[p].r) {
    t[p].sum = t[p].ls = t[p].rs = t[p].ms = v;
    return;
  }
  int mid = (t[p].l + t[p].r) >> 1;
  if (x <= mid)
    change(p << 1, x, v);
  else
    change(p << 1 | 1, x, v);
  merge(t[p], t[p << 1], t[p << 1 | 1]);
}
node query(int p, int l, int r) {
  if (t[p].l >= l && t[p].r <= r) return t[p];
  int mid = (t[p].l + t[p].r) >> 1;
  if (t[p].r <= mid)
    return query(p << 1, l, r);
  else if (t[p].l > mid)
    return query(p << 1 | 1, l, r);
  else {
    node a = query(p << 1, l, r), b = query(p << 1 | 1, l, r), w;
    merge(w, a, b);
    return w;
  }
}

int main() {
  int n = read(), m = read(), k, a, b;
  build(1, 1, n);
  while (m--) {
    k = read(), a = read(), b = read();
    if (k & 1)
      write(query(1, min(a, b), max(a, b)).ms);
    else
      change(1, a, b);
  }
  fls();
  return 0;
}

by ud2_ @ 2023-01-10 12:51:45

query 死递归。加了一些调试输出,用样例测试的结果是这样的:

query(p = 1, l = 2, r = 3), t[p] = { .l = 1, .r = 5, .sum = 9, .ls = 9, .rs = 9, .ms = 9 }
query(p = 2, l = 2, r = 3), t[p] = { .l = 1, .r = 3, .sum = 0, .ls = 3, .rs = 0, .ms = 3 }
query(p = 4, l = 2, r = 3), t[p] = { .l = 1, .r = 2, .sum = 3, .ls = 3, .rs = 3, .ms = 3 }
query(p = 8, l = 2, r = 3), t[p] = { .l = 1, .r = 1, .sum = 1, .ls = 1, .rs = 1, .ms = 1 }
query(p = 16, l = 2, r = 3), t[p] = { .l = 0, .r = 0, .sum = 0, .ls = 0, .rs = 0, .ms = 0 }
query(p = 32, l = 2, r = 3), t[p] = { .l = 0, .r = 0, .sum = 0, .ls = 0, .rs = 0, .ms = 0 }
query(p = 64, l = 2, r = 3), t[p] = { .l = 0, .r = 0, .sum = 0, .ls = 0, .rs = 0, .ms = 0 }
query(p = 128, l = 2, r = 3), t[p] = { .l = 0, .r = 0, .sum = 0, .ls = 0, .rs = 0, .ms = 0 }
query(p = 256, l = 2, r = 3), t[p] = { .l = 0, .r = 0, .sum = 0, .ls = 0, .rs = 0, .ms = 0 }
query(p = 512, l = 2, r = 3), t[p] = { .l = 0, .r = 0, .sum = 0, .ls = 0, .rs = 0, .ms = 0 }
query(p = 1024, l = 2, r = 3), t[p] = { .l = 0, .r = 0, .sum = 0, .ls = 0, .rs = 0, .ms = 0 }
query(p = 2048, l = 2, r = 3), t[p] = { .l = 0, .r = 0, .sum = 0, .ls = 0, .rs = 0, .ms = 0 }
query(p = 4096, l = 2, r = 3), t[p] = { .l = 0, .r = 0, .sum = 0, .ls = 0, .rs = 0, .ms = 0 }
query(p = 8192, l = 2, r = 3), t[p] = { .l = 0, .r = 0, .sum = 0, .ls = 0, .rs = 0, .ms = 0 }
query(p = 16384, l = 2, r = 3), t[p] = { .l = 0, .r = 0, .sum = 0, .ls = 0, .rs = 0, .ms = 0 }
query(p = 32768, l = 2, r = 3), t[p] = { .l = 0, .r = 0, .sum = 0, .ls = 0, .rs = 0, .ms = 0 }
query(p = 65536, l = 2, r = 3), t[p] = { .l = 0, .r = 0, .sum = 0, .ls = 0, .rs = 0, .ms = 0 }
query(p = 131072, l = 2, r = 3), t[p] = { .l = 0, .r = 0, .sum = 0, .ls = 0, .rs = 0, .ms = 0 }
query(p = 262144, l = 2, r = 3), t[p] = { .l = 0, .r = 0, .sum = 0, .ls = 0, .rs = 0, .ms = 0 }
query(p = 524288, l = 2, r = 3), t[p] = { .l = 0, .r = 0, .sum = 0, .ls = 0, .rs = 0, .ms = 0 }
query(p = 1048576, l = 2, r = 3), t[p] = { .l = 0, .r = 0, .sum = 0, .ls = 0, .rs = 0, .ms = 0 }
query(p = 2097152, l = 2, r = 3), main.cpp:79:93: runtime error: index 2097152 out of bounds for type 'struct node[2000000]'

by Micnation_AFO @ 2023-01-10 13:11:25

@ScottSuperb query 里面 if (t[p].r <= mid) 错了,以及 else if 里面的条件也错了,不是 t[p].r


by ScottSuperb @ 2023-01-10 13:36:39

woc 居然手残打上了 t[p].


|