#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] )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("%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
apple.cpp: In function 'int get(int, int, int, int, int)':
apple.cpp:58:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid = tl + tr >> 1;
~~~^~~~
apple.cpp: At global scope:
apple.cpp:64:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main()
^
apple.cpp: In function 'int main()':
apple.cpp:67:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d" , &t);
~~~~~^~~~~~~~~~~
apple.cpp:72:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d" , &d , &l , &r);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
576 KB |
Output is correct |
4 |
Correct |
54 ms |
13072 KB |
Output is correct |
5 |
Correct |
29 ms |
14680 KB |
Output is correct |
6 |
Correct |
28 ms |
14680 KB |
Output is correct |
7 |
Correct |
37 ms |
14712 KB |
Output is correct |
8 |
Correct |
206 ms |
64444 KB |
Output is correct |
9 |
Correct |
346 ms |
82488 KB |
Output is correct |
10 |
Correct |
389 ms |
113152 KB |
Output is correct |
11 |
Correct |
434 ms |
142404 KB |
Output is correct |
12 |
Correct |
404 ms |
155816 KB |
Output is correct |
13 |
Incorrect |
294 ms |
155816 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |