Submission #781334

# Submission time Handle Problem Language Result Execution time Memory
781334 2023-07-13T03:43:59 Z michy Monkey and Apple-trees (IZhO12_apple) C++14
0 / 100
1 ms 212 KB
#include <bits/stdc++.h>
using namespace std;

struct Node {
  int tl, tr;
  int sum = 0, lazy = 0;
  Node *left = nullptr, *right = nullptr;
  Node(int l, int r) : tl(l), tr(r) {}
};
  
void push(Node *v) {
  if (v->tl == v->tr) return;
  int tm = (v->tl + v->tr) / 2;
  if (!v->left) v->left = new Node(v->tl, tm);
  if (!v->right) v->right = new Node(tm+1, v->tr);
  if (v->lazy == 1) {
    v->left->sum = (tm - v->tl + 1);
    v->right->sum = (v->tr - tm);
    v->lazy = 0;
  }
}

int query(Node *v, int l, int r) {
  push(v);
  if (l > v->tr || r < v->tl)
    return 0;
  if (l <= v->tl && v->tr <= r)
    return v->sum;
  return (v->left ? query(v->left, l, r) : 0) + (v->right ? query(v->right, l, r) : 0);
}

void update(Node *v, int l, int r, int val) {
  push(v);
  if (l > v->tr || r < v->tl)
    return;
  if (l <= v->tl && v->tr <= r) {
    v->lazy = 1;
    v->sum = (v->tr - v->tl + 1);
    return;
  }
  update(v->left, l, r, val);
  update(v->right, l, r, val);
  v->sum = (v->left ? v->left->sum : 0) + (v->right ? v->right->sum : 0);
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int q;
  cin >> q;
  Node *root = new Node(1, 1e9);
  int ans = 0;
  while (q--) {
    int op, l, r;
    cin >> op >> l >> r;
    l += ans; r += ans;
    if (op == 1) {
      ans = query(root, l, r);
      cout << ans << endl;
    } else {
      update(root, l, r, 1);
    }
  }
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -