답안 #680408

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
680408 2023-01-10T17:48:38 Z MattTheNub 원숭이와 사과 나무 (IZhO12_apple) C++17
0 / 100
1 ms 212 KB
#include <bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

template <class T> using v = vector<T>;
using ll = long long;
using dd = long double;
using int2 = pair<int, int>;
using ll2 = pair<ll, ll>;
using dd2 = pair<dd, dd>;

#define f first
#define s second
#define all(x) begin(x), end(x)
#ifdef DEV_MODE
#define dbg(x) cerr << "[" << __LINE__ << "] " << #x << " = " << (x) << '\n';
#define dbgp(x)                                                                \
  cerr << "[" << __LINE__ << "] " << #x << " = {" << (x).f << ", " << (x).s    \
       << "}" << '\n';
#else
#define dbg(x)
#define dbgp(x)
#endif

template <class T1, class T2>
istream &operator>>(istream &in, pair<T1, T2> &p) {
  in >> p.first >> p.second;
  return in;
}
template <class T> istream &operator>>(istream &in, v<T> &v) {
  for (auto &x : v)
    in >> x;
  return in;
}

// MULTITEST TOGGLE
const bool MULTITEST = false;
/******************************************************************************/
struct Node {
  Node(ll l, ll r) : l(l), r(r) {}
  ~Node() {
    delete left;
    delete right;
  }

  ll val = 0, set = 0;
  ll l, r;
  Node *left = nullptr, *right = nullptr;

  void push() {
    ll mid = (l + r) / 2;
    if (left == nullptr) {
      left = new Node(l, mid);
    }
    if (right == nullptr) {
      right = new Node(mid + 1, r);
    }

    if (set != 0) {
      left->set = 1;
      right->set = 1;
      val = r - l + 1;
      set = 0;
    }
  }
  void pull() { val = left->val + right->val; }

  ll qry(int a, int b) {
    if (a > r || b < l)
      return 0;
    if (a <= l && r <= b)
      return val;

    push();
    return left->qry(a, b) + right->qry(a, b);
  }
  void upd(int a, int b) {
    if (a > r || b < l)
      return;
    if (a <= l && r <= b) {
      val += r - l + 1;
      set = 1;
      return;
    }
    push();
    left->upd(a, b);
    right->upd(a, b);
    pull();
  }
};

void solve() {
  int m;
  cin >> m;

  Node seg(0, 1e9);

  int c = 0;
  while (m--) {
    int d, x, y;
    cin >> d >> x >> y;
    if (d == 1) {
      int res = seg.qry(x + c, y + c);
      cout << res << '\n';
      c = res;
    } else {
      seg.upd(x + c, y + c);
    }
  }
}

int main() {
#ifdef DEV_MODE
  freopen("misc-in.txt", "r", stdin);
#else
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
#endif
  int t;
  if (MULTITEST)
    cin >> t;
  else
    t = 1;
  while (t--)
    solve();
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -