# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
39310 | chonka | Monkey and Apple-trees (IZhO12_apple) | C++98 | 546 ms | 215872 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<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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |