Submission #31730

# Submission time Handle Problem Language Result Execution time Memory
31730 2017-09-03T02:04:52 Z trath Monkey and Apple-trees (IZhO12_apple) C++
0 / 100
139 ms 262144 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 curr->flag ? y - x + 1 : 0;
		return getsum(x , y , curr->left , l , mid );
	}
	else if(x > mid){
		if(!(curr -> right)) return curr->flag ? y - x + 1 : 0;
		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 curr->flag ? y - x + 1 : 0;
		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:13:14: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11
  bool flag = 0;
              ^
apple.cpp:14:13: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11
  int soma = 0;
             ^
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 Correct 0 ms 2016 KB Output is correct
3 Memory limit exceeded 139 ms 262144 KB Memory limit exceeded
4 Halted 0 ms 0 KB -