Submission #1092024

# Submission time Handle Problem Language Result Execution time Memory
1092024 2024-09-23T00:54:15 Z juicy Monkey and Apple-trees (IZhO12_apple) C++17
100 / 100
29 ms 860 KB
#include <bits/stdc++.h>

using namespace std;

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

const int M = 1e9, N = 6000005;

int n = 1;
int s[N], L[N], R[N];

void upd(int u, int v, int id = 1, int l = 1, int r = M) {
  if (s[id] == r - l + 1) {
    return;
  }
  if (u <= l && r <= v) {
    s[id] = r - l + 1;
    return;
  } 
  int m = (l + r) / 2;
  if (u <= m) {
    if (!L[id]) {
      L[id] = ++n;
    }
    upd(u, v, L[id], l, m);
  }
  if (m < v) {
    if (!R[id]) {
      R[id] = ++n;
    }
    upd(u, v, R[id], m + 1, r);
  }
  s[id] = s[L[id]] + s[R[id]];
}

int qry(int u, int v, int id = 1, int l = 1, int r = M) {
  if (s[id] == r - l + 1) {
    return min(v, r) - max(l, u) + 1;
  } 
  if (u <= l && r <= v) {
    return s[id];
  }
  int m = (l + r) / 2;
  int res = 0;
  if (u <= m) {
    res += L[id] ? qry(u, v, L[id], l, m) : 0;
  }
  if (m < v) {
    res += R[id] ? qry(u, v, R[id], m + 1, r) : 0;
  }
  return res;
}

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

  int m; cin >> m;
  int c = 0;
  while (m--) {
    int d, x, y; cin >> d >> x >> y; 
    x += c, y += c;
    if (d == 1) {
      cout << (c = qry(x, y)) << "\n";
    } else {
      upd(x, y);
    }
  }
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 5 ms 348 KB Output is correct
5 Correct 3 ms 348 KB Output is correct
6 Correct 3 ms 480 KB Output is correct
7 Correct 3 ms 348 KB Output is correct
8 Correct 13 ms 604 KB Output is correct
9 Correct 24 ms 784 KB Output is correct
10 Correct 24 ms 604 KB Output is correct
11 Correct 23 ms 812 KB Output is correct
12 Correct 23 ms 848 KB Output is correct
13 Correct 29 ms 852 KB Output is correct
14 Correct 29 ms 784 KB Output is correct
15 Correct 23 ms 860 KB Output is correct
16 Correct 24 ms 860 KB Output is correct
17 Correct 20 ms 860 KB Output is correct
18 Correct 24 ms 860 KB Output is correct
19 Correct 23 ms 856 KB Output is correct
20 Correct 22 ms 860 KB Output is correct