#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <fstream>
#include <bitset>
typedef long long ll;
using namespace std;
const int N = 1e7 + 10;
int sz = 1;
int lazy[N];
int sm[N];
int l[N];
int r[N];
void update(int v, int tl, int tr, int ql, int qr) {
if (tl > qr || tr < ql) {
return;
}
if (tl >= ql && tr <= qr) {
sm[v] = (tr - tl + 1);
lazy[v] = 1;
return;
}
if (!l[v]) l[v] = ++sz;
if (!r[v]) r[v] = ++sz;
int tm = (tl + tr) / 2;
if (lazy[v]) {
lazy[l[v]] = 1;
sm[l[v]] = (tm - tl + 1);
lazy[r[v]] = 1;
sm[r[v]] = (tr - tm);
lazy[v] = 0;
}
update(l[v], tl, tm, ql, qr);
update(r[v], tm + 1, tr, ql, qr);
sm[v] = sm[l[v]] + sm[r[v]];
}
int sum(int v, int tl, int tr, int ql, int qr) {
if (tr < ql || tl > qr) return 0;
if (tl >= ql && tr <= qr) {
return sm[v];
}
if (!l[v]) l[v] = ++sz;
if (!r[v]) r[v] = ++sz;
int tm = (tl + tr) / 2;
if (lazy[v]) {
lazy[l[v]] = 1;
sm[l[v]] = (tm - tl + 1);
lazy[r[v]] = 1;
sm[r[v]] = (tr - tm);
lazy[v] = 0;
}
return sum(l[v], tl, tm, ql, qr) + sum(r[v], tm + 1, tr, ql, qr);
}
int main() {
int m, c = 0;
cin >> m;
for (int i = 1; i <= m; i++) {
int d, x, y;
cin >> d >> x >> y;
if (y + c > 1e7) {
throw "esim";
}
if (d == 2) {
update(1, 1, 1e9, x + c, y + c);
}
else {
c = sum(1, 1, 1e9, x + c, y + c);
cout << c << "\n";
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
14 ms |
1828 KB |
Output is correct |
5 |
Correct |
18 ms |
3932 KB |
Output is correct |
6 |
Correct |
17 ms |
3676 KB |
Output is correct |
7 |
Correct |
18 ms |
4184 KB |
Output is correct |
8 |
Correct |
104 ms |
15444 KB |
Output is correct |
9 |
Correct |
220 ms |
29424 KB |
Output is correct |
10 |
Correct |
231 ms |
31004 KB |
Output is correct |
11 |
Correct |
235 ms |
31784 KB |
Output is correct |
12 |
Correct |
242 ms |
32080 KB |
Output is correct |
13 |
Runtime error |
5 ms |
600 KB |
Execution killed with signal 6 |
14 |
Halted |
0 ms |
0 KB |
- |