#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
const int M = 1e9, N = 3000005;
int n = 1;
int s[N], L[N], R[N];
bool cov[N];
void upd(int u, int v, int id = 1, int l = 1, int r = M) {
if (u <= l && r <= v) {
s[id] = r - l + 1;
cov[id] = 1;
return;
}
int m = (l + r) / 2;
if (!cov[id]) {
if (u <= m) {
if (!L[id]) {
L[id] = ++n;
}
upd(u, v, L[id], l, m);
}
if (m < v) {
if (!R[id]) {
R[id] = ++n;
}
upd(u, v, R[id], m + 1, r);
}
s[id] = s[L[id]] + s[R[id]];
cov[id] = s[id] == r - l + 1;
}
}
int qry(int u, int v, int id = 1, int l = 1, int r = M) {
if (u <= l && r <= v) {
return s[id];
}
int m = (l + r) / 2;
int res = 0;
if (u <= m) {
if (!L[id]) {
L[id] = ++n;
if (cov[id]) {
s[n] = m - l + 1;
cov[n] = 1;
}
}
res += qry(u, v, L[id], l, m);
}
if (m < v) {
if (!R[id]) {
R[id] = ++n;
if (cov[id]) {
s[n] = r - m;
cov[n] = 1;
}
}
res += qry(u, v, R[id], m + 1, r);
}
return res;
}
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int m; cin >> m;
int c = 0;
while (m--) {
int d, x, y; cin >> d >> x >> y;
x += c, y += c;
if (d == 1) {
cout << (c = qry(x, y)) << "\n";
} else {
upd(x, y);
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Runtime error |
144 ms |
262144 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |