# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
90301 | Aydarov03 | Monkey and Apple-trees (IZhO12_apple) | C++14 | 604 ms | 247056 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 <stdio.h>
#define int long long
using namespace std;
const int N = 1e7 + 7;
int tree[N*4];
bool add[N*4];
int c;
void push( int tl , int tr , int v )
{
if( !add[v] || tree[v] )return;
tree[v] = ( tr - tl + 1 );
add[v] = 0;
if( tl != tr )
add[v+v] = add[v+v+1] = 1;
}
void upd( int l , int r , int v = 1 , int tl = 1 , int tr = N )
{
push( tl , tr , v );
if( tl > r || tr < l )return;
if( l <= tl && tr <= r )
{
add[v] = 1;
push( tl , tr , v);
return;
}
int mid = ( tl + tr ) / 2;
upd( l , r , v + v , tl , mid );
upd( l , r , v+v+1 , mid+1 , tr );
}
int get( int l , int r , int v = 1 , int tl = 1 , int tr = N )
{
push( tl , tr , v );
if( tl > r || tr < l )
return 0;
if( l <= tl && tr <= r )
{
if( tree[v] )
return tree[v];
}
if(tl == tr && !tree[v] )return 0;
int mid = tl + tr >> 1;
return get( l , r , v + v , tl , mid ) + get( l , r , v+v+1 , mid+1 , tr );
}
main()
{
int t;
scanf("%lld" , &t);
while( t-- )
{
int d , l , r;
scanf("%lld%lld%lld" , &d , &l , &r);
l += c , r += c;
if( d == 2 )
{
upd( l , r );
}
else
{
c = get( l , r );
printf("%lld\n" , c);
}
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |