#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define eb emplace_back
#define task ""
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define nx freopen (task".inp","r",stdin), freopen (task".out","w",stdout);
#define fi first
#define se second
#define pii pair <int, int>
#define tii tuple <int, int, int>
using namespace std;
struct node
{
int cnt;
bool lazy;
node *l, *r;
node(int cnt = 0, bool lazy = 0) : cnt(cnt), lazy(lazy)
{
l = r = nullptr;
}
};
#define check(x) if (x == nullptr) x = new node();
void down(node *root, int l, int r)
{
if (root == nullptr) return;
if (root -> lazy)
{
root -> cnt = r - l + 1;
if (l != r)
{
check(root -> l);
root -> l -> lazy = 1;
check(root -> r);
root -> r -> lazy = 1;
}
root -> lazy = 0;
}
}
void update(node *root, int l, int r, int u, int v)
{
down(root, l, r);
if (l > v || r < u) return;
if (l >= u && r <= v)
{
root -> lazy = 1;
down(root, l, r);
return;
}
int mid = l + r >> 1;
check(root -> l);
check(root -> r);
update(root -> l, l, mid, u, v);
update(root -> r, mid + 1, r, u, v);
root -> cnt = (root -> l -> cnt) + (root -> r -> cnt);
}
int query(node *root, int l, int r, int u, int v)
{
if (root == nullptr) return 0;
if (l > v || r < u) return 0;
down(root, l, r);
if (l >= u && r <= v)
return root -> cnt;
int mid = l + r >> 1;
int res = 0;
if (u <= mid) res += query(root -> l, l, mid, u, v);
if (mid <= v) res += query(root -> r, mid + 1, r, u, v);
return res;
}
node *root = new node();
int t;
int main()
{
if (ifstream(task".inp")) nx
fast
cin >> t;
int c = 0;
while(t--)
{
int type, l, r;
cin >> type >> l >> r;
l += c, r += c;
if (type == 1)
{
c = query(root, 1, 1e9, l, r);
cout << c << '\n';
}
else update(root, 1, 1e9, l, r);
}
}
Compilation message
apple.cpp: In function 'void update(node*, int, int, int, int)':
apple.cpp:50:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
50 | int mid = l + r >> 1;
| ~~^~~
apple.cpp: In function 'int query(node*, int, int, int, int)':
apple.cpp:64:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
64 | int mid = l + r >> 1;
| ~~^~~
apple.cpp: In function 'int main()':
apple.cpp:7:20: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
7 | #define nx freopen (task".inp","r",stdin), freopen (task".out","w",stdout);
| ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
apple.cpp:74:31: note: in expansion of macro 'nx'
74 | if (ifstream(task".inp")) nx
| ^~
apple.cpp:7:52: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
7 | #define nx freopen (task".inp","r",stdin), freopen (task".out","w",stdout);
| ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
apple.cpp:74:31: note: in expansion of macro 'nx'
74 | if (ifstream(task".inp")) nx
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
11 ms |
5308 KB |
Output is correct |
5 |
Correct |
14 ms |
6492 KB |
Output is correct |
6 |
Correct |
14 ms |
6192 KB |
Output is correct |
7 |
Correct |
13 ms |
6492 KB |
Output is correct |
8 |
Correct |
119 ms |
47140 KB |
Output is correct |
9 |
Correct |
254 ms |
80612 KB |
Output is correct |
10 |
Correct |
252 ms |
89944 KB |
Output is correct |
11 |
Correct |
273 ms |
97092 KB |
Output is correct |
12 |
Correct |
275 ms |
100512 KB |
Output is correct |
13 |
Correct |
242 ms |
122448 KB |
Output is correct |
14 |
Correct |
252 ms |
123968 KB |
Output is correct |
15 |
Correct |
404 ms |
225032 KB |
Output is correct |
16 |
Correct |
412 ms |
226444 KB |
Output is correct |
17 |
Correct |
249 ms |
128128 KB |
Output is correct |
18 |
Correct |
242 ms |
128340 KB |
Output is correct |
19 |
Correct |
405 ms |
232080 KB |
Output is correct |
20 |
Correct |
426 ms |
232196 KB |
Output is correct |