#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
constexpr bool typetest = 0;
constexpr int N = 1e6 + 5;
constexpr ll Inf = 1e18 + 7;
int n;
ll A, B;
vector<pair<ll, ll>> s;
void Read()
{
cin >> n >> A >> B;
// A * B / gcd(A, B + 1)
A /= __gcd(A, B + 1);
if (A <= Inf / B)
A *= B;
else
A = Inf;
for (int i = 1; i <= n; ++i)
{
ll l, r;
cin >> l >> r;
if (r - l + 1 >= A)
tie(l, r) = make_tuple(0, A - 1);
else
{
l %= A;
r %= A;
}
if (l <= r)
s.emplace_back(l, r);
else
{
s.emplace_back(l, A - 1);
s.emplace_back(0, r);
}
}
}
void Solve()
{
sort(s.begin(), s.end());
ll leftest(0);
ll ans(0);
for (auto i : s)
{
leftest = max(leftest, i.first);
ans += max(0ll, i.second - leftest + 1);
leftest = max(leftest, i.second + 1);
}
cout << ans;
}
int32_t main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t(1);
if (typetest)
cin >> t;
for (int _ = 1; _ <= t; ++_)
{
Read();
Solve();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
5 ms |
976 KB |
Output is correct |
3 |
Correct |
6 ms |
976 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
304 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
6 ms |
976 KB |
Output is correct |
17 |
Correct |
55 ms |
5696 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
316 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
324 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
359 ms |
41304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
534 ms |
53232 KB |
Output is correct |
3 |
Correct |
536 ms |
53180 KB |
Output is correct |
4 |
Correct |
517 ms |
53272 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
534 ms |
53232 KB |
Output is correct |
3 |
Correct |
536 ms |
53180 KB |
Output is correct |
4 |
Correct |
517 ms |
53272 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
510 ms |
53272 KB |
Output is correct |
7 |
Correct |
496 ms |
53264 KB |
Output is correct |
8 |
Correct |
492 ms |
53216 KB |
Output is correct |
9 |
Correct |
557 ms |
53296 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
534 ms |
53232 KB |
Output is correct |
3 |
Correct |
536 ms |
53180 KB |
Output is correct |
4 |
Correct |
517 ms |
53272 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
50 ms |
5692 KB |
Output is correct |
7 |
Correct |
51 ms |
5644 KB |
Output is correct |
8 |
Correct |
51 ms |
5684 KB |
Output is correct |
9 |
Correct |
51 ms |
5692 KB |
Output is correct |
10 |
Correct |
50 ms |
5716 KB |
Output is correct |
11 |
Correct |
52 ms |
5668 KB |
Output is correct |
12 |
Correct |
47 ms |
5644 KB |
Output is correct |
13 |
Correct |
51 ms |
5640 KB |
Output is correct |
14 |
Correct |
47 ms |
5688 KB |
Output is correct |
15 |
Correct |
54 ms |
5664 KB |
Output is correct |
16 |
Correct |
54 ms |
5664 KB |
Output is correct |
17 |
Correct |
50 ms |
5680 KB |
Output is correct |
18 |
Correct |
515 ms |
53280 KB |
Output is correct |
19 |
Correct |
493 ms |
53336 KB |
Output is correct |
20 |
Correct |
548 ms |
53264 KB |
Output is correct |
21 |
Correct |
53 ms |
5688 KB |
Output is correct |
22 |
Correct |
46 ms |
5672 KB |
Output is correct |
23 |
Correct |
153 ms |
18408 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
52 ms |
5692 KB |
Output is correct |
3 |
Correct |
56 ms |
5772 KB |
Output is correct |
4 |
Correct |
589 ms |
53192 KB |
Output is correct |
5 |
Correct |
52 ms |
5688 KB |
Output is correct |
6 |
Correct |
51 ms |
5664 KB |
Output is correct |
7 |
Correct |
52 ms |
5740 KB |
Output is correct |
8 |
Correct |
54 ms |
5600 KB |
Output is correct |
9 |
Correct |
52 ms |
5684 KB |
Output is correct |
10 |
Correct |
54 ms |
5728 KB |
Output is correct |
11 |
Correct |
53 ms |
5608 KB |
Output is correct |
12 |
Correct |
46 ms |
5704 KB |
Output is correct |
13 |
Correct |
53 ms |
5648 KB |
Output is correct |
14 |
Correct |
547 ms |
53264 KB |
Output is correct |
15 |
Correct |
52 ms |
5632 KB |
Output is correct |
16 |
Correct |
500 ms |
53416 KB |
Output is correct |
17 |
Correct |
489 ms |
53220 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
5 ms |
976 KB |
Output is correct |
3 |
Correct |
6 ms |
976 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
304 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
6 ms |
976 KB |
Output is correct |
17 |
Correct |
55 ms |
5696 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
316 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
0 ms |
204 KB |
Output is correct |
23 |
Correct |
0 ms |
204 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
324 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
359 ms |
41304 KB |
Output is correct |
29 |
Correct |
1 ms |
204 KB |
Output is correct |
30 |
Correct |
534 ms |
53232 KB |
Output is correct |
31 |
Correct |
536 ms |
53180 KB |
Output is correct |
32 |
Correct |
517 ms |
53272 KB |
Output is correct |
33 |
Correct |
1 ms |
204 KB |
Output is correct |
34 |
Correct |
510 ms |
53272 KB |
Output is correct |
35 |
Correct |
496 ms |
53264 KB |
Output is correct |
36 |
Correct |
492 ms |
53216 KB |
Output is correct |
37 |
Correct |
557 ms |
53296 KB |
Output is correct |
38 |
Correct |
1 ms |
204 KB |
Output is correct |
39 |
Correct |
50 ms |
5692 KB |
Output is correct |
40 |
Correct |
51 ms |
5644 KB |
Output is correct |
41 |
Correct |
51 ms |
5684 KB |
Output is correct |
42 |
Correct |
51 ms |
5692 KB |
Output is correct |
43 |
Correct |
50 ms |
5716 KB |
Output is correct |
44 |
Correct |
52 ms |
5668 KB |
Output is correct |
45 |
Correct |
47 ms |
5644 KB |
Output is correct |
46 |
Correct |
51 ms |
5640 KB |
Output is correct |
47 |
Correct |
47 ms |
5688 KB |
Output is correct |
48 |
Correct |
54 ms |
5664 KB |
Output is correct |
49 |
Correct |
54 ms |
5664 KB |
Output is correct |
50 |
Correct |
50 ms |
5680 KB |
Output is correct |
51 |
Correct |
515 ms |
53280 KB |
Output is correct |
52 |
Correct |
493 ms |
53336 KB |
Output is correct |
53 |
Correct |
548 ms |
53264 KB |
Output is correct |
54 |
Correct |
53 ms |
5688 KB |
Output is correct |
55 |
Correct |
46 ms |
5672 KB |
Output is correct |
56 |
Correct |
153 ms |
18408 KB |
Output is correct |
57 |
Correct |
1 ms |
204 KB |
Output is correct |
58 |
Correct |
52 ms |
5692 KB |
Output is correct |
59 |
Correct |
56 ms |
5772 KB |
Output is correct |
60 |
Correct |
589 ms |
53192 KB |
Output is correct |
61 |
Correct |
52 ms |
5688 KB |
Output is correct |
62 |
Correct |
51 ms |
5664 KB |
Output is correct |
63 |
Correct |
52 ms |
5740 KB |
Output is correct |
64 |
Correct |
54 ms |
5600 KB |
Output is correct |
65 |
Correct |
52 ms |
5684 KB |
Output is correct |
66 |
Correct |
54 ms |
5728 KB |
Output is correct |
67 |
Correct |
53 ms |
5608 KB |
Output is correct |
68 |
Correct |
46 ms |
5704 KB |
Output is correct |
69 |
Correct |
53 ms |
5648 KB |
Output is correct |
70 |
Correct |
547 ms |
53264 KB |
Output is correct |
71 |
Correct |
52 ms |
5632 KB |
Output is correct |
72 |
Correct |
500 ms |
53416 KB |
Output is correct |
73 |
Correct |
489 ms |
53220 KB |
Output is correct |
74 |
Correct |
1 ms |
204 KB |
Output is correct |
75 |
Correct |
0 ms |
204 KB |
Output is correct |
76 |
Correct |
1 ms |
204 KB |
Output is correct |
77 |
Correct |
0 ms |
204 KB |
Output is correct |
78 |
Correct |
1 ms |
204 KB |
Output is correct |
79 |
Correct |
6 ms |
976 KB |
Output is correct |
80 |
Correct |
574 ms |
53264 KB |
Output is correct |
81 |
Correct |
573 ms |
53192 KB |
Output is correct |
82 |
Correct |
548 ms |
53308 KB |
Output is correct |
83 |
Correct |
548 ms |
53340 KB |
Output is correct |
84 |
Correct |
543 ms |
53228 KB |
Output is correct |
85 |
Correct |
529 ms |
53264 KB |
Output is correct |
86 |
Correct |
152 ms |
18400 KB |
Output is correct |
87 |
Correct |
1 ms |
204 KB |
Output is correct |