using namespace std;
#include <bits/stdc++.h>
#define i32 int
#define i64 long long
#define u32 unsigned int
#define u64 unsigned long long
#define f32 float
#define f64 double
#define vec vector
#define F0R(i, e) for(i32 i = 0; i<e; i++)
#define FOR(i, s, e) for(i32 i = s; i<e; i++)
#define F0Rd(i, e) for(i32 i = e-1; i>=0; i--)
#define FORd(i, s, e) for(i32 i = e-1; i>=s; i--)
#define TRAV(v, g) for(auto v: g)
const i32 INF_32 = INT32_MAX/3;
const i64 INF_64 = INT64_MAX/3;
struct SegNode {
i32 ll=0, rr=1e9+5;
i32 cnt = 0;
SegNode *left=nullptr, *right=nullptr;
i32 update(i32 l, i32 r) {
if(ll >= r || rr <= l || cnt == rr-ll) {
return 0;
}
if(l<=ll && r>=rr) {
i32 dif = (rr-ll)-cnt;
cnt = rr-ll;
return dif;
}
if(left == nullptr) {
assert(right == nullptr);
i32 m = (ll+rr)/2;
left = new SegNode {ll, m};
right = new SegNode {m, rr};
}
i32 dl = left->update(l, r);
i32 dr = right->update(l, r);
// cout << "retrieved dif " << dl+dr << endl;
cnt += dl + dr;
return dl+dr;
}
i32 query(i32 l, i32 r) {
// cerr << "querying... " << l << " " << r << endl;
if(ll>=r || rr <= l) {
return 0;
}
if(l<=ll && r>=rr) {
return cnt;
}
if(rr-ll == cnt) {
i32 al = max(ll, l);
i32 br = min(rr, r);
return br-al;
}
if(left != nullptr) {
assert(right != nullptr);
i32 ccnt = left->query(l, r) + right->query(l, r);
// cout << "retrieved cnt " << ccnt << endl;
return ccnt;
}
return 0;
}
};
SegNode root;
void solve() {
i32 m;
cin >> m;
i32 c = 0;
while(m--) {
i32 d,x,y; cin >> d >> x >> y; x--;
x+=c;
y+=c;
if(d==1) {
i32 res = root.query(x, y);
c += res;
cout << res << '\n';
}
else {
root.update(x, y);
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
i32 t = 1;
// cin >> t;
while(t--) {
solve();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |