#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;
if (a >= (1e18+8800)/b) {
int ans = 0;
for (auto p : pr) {
ans += p.second - p.first+1;
}
cout << ans;
return 0;
}
int num = a * b;
vector<pair<int, int>> ev;
for (auto p : pr) {
int l = p.first, r = p.second;
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;
int last = 0;
int ans = 0;
for (auto p : ev) {
int x = p.first, type = p.second;
if (bal) {
ans += (x - last);
}
last = x;
bal += type;
}
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
11 ms |
1656 KB |
Output is correct |
3 |
Correct |
11 ms |
1536 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
4 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 |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
16 |
Correct |
11 ms |
1536 KB |
Output is correct |
17 |
Correct |
76 ms |
7660 KB |
Output is correct |
18 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
512 KB |
Output is correct |
4 |
Correct |
6 ms |
512 KB |
Output is correct |
5 |
Correct |
452 ms |
49752 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
658 ms |
49748 KB |
Output is correct |
3 |
Correct |
707 ms |
49732 KB |
Output is correct |
4 |
Correct |
646 ms |
49884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
658 ms |
49748 KB |
Output is correct |
3 |
Correct |
707 ms |
49732 KB |
Output is correct |
4 |
Correct |
646 ms |
49884 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
651 ms |
49980 KB |
Output is correct |
7 |
Correct |
638 ms |
49920 KB |
Output is correct |
8 |
Correct |
642 ms |
49748 KB |
Output is correct |
9 |
Correct |
734 ms |
49896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
658 ms |
49748 KB |
Output is correct |
3 |
Correct |
707 ms |
49732 KB |
Output is correct |
4 |
Correct |
646 ms |
49884 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
66 ms |
6892 KB |
Output is correct |
7 |
Correct |
68 ms |
6896 KB |
Output is correct |
8 |
Correct |
66 ms |
6892 KB |
Output is correct |
9 |
Correct |
65 ms |
6896 KB |
Output is correct |
10 |
Correct |
63 ms |
7020 KB |
Output is correct |
11 |
Correct |
67 ms |
6892 KB |
Output is correct |
12 |
Correct |
65 ms |
6892 KB |
Output is correct |
13 |
Correct |
72 ms |
6892 KB |
Output is correct |
14 |
Correct |
66 ms |
6892 KB |
Output is correct |
15 |
Correct |
76 ms |
6892 KB |
Output is correct |
16 |
Correct |
90 ms |
6892 KB |
Output is correct |
17 |
Correct |
64 ms |
6944 KB |
Output is correct |
18 |
Correct |
655 ms |
49736 KB |
Output is correct |
19 |
Correct |
604 ms |
49748 KB |
Output is correct |
20 |
Correct |
772 ms |
49704 KB |
Output is correct |
21 |
Correct |
76 ms |
6764 KB |
Output is correct |
22 |
Correct |
62 ms |
6764 KB |
Output is correct |
23 |
Correct |
189 ms |
22756 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
70 ms |
6764 KB |
Output is correct |
3 |
Correct |
70 ms |
6764 KB |
Output is correct |
4 |
Correct |
794 ms |
49620 KB |
Output is correct |
5 |
Correct |
73 ms |
6636 KB |
Output is correct |
6 |
Correct |
76 ms |
6764 KB |
Output is correct |
7 |
Correct |
80 ms |
6720 KB |
Output is correct |
8 |
Correct |
74 ms |
6636 KB |
Output is correct |
9 |
Correct |
71 ms |
6644 KB |
Output is correct |
10 |
Correct |
73 ms |
6636 KB |
Output is correct |
11 |
Correct |
72 ms |
6636 KB |
Output is correct |
12 |
Correct |
73 ms |
6692 KB |
Output is correct |
13 |
Correct |
75 ms |
6636 KB |
Output is correct |
14 |
Correct |
730 ms |
49360 KB |
Output is correct |
15 |
Correct |
73 ms |
6380 KB |
Output is correct |
16 |
Correct |
616 ms |
49248 KB |
Output is correct |
17 |
Correct |
634 ms |
49368 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
11 ms |
1656 KB |
Output is correct |
3 |
Correct |
11 ms |
1536 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
4 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 |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
16 |
Correct |
11 ms |
1536 KB |
Output is correct |
17 |
Correct |
76 ms |
7660 KB |
Output is correct |
18 |
Correct |
4 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |