# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
919216 | ibrahim001 | 원숭이와 사과 나무 (IZhO12_apple) | C++14 | 607 ms | 255316 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "bits/stdc++.h"
#define intt long long
using namespace std;
const intt inf = 1e18;
const int sz = 1e5+5;
int st[sz*80], lz[sz*80], L[sz*80], R[sz*80];
int last=1;
void check(int in){
if ( !L[in] ) L[in] = ++last;
if ( !R[in] ) R[in] = ++last;
}
void relax(int l, int r, int in){
if ( !lz[in] ) return;
st[in] = (r-l+1);
if ( l == r ){
lz[in]=0;
return;
}
check(in);
lz[L[in]] += lz[in];
lz[R[in]] += lz[in];
lz[in]=0;
}
void update(int a, int b, int l, int r, int in){
relax(l, r, in);
if ( l > b or r < a ) return;
if ( a <= l and r <= b ){
lz[in]++;
relax(l, r, in);
return;
}
check(in);
int mid = (l+r)>>1;
update(a, b, l, mid, L[in]);
update(a, b, mid+1, r, R[in]);
st[in] = st[L[in]]+st[R[in]];
}
int getans(int a, int b, int l, int r, int in){
relax(l, r, in);
if ( l > b or r < a ) return 0;
if ( a <= l and r <= b ) return st[in];
check(in);
int mid = (l+r)>>1;
return getans(a, b, l, mid, L[in])+getans(a, b, mid+1, r, R[in]);
}
int i,j;
signed main(){
int n=1e9, q;
cin >> q;
int c = 0;
while(q--){
int t;
cin >> t;
int x, y;
cin >> x >> y;
x += c;
y += c;
if ( t == 1 ){
int res = getans(x , y, 1, n, 1);
c = res;
cout << res << endl;
}
else{
update(x, y, 1, n, 1);
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |