#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second
using namespace std;
const int inf = 1e9;
struct node {
int val, lz;
int st, en, len;
node *left, *right;
void build(int start, int end) {
st = start;
en = end;
len = en - st + 1;
lz = 0;
}
void lazy() {
if (left == NULL) {
int md = (st + en) / 2;
left = new node();
right = new node();
left->build(st, md);
right->build(md + 1, en);
}
if (lz == 1) {
left->val = lz * left->len;
left->lz = lz;
right->val = lz * right->len;
right->lz = lz;
}
}
int query(int lf, int rg) {
if (st > rg || en < lf) return 0ll;
if (lf <= st && en <= rg) return val;
if (left == NULL) return 0ll;
lazy();
return left->query(lf, rg) + right->query(lf, rg);
}
void update(int lf, int rg) {
if (st > rg || en < lf) return;
if (lf <= st && en <= rg) {
val = 1 * len;
lz = 1;
return;
}
lazy();
left->update(lf, rg);
right->update(lf, rg);
val = left->val + right->val;
}
} sg;
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int q;
cin >> q;
int c = 0;
sg.build(1, inf);
for (int i = 0; i < q; i++) {
int t, x, y;
cin >> t >> x >> y;
if (t == 1) {
int ans = sg.query(x + c, y + c);
cout << ans << '\n';
c = ans;
} else if (t == 2) {
sg.update(x + c, y + c);
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |