# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
90290 | Aydarov03 | Monkey and Apple-trees (IZhO12_apple) | C++14 | 2 ms | 256 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>
using namespace std;
const int N = 1e5 + 7;
bool tree[N];
int n = N;
void push( int tl , int tr , int v )
{
if( tree[v] == true )
{
tree[v + v] = tree[v + v + 1] = true;
tree[v] = false;
}
}
void upd( int l , int r , int v = 1 , int tl = 1 , int tr = 10 )
{
if( tl > r || tr < l || tree[v] == true)
return;
if( l <= tl && tr <= r )
{
tree[v] = true;
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 = 10 )
{
if( tl > r || tr < l )
return 0;
if( l <= tl && tr <= r && tree[v] == true )
{
return ( tr - tl + 1);
}
if( tl == tr )return 0;
int mid = ( tl + tr ) / 2;
return get( l , r , v+v , tl , mid ) + get( l , r , v+v+1 , mid+1 , tr );
}
main()
{
int t , d , l , r;
cin >> t;
for(int i = 1; i <= t; i++)
{
scanf("%d%d%d" , &d , &l , &r);
if( d == 2 )
upd( l , r );
else
cout << get( l , r ) << endl;
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |