제출 #653519

#제출 시각아이디문제언어결과실행 시간메모리
653519amukkalir원숭이와 사과 나무 (IZhO12_apple)C++17
0 / 100
398 ms155380 KiB
#include "bits/stdc++.h" using namespace std; const int nax = 1e7; int tree[4*nax+5]; bool lazy[4*nax+5]; int n; void cek (int idx, int l, int r) { if(!lazy[idx]) return; tree[idx] = r-l+1; if(r!=l) { lazy[idx<<1] = 1; lazy[idx<<1|1] = 1; } lazy[idx]=0; } void upd (int fr, int to, int idx = 1, int l = 1, int r = nax) { cek (idx, l, r) ; if (r < fr || l > to) return; else if (fr <= l && r <= to) { lazy[idx]=1; cek(idx,l,r); } else { int m = (l+r) >> 1; upd(fr, to, idx<<1, l, m); upd(fr, to, idx<<1|1, m+1, r); tree[idx] = tree[idx<<1] + tree[idx<<1|1]; } } long long get (int fr, int to, int idx = 1, int l=1, int r=nax) { cek(idx, l, r); if (r < fr || l > to) return 0; else if (fr <= l && r <= to) return tree[idx]; else { int m = (l+r) >> 1; return get(fr, to, idx<<1, l, m) + get (fr, to, idx<<1|1, m+1, r); } } signed main () { int m; cin >> m; long long c = 0; while (m--) { long long tp, l, r; cin >> tp >> l >> r; l += c; r += c; assert(r <= 1e7); if(tp == 1) { long long res = get(l,r); cout << res << "\n"; c = res; } else { upd(l,r); } } } /* */
#Verdict Execution timeMemoryGrader output
Fetching results...