Submission #39310

#TimeUsernameProblemLanguageResultExecution timeMemory
39310chonkaMonkey and Apple-trees (IZhO12_apple)C++98
100 / 100
546 ms215872 KiB
#include<iostream>
#include<stdio.h>
using namespace std ;


struct Tree {
	int IL , IR ;
	int val ;
	int lazy ;
	Tree *pl , *pr ;
	Tree ( int x , int y ) {
		this->IL = x ;
		this->IR = y ;
		this->lazy = 0 ;
		this->val = 0 ;
		this->pl = this->pr = NULL ;
	}
	void push ( ) {
		if ( this->IL == this->IR ) { return ; }
		if ( this->pl != NULL ) { return ; }
		int mid = ( this->IL + this->IR ) / 2 ;
		this->pl = new Tree ( this->IL , mid ) ;
		this->pr = new Tree ( mid + 1 , this->IR ) ;
	}
	void push_lazy ( ) {
		if ( this->lazy == 0 ) { return ; }
		this->val = ( this->IR - this->IL + 1 ) ;
		if ( this->IL != this->IR ) {
			this->pl->lazy = 1 ;
			this->pr->lazy = 1 ;
		}
		this->lazy = 0 ;
	}
	void recalc ( ) {
		this->pl->push_lazy ( ) ;
		this->pr->push_lazy ( ) ;
		this->val = this->pl->val + this->pr->val ;
	}
	void update ( int x , int y ) {
		this->push ( ) ;
		if ( this->lazy == 1 ) { return ; }
		this->push_lazy ( ) ;
		if ( this->IR < x || y < this->IL ) { return ; }
		if ( x <= this->IL && this->IR <= y ) {
			this->lazy = 1 ;
			this->push_lazy ( ) ;
			return ;
		}
		this->pl->update ( x , y ) ;
		this->pr->update ( x , y ) ;
		this->recalc ( ) ;
	}
	int query ( int x , int y ) {
		if ( this == NULL ) { return 0 ; }
		this->push ( ) ;
		this->push_lazy ( ) ;
		if ( this->IR < x || y < this->IL ) { return 0 ; }
		if ( x <= this->IL && this->IR <= y ) { return this->val ; }
		return this->pl->query ( x , y ) + this->pr->query ( x , y ) ;
	}
};

Tree *root ;

int main ( ) {
	root = new Tree ( 1 , 1000000000 ) ;
	int q ;
	scanf ( "%d" , &q ) ;
	int type , x , y ;
	int c = 0 ;
	while ( q != 0 ) {
		q -- ;
		scanf ( "%d%d%d" , &type , &x , &y ) ;
		x += c ;
		y += c ;
		if ( type == 2 ) {
			root->update ( x , y ) ;
		}
		else {
			c = root->query ( x , y ) ;
			printf ( "%d\n" , c ) ;
		}
	}
	return 0 ;
}

Compilation message (stderr)

apple.cpp: In function 'int main()':
apple.cpp:68:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf ( "%d" , &q ) ;
                      ^
apple.cpp:73:40: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf ( "%d%d%d" , &type , &x , &y ) ;
                                        ^
#Verdict Execution timeMemoryGrader output
Fetching results...