#include <bits/stdc++.h>
using namespace std;
const int maxn = (int) 1e7 + 7;
int seg[4 * maxn + 7];
int lazy[4 * maxn + 7];
void down(int id, int l, int r) {
if (lazy[id] && l < r) {
int &v = lazy[id];
int g = (l + r) >> 1;
seg[id << 1] = g - l + 1;
seg[id << 1 | 1] = r - g;
lazy[id << 1] += v;
lazy[id << 1 | 1] += v;
v = 0;
return;
}
}
void update(int id, int l, int r, int u, int v) {
if (l > v || u > r) return;
if (u <= l && r <= v) {
seg[id] = r - l + 1;
lazy[id] = 1;
return;
}
down(id, l, r);
int g = (l + r) >> 1;
update(id << 1, l, g, u, v);
update(id << 1 | 1, g + 1, r, u, v);
seg[id] = seg[id << 1] + seg[id << 1 | 1];
}
int get(int id, int l, int r, int u, int v) {
if (l > v || u > r) return 0;
if (u <= l && r <= v) return seg[id];
down(id, l, r);
int g = (l + r) >> 1;
return get(id << 1, l, g, u, v) + get(id << 1 | 1, g + 1, r, u, v);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
if (fopen("test.inp","r")) {
freopen("test.inp","r",stdin);
freopen("test.out","w",stdout);
}
int n;
cin >> n;
int preAns = 0;
while (n--) {
int type, l, r;
cin >> type >> l >> r;
l += preAns;
r += preAns;
assert(l <= maxn);
assert(r <= maxn);
if (type == 2) {
update(1, 1, maxn, l, r);
} else {
cout << (preAns = get(1, 1, maxn, l, r)) << "\n";
}
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
apple.cpp: In function 'int main()':
apple.cpp:47:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
47 | freopen("test.inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
apple.cpp:48:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
48 | freopen("test.out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |