#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define TASK ""
#define bit(x) (1LL << (x))
#define getbit(x, i) (((x) >> (i)) & 1)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
template <typename T1, typename T2> bool mini(T1 &a, T2 b) {
if (a > b) {a = b; return true;} return false;
}
template <typename T1, typename T2> bool maxi(T1 &a, T2 b) {
if (a < b) {a = b; return true;} return false;
}
mt19937_64 rd(chrono::steady_clock::now().time_since_epoch().count());
int rand(int l, int r) {
return l + rd() % (r - l + 1);
}
const int N = 1e5 + 5;
const int oo = 1e9;
const long long ooo = 1e18;
const int mod = 1e9 + 7; // 998244353;
const long double pi = acos(-1);
long long lcm(long long a, long long b) {
long long res = a / __gcd(a, b);
if (res > 2 * ooo / b)
return 2 * ooo;
return res * b;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
#ifdef ONLINE_JUDGE
// freopen(TASK".inp","r",stdin);
// freopen(TASK".out","w",stdout);
#endif
long long n, A, B;
cin >> n >> A >> B;
long long x = __gcd(A, B + 1);
long long y = B;
A /= x;
if (A > 2 * ooo / y)
A = 2 * ooo;
else
A *= y;
long long len = lcm(A, B);
vector <pair <long long, int>> events;
for (int i = 1; i <= n; i++) {
long long l, r;
cin >> l >> r;
if (r - l + 1 >= len)
return cout << len, 0;
events.push_back(mp(l % len, 1));
events.push_back(mp(r % len + 1, -1));
if (l % len > r % len) {
events.push_back(mp(0, 1));
events.push_back(mp(len, -1));
}
}
sort(ALL(events));
long long ans = 0;
long long pre = 0;
int cnt = 0;
for (pair <long long, int> pir : events) {
if (cnt > 0)
ans += pir.fi - pre;
// cerr << pre << " " << pir.fi << "\n";
cnt += pir.se;
pre = pir.fi;
}
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
5 ms |
984 KB |
Output is correct |
3 |
Correct |
6 ms |
1300 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
328 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
324 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
324 KB |
Output is correct |
16 |
Correct |
5 ms |
1240 KB |
Output is correct |
17 |
Correct |
59 ms |
7248 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
344 ms |
33172 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
472 ms |
33240 KB |
Output is correct |
3 |
Correct |
494 ms |
33188 KB |
Output is correct |
4 |
Correct |
456 ms |
33232 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
472 ms |
33240 KB |
Output is correct |
3 |
Correct |
494 ms |
33188 KB |
Output is correct |
4 |
Correct |
456 ms |
33232 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
482 ms |
33336 KB |
Output is correct |
7 |
Correct |
494 ms |
33188 KB |
Output is correct |
8 |
Correct |
477 ms |
33184 KB |
Output is correct |
9 |
Correct |
557 ms |
33256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
472 ms |
33240 KB |
Output is correct |
3 |
Correct |
494 ms |
33188 KB |
Output is correct |
4 |
Correct |
456 ms |
33232 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
47 ms |
4512 KB |
Output is correct |
7 |
Correct |
48 ms |
4508 KB |
Output is correct |
8 |
Correct |
44 ms |
4508 KB |
Output is correct |
9 |
Correct |
45 ms |
4556 KB |
Output is correct |
10 |
Correct |
43 ms |
4468 KB |
Output is correct |
11 |
Correct |
47 ms |
4484 KB |
Output is correct |
12 |
Correct |
48 ms |
7220 KB |
Output is correct |
13 |
Correct |
56 ms |
7216 KB |
Output is correct |
14 |
Correct |
51 ms |
7236 KB |
Output is correct |
15 |
Correct |
56 ms |
7224 KB |
Output is correct |
16 |
Correct |
54 ms |
7260 KB |
Output is correct |
17 |
Correct |
48 ms |
7220 KB |
Output is correct |
18 |
Correct |
524 ms |
68880 KB |
Output is correct |
19 |
Correct |
491 ms |
61708 KB |
Output is correct |
20 |
Correct |
620 ms |
61240 KB |
Output is correct |
21 |
Correct |
55 ms |
7240 KB |
Output is correct |
22 |
Correct |
42 ms |
7232 KB |
Output is correct |
23 |
Correct |
145 ms |
26680 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
52 ms |
4488 KB |
Output is correct |
3 |
Correct |
54 ms |
4556 KB |
Output is correct |
4 |
Correct |
607 ms |
33192 KB |
Output is correct |
5 |
Correct |
50 ms |
4556 KB |
Output is correct |
6 |
Correct |
51 ms |
4556 KB |
Output is correct |
7 |
Correct |
52 ms |
4512 KB |
Output is correct |
8 |
Correct |
54 ms |
4532 KB |
Output is correct |
9 |
Correct |
49 ms |
4556 KB |
Output is correct |
10 |
Correct |
55 ms |
4564 KB |
Output is correct |
11 |
Correct |
50 ms |
4476 KB |
Output is correct |
12 |
Correct |
44 ms |
4564 KB |
Output is correct |
13 |
Correct |
52 ms |
4528 KB |
Output is correct |
14 |
Correct |
563 ms |
33184 KB |
Output is correct |
15 |
Correct |
54 ms |
4456 KB |
Output is correct |
16 |
Correct |
439 ms |
33256 KB |
Output is correct |
17 |
Correct |
471 ms |
33312 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
5 ms |
984 KB |
Output is correct |
3 |
Correct |
6 ms |
1300 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
328 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
324 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
324 KB |
Output is correct |
16 |
Correct |
5 ms |
1240 KB |
Output is correct |
17 |
Correct |
59 ms |
7248 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
0 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
344 ms |
33172 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
472 ms |
33240 KB |
Output is correct |
31 |
Correct |
494 ms |
33188 KB |
Output is correct |
32 |
Correct |
456 ms |
33232 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
482 ms |
33336 KB |
Output is correct |
35 |
Correct |
494 ms |
33188 KB |
Output is correct |
36 |
Correct |
477 ms |
33184 KB |
Output is correct |
37 |
Correct |
557 ms |
33256 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
47 ms |
4512 KB |
Output is correct |
40 |
Correct |
48 ms |
4508 KB |
Output is correct |
41 |
Correct |
44 ms |
4508 KB |
Output is correct |
42 |
Correct |
45 ms |
4556 KB |
Output is correct |
43 |
Correct |
43 ms |
4468 KB |
Output is correct |
44 |
Correct |
47 ms |
4484 KB |
Output is correct |
45 |
Correct |
48 ms |
7220 KB |
Output is correct |
46 |
Correct |
56 ms |
7216 KB |
Output is correct |
47 |
Correct |
51 ms |
7236 KB |
Output is correct |
48 |
Correct |
56 ms |
7224 KB |
Output is correct |
49 |
Correct |
54 ms |
7260 KB |
Output is correct |
50 |
Correct |
48 ms |
7220 KB |
Output is correct |
51 |
Correct |
524 ms |
68880 KB |
Output is correct |
52 |
Correct |
491 ms |
61708 KB |
Output is correct |
53 |
Correct |
620 ms |
61240 KB |
Output is correct |
54 |
Correct |
55 ms |
7240 KB |
Output is correct |
55 |
Correct |
42 ms |
7232 KB |
Output is correct |
56 |
Correct |
145 ms |
26680 KB |
Output is correct |
57 |
Correct |
0 ms |
212 KB |
Output is correct |
58 |
Correct |
52 ms |
4488 KB |
Output is correct |
59 |
Correct |
54 ms |
4556 KB |
Output is correct |
60 |
Correct |
607 ms |
33192 KB |
Output is correct |
61 |
Correct |
50 ms |
4556 KB |
Output is correct |
62 |
Correct |
51 ms |
4556 KB |
Output is correct |
63 |
Correct |
52 ms |
4512 KB |
Output is correct |
64 |
Correct |
54 ms |
4532 KB |
Output is correct |
65 |
Correct |
49 ms |
4556 KB |
Output is correct |
66 |
Correct |
55 ms |
4564 KB |
Output is correct |
67 |
Correct |
50 ms |
4476 KB |
Output is correct |
68 |
Correct |
44 ms |
4564 KB |
Output is correct |
69 |
Correct |
52 ms |
4528 KB |
Output is correct |
70 |
Correct |
563 ms |
33184 KB |
Output is correct |
71 |
Correct |
54 ms |
4456 KB |
Output is correct |
72 |
Correct |
439 ms |
33256 KB |
Output is correct |
73 |
Correct |
471 ms |
33312 KB |
Output is correct |
74 |
Correct |
1 ms |
212 KB |
Output is correct |
75 |
Correct |
0 ms |
324 KB |
Output is correct |
76 |
Correct |
1 ms |
212 KB |
Output is correct |
77 |
Correct |
1 ms |
212 KB |
Output is correct |
78 |
Correct |
1 ms |
324 KB |
Output is correct |
79 |
Correct |
6 ms |
1240 KB |
Output is correct |
80 |
Correct |
632 ms |
68212 KB |
Output is correct |
81 |
Correct |
639 ms |
68244 KB |
Output is correct |
82 |
Correct |
603 ms |
68112 KB |
Output is correct |
83 |
Correct |
594 ms |
68944 KB |
Output is correct |
84 |
Correct |
590 ms |
68836 KB |
Output is correct |
85 |
Correct |
600 ms |
68892 KB |
Output is correct |
86 |
Correct |
141 ms |
26716 KB |
Output is correct |
87 |
Correct |
1 ms |
212 KB |
Output is correct |