Submission #489767

# Submission time Handle Problem Language Result Execution time Memory
489767 2021-11-24T14:22:53 Z czhang2718 Monkey and Apple-trees (IZhO12_apple) C++14
100 / 100
218 ms 71156 KB
#include "bits/stdc++.h"
using namespace std;

int m;
const int MX=7000000;
int cnt;
int child[MX][2];
int on[MX], sum[MX];

void push(int x, int lx, int rx){
  if(!on[x]) return;
  if(!child[x][0]) child[x][0]=++cnt, child[x][1]=++cnt;
  on[child[x][0]]=on[child[x][1]]=1;
  int m=(lx+rx)/2;
  sum[child[x][0]]=m-lx;
  sum[child[x][1]]=rx-m;
}

void upd(int l, int r, int x, int lx, int rx){
  if(lx>=l && rx<=r){
    on[x]=1;
    sum[x]=rx-lx;
    return;
  }
  if(lx>=r || rx<=l) return;
  push(x, lx, rx);
  int m=(lx+rx)/2;
  if(!child[x][0]) child[x][0]=++cnt, child[x][1]=++cnt;
  upd(l, r, child[x][0], lx, m);
  upd(l, r, child[x][1], m, rx);
  sum[x]=sum[child[x][0]]+sum[child[x][1]];
}

void upd(int l, int r){
  upd(l, r, 0, 0, 1e9+1);
}

int calc(int l, int r, int x, int lx, int rx){
  if(lx>=l && rx<=r) return sum[x];
  if(lx>=r || rx<=l) return 0;
  push(x, lx, rx);
  int m=(lx+rx)/2;
  if(!child[x][0]) child[x][0]=++cnt, child[x][1]=++cnt;
  return calc(l, r, child[x][0], lx, m)+calc(l, r, child[x][1], m, rx);
}

int calc(int l, int r){
  return calc(l, r, 0, 0, 1e9+1);
}

int main(){
  cin.tie(0)->sync_with_stdio(0);

  cin >> m;
  int c=0;
  while(m--){
    int op, x, y; cin >> op >> x >> y;
    x+=c;
    y+=c;
    if(op==1){
      int ans=calc(x, y+1);
      cout << ans << '\n';
      c=ans;
    }
    else upd(x, y+1);
  }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 8 ms 1868 KB Output is correct
5 Correct 9 ms 2124 KB Output is correct
6 Correct 9 ms 2036 KB Output is correct
7 Correct 10 ms 2124 KB Output is correct
8 Correct 70 ms 14896 KB Output is correct
9 Correct 164 ms 25624 KB Output is correct
10 Correct 154 ms 28324 KB Output is correct
11 Correct 179 ms 30440 KB Output is correct
12 Correct 161 ms 31300 KB Output is correct
13 Correct 138 ms 36548 KB Output is correct
14 Correct 157 ms 36976 KB Output is correct
15 Correct 218 ms 67020 KB Output is correct
16 Correct 208 ms 69732 KB Output is correct
17 Correct 150 ms 40132 KB Output is correct
18 Correct 157 ms 40192 KB Output is correct
19 Correct 207 ms 71156 KB Output is correct
20 Correct 213 ms 71112 KB Output is correct