#include <bits/stdc++.h>
#define fast cin.tie(0)->sync_with_stdio(0);
#define int long long
#define inf ((int)1e18)
using namespace std;
const int C = inf * 2;
struct segtree {
int n;
struct node {
int sum, l, r;
bool set;
node(): sum(0), l(0), r(0), set(false) {}
};
vector <node> t;
int newnode() {
t.push_back(node());
return t.size() - 1;
}
void init(int size) {
n = size;
newnode();
}
void set(int l, int r) {
return update(0, 0, n - 1, l, r);
}
void update(int v, int l, int r, int ul, int ur) {
if(l >= ul and r <= ur) {
t[v].sum = (r - l + 1);
t[v].set = 1;
return;
}
if(t[v].set) return;
if(!t[v].l) {
t[v].l = newnode();
t[v].r = newnode();
}
int m = (l + r) / 2;
if(ul <= m) update(t[v].l, l, m, ul, ur);
if(ur > m) update(t[v].r, m + 1, r, ul, ur);
t[v].sum = t[t[v].l].sum + t[t[v].r].sum;
}
}t;
int32_t main(){
fast
int n, a, b;
cin >> n >> a >> b;
__int128__ g = gcd(a, b + 1);
__int128__ mult = a * (b + 1);
if(mult / g > C) {
int sum = 0;
for(int i = 0; i < n; i++) {
int l, r;
cin >> l >> r;
sum += r - l + 1;
}
cout << sum;
return 0;
}
int tekrar = mult / g / (b + 1) * b;
t.init(tekrar);
for(int i = 0; i < n; i++) {
int l, r;
cin >> l >> r;
if(r - l + 1 >= tekrar) {
cout << tekrar;
return 0;
}
int ll = l % tekrar, rr = r % tekrar;
if(ll <= rr) {
t.set(ll, rr);
// cout << ll << " " << rr << "\n";
}
else {
// cout << 0 << " " << rr << "\n";
t.set(0, rr);
// cout << ll << " " << tekrar - 1 << "\n\n";
t.set(ll, tekrar - 1);
}
}
cout << t.t[0].sum;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
6 ms |
5332 KB |
Output is correct |
3 |
Correct |
7 ms |
4820 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
6 ms |
5844 KB |
Output is correct |
17 |
Correct |
37 ms |
9616 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 |
0 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 |
1 ms |
1500 KB |
Output is correct |
3 |
Correct |
1 ms |
1500 KB |
Output is correct |
4 |
Correct |
2 ms |
1500 KB |
Output is correct |
5 |
Correct |
361 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
389 ms |
68112 KB |
Output is correct |
3 |
Runtime error |
327 ms |
524288 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
389 ms |
68112 KB |
Output is correct |
3 |
Runtime error |
327 ms |
524288 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
389 ms |
68112 KB |
Output is correct |
3 |
Runtime error |
327 ms |
524288 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
77 ms |
67664 KB |
Output is correct |
3 |
Correct |
118 ms |
131672 KB |
Output is correct |
4 |
Runtime error |
330 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 |
6 ms |
5332 KB |
Output is correct |
3 |
Correct |
7 ms |
4820 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
6 ms |
5844 KB |
Output is correct |
17 |
Correct |
37 ms |
9616 KB |
Output is correct |
18 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |