# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
90299 | Aydarov03 | Monkey and Apple-trees (IZhO12_apple) | C++14 | 217 ms | 73972 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>
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])
{
tree[v] = ( tr - tl + 1 );
add[v+v] = add[v+v+1] = 1;
add[v] = 0;
}
}
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)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("%d" , &t);
while( t-- )
{
int d , l , r;
scanf("%d%d%d" , &d , &l , &r);
l += c , r += c;
if( d == 2 )
{
upd( l , r);
}
else
{
c = get( l , r );
printf("%d\n" , c);
}
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |