#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include <debug.h>
#else
#define debug(...) 42
#endif
#define int long long
class SparseSegtree {
private:
struct Node {
int freq = 0;
int lazy = 0;
Node *left = nullptr;
Node *right = nullptr;
};
Node *root = new Node;
const int n;
int comb(int a, int b) { return a + b; }
void apply(Node *cur, int len, int val) {
if (val == 1) {
(cur->lazy) = val;
(cur->freq) = len * val;
}
}
void push_down(Node *cur, int l, int r) {
if ((cur->left) == nullptr) { (cur->left) = new Node; }
if ((cur->right) == nullptr) { (cur->right) = new Node; }
int m = (l + r) / 2;
apply(cur->left, m - l + 1, cur->lazy);
apply(cur->right, r - m, cur->lazy);
}
void range_set(Node *cur, int l, int r, int ql, int qr, int val) {
if (qr < l || ql > r) { return; }
if (ql <= l && r <= qr) {
apply(cur, r - l + 1, val);
} else {
push_down(cur, l, r);
int m = (l + r) / 2;
range_set(cur->left, l, m, ql, qr, val);
range_set(cur->right, m + 1, r, ql, qr, val);
(cur->freq) = comb((cur->left)->freq, (cur->right)->freq);
}
}
int range_sum(Node *cur, int l, int r, int ql, int qr) {
if (qr < l || ql > r) { return 0; }
if (ql <= l && r <= qr) { return cur->freq; }
push_down(cur, l, r);
int m = (l + r) / 2;
return comb(range_sum(cur->left, l, m, ql, qr),
range_sum(cur->right, m + 1, r, ql, qr));
}
public:
SparseSegtree(int n) : n(n) {}
void range_set(int ql, int qr, int val) { range_set(root, 0, n - 1, ql, qr, val); }
int range_sum(int ql, int qr) { return range_sum(root, 0, n - 1, ql, qr); }
};
void solve(){
int q;
cin >> q;
SparseSegtree st(1e9 + 1);
int c = 0;
while(q--){
int t, x, y;
cin >> t >> x >> y;
if (t == 1){
c = st.range_sum(x + c, y + c);
cout << c << "\n";
}
else{
st.range_set(x + c, y + c, 1);
}
}
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int tt = 1;
// cin >> tt;
while(tt--) {
solve();
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |