#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define F first
#define S second
#define pb push_back
const long MAXN = 200000;
struct node{
int left, right;
int sum = 0, lazy = 0;
node *left_child = nullptr, *right_child = nullptr;
node(int l, int r){
left = l;
right = r;
}
void expand(){
if(!left_child and left != right){
int m = (left + right)/2;
left_child = new node(left, m);
right_child = new node(m + 1, right);
}
}
void update(int a, int b){
if(left > b or right < a) return;
if(left >= a and right <= b){
lazy = 1;
sum = right - left + 1;
return;
}
expand();
if(lazy != 0){
sum = right - left + 1;
if(left != right){
left_child->lazy = 1;
right_child->lazy = 1;
}
lazy = 0;
}
left_child->update(a, b);
right_child->update(a, b);
sum = left_child->sum + right_child->sum;
return;
}
int query(int a, int b){
if(left > b or right < a) return 0;
if(left >= a and right <= b) return sum;
expand();
if(lazy != 0){
sum = right - left + 1;
if(left != right){
left_child->lazy = 1;
right_child->lazy = 1;
}
lazy = 0;
}
return left_child->query(a, b) + right_child->query(a, b);
}
};
int main(){
node *root = new node(0, 1e9 - 1);
int M, C = 0;
cin >> M;
for(int i = 0; i < M; i++){
int d, x, y;
cin >> d >> x >> y;
if(d == 2){
root->update(x + C, y + C);
}
else{
C = root->query(x + C, y + C);
cout << C << "\n";
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |