QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#110875#5069. VacationLitDarknessWA 501ms105328kbC++146.4kb2023-06-04 14:47:252023-06-04 14:47:28

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-04 14:47:28]
  • 评测
  • 测评结果:WA
  • 用时:501ms
  • 内存:105328kb
  • [2023-06-04 14:47:25]
  • 提交

answer

#include <bits/stdc++.h>
#define For(i, a, b) for (int i = a; i <= b; ++i)
#define Rep(i, a, b) for (int i = a; i >= b; --i)
using namespace std;
namespace io {
template<typename T>inline void read(T &x) {
  char ch, f = 0; x = 0;
  while (!isdigit(ch = getchar())) f |= ch == '-';
  while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
  x = f? -x: x;
}
char ch[40];
template<typename T>inline void write(T x) {
  (x < 0) && (putchar('-'), x = -x);
  x || putchar('0');
  int i = 0;
  while (x) ch[i++] = x % 10 ^ 48, x /= 10;
  while (i) putchar(ch[--i]);
}
}
#define rd io::read
#define wt io::write
using i64 = long long;
const int maxN = 2e6 + 5;
int a[maxN], c, n, blo, m;
struct Node1 {
  i64 sum, pre, suf, ans;
  Node1 operator+ (const Node1 &a) const {
    return {sum + a.sum, max(pre, sum + a.pre), max(a.suf, a.sum + suf), max({ans, a.ans, suf + a.pre})};
  }
};
struct Seg1 {
  vector<Node1> T;
  int len, beg;
  inline void init(int l) { len = l; T.resize(l << 2|1); }
  void build(int k, int l, int r) {
    if (l == r) {
      T[k].sum = a[beg + l - 1];
      T[k].ans = T[k].suf = T[k].pre = max(0, a[beg + l - 1]);      
      return;   
    }
    int mid = l + r >> 1;
    build(k << 1, l, mid);
    build(k << 1|1, mid + 1, r);
    T[k] = T[k << 1] + T[k << 1|1];
  }
  void update(int x, int v, int k, int l, int r) {
    if (l == r) {
      T[k].sum = v;
      T[k].ans = T[k].suf = T[k].pre = max(0, v);
      return;
    }
    int mid = l + r >> 1;
    if (x <= mid) update(x, v, k << 1, l, mid);
    else update(x, v, k << 1|1, mid + 1, r);
    T[k] = T[k << 1] + T[k << 1|1];
  }
  Node1 query(int x, int y, int k, int l, int r) {
    if (x <= l && r <= y) return T[k];
    int mid = l + r >> 1;
    if (x <= mid) {
      if (y > mid) return query(x, y, k << 1, l, mid) + query(x, y, k << 1|1, mid + 1, r);
      return query(x, y, k << 1, l, mid);
    }
    return query(x, y, k << 1|1, mid + 1, r);
  }
};
int bel[maxN], R[maxN];
struct Node2 {
  i64 sa, sb, pa, pb, ans;
  Node2 operator+ (const Node2 &a) const {
    return {sa + a.sa, sb + a.sb, max(pa, sa + a.pa), max(pb, sb + a.pb), max({ans + a.sb, a.ans + sa, pa + a.pb})};
  }
};
struct Seg2 {
  vector<Node2> T;
  int len, beg;
  inline void init(int l) { len = l; T.resize(l << 2|1); }
  void build(int k, int l, int r) {
    if (l == r) {
      T[k].sa = a[min(beg + l - 1 + c, n + 1)];
      T[k].sb = a[beg + l - 1];
      T[k].pa = max(T[k].sa, 0ll);
      T[k].pb = max(T[k].sb, 0ll);
      T[k].ans = max(T[k].pa, T[k].pb);
      return;
    }
    int mid = l + r >> 1;
    build(k << 1, l, mid);
    build(k << 1|1, mid + 1, r);
    T[k] = T[k << 1] + T[k << 1|1];
  }
  i64 rev;
  Node2 query(int x, int y, int k, int l, int r) {
    if (x <= l && r <= y) return T[k];
    int mid = l + r >> 1;
    if (x <= mid) {
      if (y > mid) return query(x, y, k << 1, l, mid) + query(x, y, k << 1|1, mid + 1, r);
      rev += T[k << 1|1].sb;
      return query(x, y, k << 1, l, mid);
    }
    rev += T[k << 1].sa;
    return query(x, y, k << 1|1, mid + 1, r);
  }
  i64 Squery(int x, int y) {
    rev = 0; i64 v = query(x, y, 1, 1, len).ans;
    return v + rev;
  }
  void update(int x, int op, int v, int k, int l, int r) {
    if (l == r) {
      if (op == 0) {
        T[k].sa = v; T[k].pa = max(T[k].sa, 0ll);
      } else {
        T[k].sb = v; T[k].pb = max(T[k].sb, 0ll);
      }
      T[k].ans = max(T[k].pa, T[k].pb);
      return;
    }
    int mid = l + r >> 1;
    if (x <= mid) update(x, op, v, k << 1, l, mid);
    else update(x, op, v, k << 1|1, mid + 1, r);
    T[k] = T[k << 1] + T[k << 1|1];
  }
};
vector<Seg1> T1;
vector<Seg2> T2;
vector<i64> mx;
void build(int k = 1, int l = 1, int r = blo) {
  if (l == r) {
    if (l < blo) {
      T1[l].init(c); T2[l].init(c);
      T1[l].beg = T2[l].beg = (l - 1) * c + 1;
      T2[l].build(1, 1, c);
    } else {
      T1[l].init(n - (l - 1) * c);
      T1[l].beg = (l - 1) * c + 1;
    }
    T1[l].build(1, 1, T1[l].len);
    mx[k] = T1[l].T[1].ans;
    return;
  }
  int mid = l + r >> 1;
  build(k << 1, l, mid);
  build(k << 1|1, mid + 1, r);
  mx[k] = max(mx[k << 1], mx[k << 1|1]);
}
void update(int x, int v, int k = 1, int l = 1, int r = blo) {
  if (l == r) {
    int rr = x - R[l - 1];
    T1[l].update(rr, v, 1, 1, T1[l].len);
    if (l > 1) T2[l - 1].update(rr, 0, v, 1, 1, T2[l - 1].len);
    if (l < bel[n]) T2[l].update(rr, 1, v, 1, 1, T2[l].len);
    mx[k] = T1[l].T[1].ans;
    return;
  }
  int mid = l + r >> 1;
  if (bel[x] <= mid) update(x, v, k << 1, l, mid);
  else update(x, v, k << 1|1, mid + 1, r);
  mx[k] = max(mx[k << 1], mx[k << 1|1]);
}
i64 query(int x, int y, int k = 1, int l = 1, int r = blo) {
  if (x <= l && r <= y) return mx[k];
  int mid = l + r >> 1; i64 ans = 0;
  if (x <= mid) ans = max(ans, query(x, y, k << 1, l, mid));
  if (y > mid) ans = max(ans, query(x, y, k << 1|1, mid + 1, r));
  return ans;
}
inline int gv(int x) { return x - R[bel[x] - 1]; }
i64 ask(int x, int y) {
  if (bel[x] == bel[y]) 
    return T1[bel[x]].query(gv(x), gv(y), 1, 1, R[bel[x]] - R[bel[x] - 1]).ans;
  if (y - x + 1 <= c) {
    Node1 p = T1[bel[x]].query(gv(x), T1[bel[x]].len, 1, 1, T1[bel[x]].len) + T1[bel[y]].query(1, gv(y), 1, 1, T1[bel[y]].len);
    return p.ans;
  }
  if (bel[y] == bel[x] + 1) {
    Node1 p;
    if (x > R[bel[x] - 1] + 1) p = T1[bel[x]].query(gv(x), T1[bel[x]].len, 1, 1, T1[bel[x]].len) + T1[bel[x + c - 1]].query(1, gv(x + c - 1), 1, 1, T1[bel[y]].len);
    else p = T1[bel[x]].T[1];
    i64 ans = max(p.ans, T1[bel[y]].query(1, gv(y), 1, 1, T1[bel[y]].len).ans);
    return max(ans, T2[bel[x]].Squery(gv(x + c), gv(y)));
  }
  i64 ans = max({query(bel[x] + 1, bel[y] - 1), T1[bel[x]].query(gv(x), T1[bel[x]].len, 1, 1, T1[bel[x]].len).ans, T1[bel[y]].query(1, gv(y), 1, 1, T1[bel[y]].len).ans});
  ans = max({ans, T2[bel[x]].Squery(gv(x), c), T2[bel[y] - 1].Squery(1, gv(y))});
  return ans;
}
int main() {
  rd(n); rd(m); rd(c);
  blo = (n - 1) / c + 1;
  For (i, 1, n) {
    rd(a[i]);
    bel[i] = (i - 1) / c + 1;
  }
  For (i, 1, blo) 
    R[i] = min(R[i - 1] + c, n);
  T1.resize(blo + 1); T2.resize(blo + 1); mx.resize(blo << 2|1);
  build(); int op, x, y; 
  For (i, 1, m) {
    rd(op); rd(x); rd(y);
    if (op == 1) {
      update(x, y);
    } else {
      wt(ask(x, y)); putchar('\n');
    }
  }
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 7480kb

input:

5 6 3
0 -5 -3 8 -3
2 3 5
1 2 5
2 1 5
1 4 -3
2 3 5
2 1 5

output:

8
10
0
5

result:

ok 4 number(s): "8 10 0 5"

Test #2:

score: 0
Accepted
time: 501ms
memory: 105328kb

input:

200000 500000 1
387060158 961744470 37167782 737122872 -532977662 1604246 -30977399 871848791 444997246 454204578 -813187501 -660394286 448014171 -835115276 -631880452 887715308 258530352 805589560 -414653327 -156732249 -335096199 -80266237 367896009 738406627 -903652056 446120866 415658444 -1347916...

output:

999902477
999981999
999343404
999847372
999957587
998160312
999981999
999981999
999981999
999980061
999981999
999981999
999981999
999876122
999981999
999996602
999981999
999981999
999981999
999723649
999981999
999957587
999896087
999981999
999981999
999981999
999981999
999981999
999957587
999981999
...

result:

ok 250051 numbers

Test #3:

score: -100
Wrong Answer
time: 390ms
memory: 75332kb

input:

200000 500000 5
802774074 383481934 -295470374 285359286 751657057 197444479 626916547 -828168464 288373833 -493446966 -208422769 956745384 919286225 959643271 -176531848 -380256966 357111771 -50890039 -637284768 -337010918 259019684 752475630 -259898780 98620995 -704832505 -532710796 -971600790 -84...

output:

4544135313
4544135313
4322308420
2770770271
4544135313
4544135313
4322308420
4386413596
4386413596
3731128239
4322308420
4100474957
4266013548
4544135313
4386413596
4094787940
4386413596
4386413596
4386413596
4322308420
4266013548
4386413596
4322308420
4544135313
4386413596
4322308420
4322308420
385...

result:

wrong answer 3rd numbers differ - expected: '4443416295', found: '4322308420'