Submission #31728

# Submission time Handle Problem Language Result Execution time Memory
31728 2017-09-03T01:01:51 Z trath Monkey and Apple-trees (IZhO12_apple) C++11
0 / 100
0 ms 2016 KB
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define int long long
#define ieps (int) 1e6
#define eps (int) 1e9
#define pii pair<int,int>
int n , xp , yp;
struct node{
	bool flag = 0;
	int soma = 0;
	struct node *left , *right;
	node() : left(NULL) , right(NULL) {}
	void pullnew(){
		if(!left){
			left = new node();
			right = new node();
		}
	}


};

node *st = new node();

void update(int x , int y , node *curr , int l = 1 , int r = (int) 1e9){
	if(curr->flag) return;
	if(x == l && y == r){
		curr->flag  = true;
		curr->soma = y - x + 1;
		return;
	}
	curr->pullnew();
	int mid = (l+r)/2;
	if(y <= mid){
		update(x , y , curr-> left , l ,mid);
	}
	else if(x > mid){
		update(x , y,  curr->right , mid + 1 , r);
	}
	else{
		update(x , mid , curr->left , l , mid);
		update(mid + 1 , y , curr->right , mid + 1 , r);
	}
	curr->flag = min(curr->left->flag , curr->right->flag);
	curr->soma = (curr->flag ? r - l + 1 : curr->left->soma + curr->right->soma);
}

int getsum(int x , int y , node *curr , int l = 1 , int r=  (int) 1e9){
	if(x == l && y == r){
		return curr->soma;
	}
	int mid = (l+r)/2;
	if(y <= mid){
		if(!(curr->left)) return (y-x + 1);
		return getsum(x , y , curr->left , l , mid );
	}
	else if(x > mid){
		if(!(curr -> right)) return (y-x+1);
		return getsum(x , y , curr->right , mid + 1 , r);
	}
	else{
		int t = 0;
		if(curr->left) t+= getsum(x , mid , curr->left , l ,mid);
		if(curr->right) t+= getsum(mid + 1 , y , curr->right , mid + 1 , r);
		if(!curr->left && !curr->right) return y - x + 1;
		return t;
	}
}
int c = 0LL;

int32_t main(){
	int q;
	scanf("%lld" , &q);
	while(q--){
	scanf("%lld%lld%lld" , &n ,&xp , &yp);
	if(n == 1){
		c = getsum(xp + c , yp + c , st);
		printf("%lld\n" , c);
	}
	else{
		update(xp + c , yp + c , st);
	}
}
}

Compilation message

apple.cpp: In function 'int32_t main()':
apple.cpp:77:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld" , &q);
                    ^
apple.cpp:79:39: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld%lld%lld" , &n ,&xp , &yp);
                                       ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2016 KB Output is correct
2 Incorrect 0 ms 2016 KB Output isn't correct
3 Halted 0 ms 0 KB -