#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> pii;
#define ff first
#define ss second
#define MP make_pair
int gcd(int a, int b) {
if(a == 0) return b;
if(b == 0) return a;
return gcd(b % a, a);
}
struct tree {
bool lazy;
int tl, tr;
tree *lc, *rc;
int sum;
tree(int l, int r) {
tl = l, tr = r;
lazy = sum = 0;
lc = rc = NULL;
}
void birth() {
if(tl == tr) return;
if(lc != NULL) return;
lc = new tree(tl, (tl + tr) / 2);
rc = new tree((tl + tr) / 2 + 1, tr);
}
void upt(int l, int r) {
if(lazy) return;
// cout << tl << ' ' << tr << ": " << l << ' ' << r << endl;
if(tl == l && r == tr) {
sum = r - l + 1;
lazy = 1;
return;
}
birth();
int tm = (tl + tr) / 2;
if(r <= tm) lc->upt(l, r);
else if(tm < l) rc->upt(l, r);
else {
lc->upt(l, tm);
rc->upt(tm + 1, r);
}
sum = lc->sum + rc->sum;
if(lc->lazy && rc->lazy)
lazy = 1;
}
};
signed main() {
int a, b, n;
cin >> n >> a >> b;
int t = a / gcd(a, b + 1) * b;
tree *root = new tree(0, t - 1);
// cout << "sda = " << t << endl;
int l, r; bool gay = false;
for(int i = 0; i < n; i++) {
cin >> l >> r;
if(r - l + 1 >= t) {
gay = 1;
continue;
}
l %= t;
r %= t;
if(l <= r) root->upt(l, r);
else {
root->upt(l, t - 1);
root->upt(0, r);
}
}
cout << ((gay) ? t : root->sum) << endl;
return 0;
}
Compilation message
strange_device.cpp: In constructor 'tree::tree(long long int, long long int)':
strange_device.cpp:24:14: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
24 | lazy = sum = 0;
| ~~~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
14 ms |
5468 KB |
Output is correct |
3 |
Correct |
16 ms |
6492 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
14 ms |
4700 KB |
Output is correct |
17 |
Correct |
109 ms |
13392 KB |
Output is correct |
18 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
1528 KB |
Output is correct |
3 |
Correct |
2 ms |
1624 KB |
Output is correct |
4 |
Correct |
2 ms |
1628 KB |
Output is correct |
5 |
Correct |
753 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1128 ms |
125600 KB |
Output is correct |
3 |
Runtime error |
861 ms |
524288 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1128 ms |
125600 KB |
Output is correct |
3 |
Runtime error |
861 ms |
524288 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1128 ms |
125600 KB |
Output is correct |
3 |
Runtime error |
861 ms |
524288 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
178 ms |
83644 KB |
Output is correct |
3 |
Correct |
267 ms |
197240 KB |
Output is correct |
4 |
Runtime error |
659 ms |
524288 KB |
Execution killed with signal 9 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
14 ms |
5468 KB |
Output is correct |
3 |
Correct |
16 ms |
6492 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
14 ms |
4700 KB |
Output is correct |
17 |
Correct |
109 ms |
13392 KB |
Output is correct |
18 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |