Submission #1043690

# Submission time Handle Problem Language Result Execution time Memory
1043690 2024-08-04T13:53:51 Z juicy Bitaro, who Leaps through Time (JOI19_timeleap) C++17
100 / 100
326 ms 58196 KB
#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif

const int N = 3e5 + 5;

struct Node {
  int s, t; long long c;

  Node(int s = 0LL, int t = 0LL, long long c = -1): s(s), t(t), c(c) {};

  friend Node operator + (const Node &lt, const Node &rt) {
    if (~lt.c && ~rt.c) {
      return {lt.s, rt.t, lt.c + rt.c + max(0, lt.t - rt.s)};
    }
    if (~lt.c) {
      return {lt.s, min(rt.t, max(lt.t, rt.s)), lt.c + max(0, lt.t - rt.t)};
    }
    if (~rt.c) {
      return {min(lt.t, max(lt.s, rt.s)), rt.t, max(0, lt.s - rt.s) + rt.c};
    }
    if (lt.t < rt.s) {
      return {lt.t, rt.s, 0};
    }
    if (lt.s > rt.t) {
      return {lt.s, rt.t, lt.s - rt.t};
    }
    return {max(lt.s, rt.s), min(lt.t, rt.t), -1};
  }
};

int n, q;

struct Segtree {
  Node s[4 * N];
  
  void upd(int i, int u, int v, int id = 1, int l = 1, int r = n - 1) {
    if (l == r) {
      s[id] = {u - i, v - i - 1};
      return;
    }
    int md = (l + r) / 2;
    if (i <= md) {
      upd(i, u, v, id * 2, l, md);
    } else {
      upd(i, u, v, id * 2 + 1, md + 1, r);
    }
    s[id] = s[id * 2] + s[id * 2 + 1];
  }

  Node qry(int u, int v, int id = 1, int l = 1, int r = n - 1) {
    if (u <= l && r <= v) {
      return s[id];
    }
    int md = (l + r) / 2;
    if (v <= md) {
      return qry(u, v, id * 2, l, md);
    }
    if (md < u) {
      return qry(u, v, id * 2 + 1, md + 1, r);
    }
    return qry(u, v, id * 2, l, md) + qry(u, v, id * 2 + 1, md + 1, r);
  }

  long long get(int l, int r, int s, int e) {
    if (l == r) {
      return max(0, s - e);
    }
    return max(0LL, (Node(s - l, s - l, -1) + qry(l, r - 1) + Node(e - r, e - r, -1)).c);
  }
} A, B;

int main() {
  ios::sync_with_stdio(false); cin.tie(nullptr);

  cin >> n >> q;
  for (int i = 1; i < n; ++i) {
    int l, r; cin >> l >> r;
    A.upd(i, l, r);
    B.upd(n - i, l, r);
  }
  while (q--) {
    int type; cin >> type;
    if (type == 1) {
      int p, s, e; cin >> p >> s >> e;
      A.upd(p, s, e);
      B.upd(n - p, s, e);
    } else {
      int s, e, l, r; cin >> l >> s >> r >> e;
      if (l <= r) {
        cout << A.get(l, r, s, e) << "\n";
      } else {
        cout << B.get(n - l + 1, n - r + 1, s, e) << "\n";
      }
    }
  }
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 37976 KB Output is correct
2 Correct 4 ms 37980 KB Output is correct
3 Correct 4 ms 37980 KB Output is correct
4 Correct 4 ms 37980 KB Output is correct
5 Correct 4 ms 37980 KB Output is correct
6 Correct 4 ms 37980 KB Output is correct
7 Correct 4 ms 37980 KB Output is correct
8 Correct 5 ms 37980 KB Output is correct
9 Correct 5 ms 37976 KB Output is correct
10 Correct 4 ms 37976 KB Output is correct
11 Correct 5 ms 37976 KB Output is correct
12 Correct 6 ms 38092 KB Output is correct
13 Correct 5 ms 37976 KB Output is correct
14 Correct 5 ms 38080 KB Output is correct
15 Correct 8 ms 37980 KB Output is correct
16 Correct 5 ms 37976 KB Output is correct
17 Correct 6 ms 37976 KB Output is correct
18 Correct 6 ms 37980 KB Output is correct
19 Correct 5 ms 37976 KB Output is correct
20 Correct 5 ms 37976 KB Output is correct
21 Correct 5 ms 37980 KB Output is correct
22 Correct 5 ms 37980 KB Output is correct
23 Correct 5 ms 38076 KB Output is correct
24 Correct 6 ms 37980 KB Output is correct
25 Correct 6 ms 37976 KB Output is correct
26 Correct 6 ms 37980 KB Output is correct
27 Correct 5 ms 37980 KB Output is correct
28 Correct 6 ms 37980 KB Output is correct
29 Correct 5 ms 38044 KB Output is correct
30 Correct 5 ms 38084 KB Output is correct
31 Correct 6 ms 38232 KB Output is correct
32 Correct 6 ms 37980 KB Output is correct
33 Correct 7 ms 37980 KB Output is correct
34 Correct 5 ms 37980 KB Output is correct
35 Correct 5 ms 37980 KB Output is correct
36 Correct 6 ms 37976 KB Output is correct
37 Correct 5 ms 38076 KB Output is correct
38 Correct 6 ms 37980 KB Output is correct
39 Correct 5 ms 37980 KB Output is correct
40 Correct 6 ms 37980 KB Output is correct
41 Correct 5 ms 37980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 326 ms 42104 KB Output is correct
2 Correct 287 ms 57464 KB Output is correct
3 Correct 274 ms 57684 KB Output is correct
4 Correct 289 ms 57172 KB Output is correct
5 Correct 297 ms 57684 KB Output is correct
6 Correct 288 ms 57688 KB Output is correct
7 Correct 286 ms 57684 KB Output is correct
8 Correct 304 ms 58196 KB Output is correct
9 Correct 305 ms 57576 KB Output is correct
10 Correct 284 ms 57684 KB Output is correct
11 Correct 283 ms 57788 KB Output is correct
12 Correct 289 ms 58196 KB Output is correct
13 Correct 301 ms 58108 KB Output is correct
14 Correct 4 ms 37980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 37976 KB Output is correct
2 Correct 4 ms 37980 KB Output is correct
3 Correct 4 ms 37980 KB Output is correct
4 Correct 4 ms 37980 KB Output is correct
5 Correct 4 ms 37980 KB Output is correct
6 Correct 4 ms 37980 KB Output is correct
7 Correct 4 ms 37980 KB Output is correct
8 Correct 5 ms 37980 KB Output is correct
9 Correct 5 ms 37976 KB Output is correct
10 Correct 4 ms 37976 KB Output is correct
11 Correct 5 ms 37976 KB Output is correct
12 Correct 6 ms 38092 KB Output is correct
13 Correct 5 ms 37976 KB Output is correct
14 Correct 5 ms 38080 KB Output is correct
15 Correct 8 ms 37980 KB Output is correct
16 Correct 5 ms 37976 KB Output is correct
17 Correct 6 ms 37976 KB Output is correct
18 Correct 6 ms 37980 KB Output is correct
19 Correct 5 ms 37976 KB Output is correct
20 Correct 5 ms 37976 KB Output is correct
21 Correct 5 ms 37980 KB Output is correct
22 Correct 5 ms 37980 KB Output is correct
23 Correct 5 ms 38076 KB Output is correct
24 Correct 6 ms 37980 KB Output is correct
25 Correct 6 ms 37976 KB Output is correct
26 Correct 6 ms 37980 KB Output is correct
27 Correct 5 ms 37980 KB Output is correct
28 Correct 6 ms 37980 KB Output is correct
29 Correct 5 ms 38044 KB Output is correct
30 Correct 5 ms 38084 KB Output is correct
31 Correct 6 ms 38232 KB Output is correct
32 Correct 6 ms 37980 KB Output is correct
33 Correct 7 ms 37980 KB Output is correct
34 Correct 5 ms 37980 KB Output is correct
35 Correct 5 ms 37980 KB Output is correct
36 Correct 6 ms 37976 KB Output is correct
37 Correct 5 ms 38076 KB Output is correct
38 Correct 6 ms 37980 KB Output is correct
39 Correct 5 ms 37980 KB Output is correct
40 Correct 6 ms 37980 KB Output is correct
41 Correct 5 ms 37980 KB Output is correct
42 Correct 326 ms 42104 KB Output is correct
43 Correct 287 ms 57464 KB Output is correct
44 Correct 274 ms 57684 KB Output is correct
45 Correct 289 ms 57172 KB Output is correct
46 Correct 297 ms 57684 KB Output is correct
47 Correct 288 ms 57688 KB Output is correct
48 Correct 286 ms 57684 KB Output is correct
49 Correct 304 ms 58196 KB Output is correct
50 Correct 305 ms 57576 KB Output is correct
51 Correct 284 ms 57684 KB Output is correct
52 Correct 283 ms 57788 KB Output is correct
53 Correct 289 ms 58196 KB Output is correct
54 Correct 301 ms 58108 KB Output is correct
55 Correct 4 ms 37980 KB Output is correct
56 Correct 286 ms 54508 KB Output is correct
57 Correct 272 ms 54104 KB Output is correct
58 Correct 266 ms 54612 KB Output is correct
59 Correct 298 ms 54680 KB Output is correct
60 Correct 272 ms 54208 KB Output is correct
61 Correct 297 ms 54896 KB Output is correct
62 Correct 286 ms 54868 KB Output is correct
63 Correct 298 ms 54768 KB Output is correct
64 Correct 287 ms 54868 KB Output is correct
65 Correct 272 ms 54508 KB Output is correct
66 Correct 295 ms 54616 KB Output is correct
67 Correct 282 ms 54896 KB Output is correct
68 Correct 291 ms 54100 KB Output is correct
69 Correct 302 ms 54868 KB Output is correct
70 Correct 270 ms 54400 KB Output is correct
71 Correct 276 ms 53624 KB Output is correct
72 Correct 287 ms 53744 KB Output is correct
73 Correct 289 ms 54408 KB Output is correct
74 Correct 324 ms 54420 KB Output is correct
75 Correct 307 ms 54640 KB Output is correct
76 Correct 303 ms 55036 KB Output is correct
77 Correct 5 ms 37980 KB Output is correct