Submission #90316

# Submission time Handle Problem Language Result Execution time Memory
90316 2018-12-21T08:35:55 Z Aydarov03 Monkey and Apple-trees (IZhO12_apple) C++14
0 / 100
5 ms 504 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 1e7 + 7;
	
int tree[N*3];
bool add[N*3];
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

apple.cpp: In function 'int get(int, int, int, int, int)':
apple.cpp:56:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int mid = tl + tr >> 1;
            ~~~^~~~
apple.cpp: At global scope:
apple.cpp:62:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main()
      ^
apple.cpp: In function 'int main()':
apple.cpp:65:19: warning: format '%lld' expects argument of type 'long long int*', but argument 2 has type 'int*' [-Wformat=]
  scanf("%lld" , &t);
                 ~~^
apple.cpp:70:38: warning: format '%lld' expects argument of type 'long long int*', but argument 2 has type 'int*' [-Wformat=]
   scanf("%lld%lld%lld" , &d , &l , &r);
                          ~~          ^
apple.cpp:70:38: warning: format '%lld' expects argument of type 'long long int*', but argument 3 has type 'int*' [-Wformat=]
apple.cpp:70:38: warning: format '%lld' expects argument of type 'long long int*', but argument 4 has type 'int*' [-Wformat=]
apple.cpp:81:23: warning: format '%lld' expects argument of type 'long long int', but argument 2 has type 'int' [-Wformat=]
    printf("%lld\n" , c);
                       ^
apple.cpp:65:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld" , &t);
  ~~~~~^~~~~~~~~~~~~
apple.cpp:70:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld%lld%lld" , &d , &l , &r);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -