#include <bits/stdc++.h>
using namespace std; using ii = pair<int,int>; using ll = long long;
#define rep(i,a,b) for (auto i = (a); i <= (b); ++i)
#define all(x) (x).begin(), (x).end()
#define siz(x) int((x).size())
#define Mup(x,y) x = max(x,y)
#define mup(x,y) x = min(x,y)
struct node {
int v; bool z;
int s, e;
node *l, *r;
node(int s, int e): v(0), z(0), s(s), e(e) {}
void propagate() {
int m = (s+e)/2;
if (!l) l = new node(s,m);
if (!r) r = new node(m+1,e);
if (z) {
l->v = m-s+1;
r->v = e-m;
l->z = r->z = 1;
z = 0;
}
}
void update(int a, int b) {
if (a <= s and e <= b) {
v = e-s+1, z = 1;
return;
}
if (b < s or e < a) return;
propagate();
l->update(a,b), r->update(a,b);
v = (l?l->v:0) + (r?r->v:0);
}
int query(int a, int b) {
if (a <= s and e <= b) return v;
if (b < s or e < a) return 0;
propagate();
return (l?l->query(a,b):0) + (r?r->query(a,b):0);
}
};
int m;
int main() {
node *ds = new node(1,int(1e9));
ll c = 0;
scanf("%d", &m); while (m--)
{
int d, x, y;
scanf("%d %d %d", &d, &x, &y);
if (d == 1) {
c = ds->query(x+c,y+c);
printf("%lld\n", c);
} else {
ds->update(x+c,y+c);
}
}
}
Compilation message
apple.cpp: In function 'int main()':
apple.cpp:51:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
51 | scanf("%d", &m); while (m--)
| ~~~~~^~~~~~~~~~
apple.cpp:54:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
54 | scanf("%d %d %d", &d, &x, &y);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
304 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
12 ms |
4924 KB |
Output is correct |
5 |
Correct |
15 ms |
5944 KB |
Output is correct |
6 |
Correct |
14 ms |
5716 KB |
Output is correct |
7 |
Correct |
17 ms |
5948 KB |
Output is correct |
8 |
Correct |
120 ms |
44376 KB |
Output is correct |
9 |
Correct |
248 ms |
76256 KB |
Output is correct |
10 |
Correct |
250 ms |
84376 KB |
Output is correct |
11 |
Correct |
282 ms |
90528 KB |
Output is correct |
12 |
Correct |
262 ms |
93536 KB |
Output is correct |
13 |
Correct |
229 ms |
109900 KB |
Output is correct |
14 |
Correct |
228 ms |
110936 KB |
Output is correct |
15 |
Correct |
368 ms |
201940 KB |
Output is correct |
16 |
Correct |
382 ms |
203072 KB |
Output is correct |
17 |
Correct |
233 ms |
114700 KB |
Output is correct |
18 |
Correct |
232 ms |
114756 KB |
Output is correct |
19 |
Correct |
386 ms |
207792 KB |
Output is correct |
20 |
Correct |
380 ms |
207692 KB |
Output is correct |