# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
31733 | trath | Monkey and Apple-trees (IZhO12_apple) | C++14 | 0 ms | 2016 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 <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 pullnewleft(){
if(!left){
left = new node();
}
}
void pullnewright(){
if(!right){
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;
}
int mid = (l+r)/2;
if(y <= mid){
curr->pullnewleft();
update(x , y , curr-> left , l ,mid);
}
else if(x > mid){
curr->pullnewright();
update(x , y, curr->right , mid + 1 , r);
}
else{
curr->pullnewright();
curr->pullnewleft();
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(curr->flag) return y-x + 1;
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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |