#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(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:83:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld" , &q);
^
apple.cpp:85: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 |
Runtime error |
0 ms |
2016 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |