Submission #1275563

#TimeUsernameProblemLanguageResultExecution timeMemory
1275563huseyncafarliMonkey and Apple-trees (IZhO12_apple)C++20
0 / 100
1 ms568 KiB
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define nline '\n'
#define lsb(x) ((x) & -(x))
#define int ll
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)
using namespace std;

const int sz = 2e5 + 5;
const int inf = 2e9 + 5;
const int mod1 = 1e9 + 7;
const int mod2 = 998244353;

struct node {
  int lchild=0, rchild=0, res=0;
};

node st[sz*40];
int lazy[sz*40];

int last = 1;
void relax(int v, int l, int r) {
  if (!lazy[v]) return;
  st[v].res = (r - l + 1);
  if (l != r) {
    if (!st[v].lchild) {
      st[v].lchild = ++last;
      st[v].rchild = ++last;
    }
    lazy[st[v].lchild] = 1;
    lazy[st[v].rchild] = 1;
  }
  lazy[v] = 0;
}

void update(int v, int l, int r, int a, int b) {
  relax(v, l, r);
  if (r < a or l > b) return;
  if (l >= a and r <= b) {
    lazy[v] = 1;
    relax(v, l, r);
    return;
  }
  int mid = (l + r) >> 1;
  if (!st[v].lchild) {
    st[v].lchild = ++last;
    st[v].rchild = ++last;
  }
  update(st[v].lchild, l, mid, a, b);
  update(st[v].rchild, mid+1, r, a, b);
  st[v].res = st[st[v].lchild].res + st[st[v].rchild].res;
}

int getans(int v, int l, int r, int a, int b) {
  relax(v, l, r);
  if (!v) return 0;
  if (r < a or l > b) return 0;
  if (l >= a and r <= b) return st[v].res;
  int mid = (l + r) >> 1;
  return getans(st[v].lchild, l, mid, a, b) + getans(st[v].rchild, mid+1, r, a, b);
}

void solve(){
  int m, c = 0;
  cin >> m;
  while (m--) {
    int d, x, y;
    cin >> d >> x >> y;
    if (d == 1) {
      int ans = getans(1,1,1e9, x + c, y + c);
      c += ans;
      cout << ans << nline;
    } else {
      update(1,1,1e9,x + c,y + c);
    }
  }
}
signed main(){
  fastio;
  int t = 1;
  // cin >> t;
  while(t--) {
    solve();
  }
}
#Verdict Execution timeMemoryGrader output
Fetching results...