#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#define pb push_back
#define int long long
#define str string
using namespace std;
const int M = 1e9 + 7;
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n, a, b;
cin >> n >> a >> b;
vector<pair<int, int>> pr(n);
for (int i = 0; i < n; i++) cin >> pr[i].first >> pr[i].second;
int g = gcd(a, b + 1);
a /= g;
__int128_t num = a * b;
if (n == 1) {
int l = pr[0].first, r = pr[0].second;
if (r - l >= num - 1) {
cout << (int) num;
} else {
if (l == r) {
cout << 1;
} else {
l %= num;
r %= num;
if (l < r) {
cout << r - l + 1;
} else {
cout << (r + 1) + (int) num - l;
}
}
}
return 0;
}
vector<pair<__int128_t, int>> ev;
for (auto p : pr) {
int l = p.first, r = p.second;
if (r - l >= num - 1) {
cout << (int) num;
return 0;
}
l %= num;
r %= num;
if (r < l) {
ev.pb({l, 1});
ev.pb({num, -1});
ev.pb({0, 1});
ev.pb({r + 1, -1});
} else {
ev.pb({l, 1});
ev.pb({r + 1, -1});
}
}
sort(ev.begin(), ev.end());
int bal = 0;
__int128_t last = 0;
int ans = 0;
for (auto p : ev) {
__int128_t x = p.first;
int type = p.second;
if (bal) {
ans += (x - last);
}
last = x;
bal += type;
}
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
12 ms |
1916 KB |
Output is correct |
3 |
Correct |
12 ms |
1916 KB |
Output is correct |
4 |
Correct |
6 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
4 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
11 ms |
1916 KB |
Output is correct |
17 |
Correct |
90 ms |
11368 KB |
Output is correct |
18 |
Incorrect |
4 ms |
384 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Incorrect |
4 ms |
384 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
512 KB |
Output is correct |
3 |
Correct |
5 ms |
512 KB |
Output is correct |
4 |
Correct |
5 ms |
512 KB |
Output is correct |
5 |
Correct |
510 ms |
82288 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
737 ms |
82668 KB |
Output is correct |
3 |
Correct |
779 ms |
82592 KB |
Output is correct |
4 |
Correct |
752 ms |
82592 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
737 ms |
82668 KB |
Output is correct |
3 |
Correct |
779 ms |
82592 KB |
Output is correct |
4 |
Correct |
752 ms |
82592 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
762 ms |
82624 KB |
Output is correct |
7 |
Correct |
711 ms |
82584 KB |
Output is correct |
8 |
Correct |
733 ms |
82624 KB |
Output is correct |
9 |
Correct |
931 ms |
82524 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
737 ms |
82668 KB |
Output is correct |
3 |
Correct |
779 ms |
82592 KB |
Output is correct |
4 |
Correct |
752 ms |
82592 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
71 ms |
10984 KB |
Output is correct |
7 |
Correct |
76 ms |
10984 KB |
Output is correct |
8 |
Correct |
77 ms |
10984 KB |
Output is correct |
9 |
Correct |
77 ms |
10984 KB |
Output is correct |
10 |
Correct |
76 ms |
10984 KB |
Output is correct |
11 |
Correct |
76 ms |
10984 KB |
Output is correct |
12 |
Correct |
70 ms |
10984 KB |
Output is correct |
13 |
Correct |
83 ms |
10968 KB |
Output is correct |
14 |
Correct |
72 ms |
10984 KB |
Output is correct |
15 |
Correct |
89 ms |
10984 KB |
Output is correct |
16 |
Correct |
79 ms |
10984 KB |
Output is correct |
17 |
Correct |
75 ms |
10984 KB |
Output is correct |
18 |
Correct |
762 ms |
82612 KB |
Output is correct |
19 |
Correct |
717 ms |
82624 KB |
Output is correct |
20 |
Correct |
925 ms |
82564 KB |
Output is correct |
21 |
Correct |
86 ms |
10984 KB |
Output is correct |
22 |
Correct |
73 ms |
10988 KB |
Output is correct |
23 |
Correct |
212 ms |
39264 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
81 ms |
10984 KB |
Output is correct |
3 |
Correct |
84 ms |
10984 KB |
Output is correct |
4 |
Correct |
965 ms |
82592 KB |
Output is correct |
5 |
Correct |
84 ms |
10856 KB |
Output is correct |
6 |
Correct |
83 ms |
10856 KB |
Output is correct |
7 |
Correct |
80 ms |
10856 KB |
Output is correct |
8 |
Correct |
90 ms |
10984 KB |
Output is correct |
9 |
Correct |
77 ms |
10856 KB |
Output is correct |
10 |
Correct |
91 ms |
10856 KB |
Output is correct |
11 |
Correct |
80 ms |
10856 KB |
Output is correct |
12 |
Correct |
74 ms |
10856 KB |
Output is correct |
13 |
Correct |
84 ms |
10856 KB |
Output is correct |
14 |
Correct |
890 ms |
82356 KB |
Output is correct |
15 |
Correct |
87 ms |
10728 KB |
Output is correct |
16 |
Correct |
709 ms |
82416 KB |
Output is correct |
17 |
Correct |
752 ms |
82420 KB |
Output is correct |
18 |
Incorrect |
4 ms |
384 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
12 ms |
1916 KB |
Output is correct |
3 |
Correct |
12 ms |
1916 KB |
Output is correct |
4 |
Correct |
6 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
4 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
11 ms |
1916 KB |
Output is correct |
17 |
Correct |
90 ms |
11368 KB |
Output is correct |
18 |
Incorrect |
4 ms |
384 KB |
Output isn't correct |