#include <bits/stdc++.h>
#define SZ(v) ((int)(v).size())
using namespace std;
using ll = long long;
template<typename... Args>
void read(Args&... args)
{
((cin >> args), ...);
}
template<typename T>
void read(vector<T> &vec)
{
for (auto &v : vec) read(v);
}
void write() {}
template<typename H, typename... T>
void write(const H &h, const T&... t)
{
cout << h;
if (sizeof...(t)) {cout << ' '; write(t...);}
}
template<typename T>
void write(const vector<T> &vec)
{
if (SZ(vec) == 0) return;
write(vec[0]);
for (int i(1); i < SZ(vec); ++i)
{cout << ' '; write(vec[i]);}
}
template<typename... Args>
void writeln(Args... args)
{
write(args...); cout << '\n';
}
void show(__int128 x)
{
if (x >= 10)
show(x/10);
cout << int(x%10);
}
int main(void)
{
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int n;
ll _A, _B;
using T = __int128;
read(n, _A, _B);
T A(_A), B(_B);
T mod = (A * B) / gcd(_A, _B+1);
vector<pair<T, T>> intervals;
for (int i(0); i < n; ++i)
{
ll _l, _r;
read(_l, _r);
T l(_l), r(_r);
l %= mod, r %= mod;
if (_r-_l+1 >= mod)
intervals.emplace_back(0, mod-1);
else if (l > r)
{
intervals.emplace_back(l, mod-1);
intervals.emplace_back(0, r);
}
else
intervals.emplace_back(l, r);
}
sort(intervals.begin(), intervals.end());
T lst(-1);
T sol(0);
for (auto [l, r] : intervals)
{
sol += max(T(0), r - max(l, lst+1) + 1);
lst = max(lst, r);
}
show(sol);
cout << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
6 ms |
1392 KB |
Output is correct |
3 |
Correct |
6 ms |
1392 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
6 ms |
1392 KB |
Output is correct |
17 |
Correct |
57 ms |
6244 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
492 KB |
Output is correct |
3 |
Correct |
1 ms |
492 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
5 |
Correct |
377 ms |
33340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
523 ms |
36156 KB |
Output is correct |
3 |
Correct |
521 ms |
33468 KB |
Output is correct |
4 |
Correct |
502 ms |
33468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
523 ms |
36156 KB |
Output is correct |
3 |
Correct |
521 ms |
33468 KB |
Output is correct |
4 |
Correct |
502 ms |
33468 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
516 ms |
33620 KB |
Output is correct |
7 |
Correct |
516 ms |
33468 KB |
Output is correct |
8 |
Correct |
505 ms |
33468 KB |
Output is correct |
9 |
Correct |
605 ms |
33604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
523 ms |
36156 KB |
Output is correct |
3 |
Correct |
521 ms |
33468 KB |
Output is correct |
4 |
Correct |
502 ms |
33468 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
50 ms |
6372 KB |
Output is correct |
7 |
Correct |
53 ms |
6244 KB |
Output is correct |
8 |
Correct |
50 ms |
6116 KB |
Output is correct |
9 |
Correct |
52 ms |
5988 KB |
Output is correct |
10 |
Correct |
52 ms |
6044 KB |
Output is correct |
11 |
Correct |
53 ms |
5988 KB |
Output is correct |
12 |
Correct |
50 ms |
5984 KB |
Output is correct |
13 |
Correct |
55 ms |
5988 KB |
Output is correct |
14 |
Correct |
49 ms |
5860 KB |
Output is correct |
15 |
Correct |
58 ms |
5860 KB |
Output is correct |
16 |
Correct |
55 ms |
5732 KB |
Output is correct |
17 |
Correct |
53 ms |
5732 KB |
Output is correct |
18 |
Correct |
515 ms |
33468 KB |
Output is correct |
19 |
Correct |
499 ms |
33612 KB |
Output is correct |
20 |
Correct |
628 ms |
33468 KB |
Output is correct |
21 |
Correct |
54 ms |
5732 KB |
Output is correct |
22 |
Correct |
47 ms |
5732 KB |
Output is correct |
23 |
Correct |
157 ms |
18024 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
54 ms |
5732 KB |
Output is correct |
3 |
Correct |
55 ms |
5732 KB |
Output is correct |
4 |
Correct |
649 ms |
33468 KB |
Output is correct |
5 |
Correct |
54 ms |
5732 KB |
Output is correct |
6 |
Correct |
54 ms |
5732 KB |
Output is correct |
7 |
Correct |
56 ms |
5732 KB |
Output is correct |
8 |
Correct |
57 ms |
5680 KB |
Output is correct |
9 |
Correct |
53 ms |
5672 KB |
Output is correct |
10 |
Correct |
54 ms |
5732 KB |
Output is correct |
11 |
Correct |
57 ms |
5732 KB |
Output is correct |
12 |
Correct |
48 ms |
5720 KB |
Output is correct |
13 |
Correct |
54 ms |
5732 KB |
Output is correct |
14 |
Correct |
603 ms |
33596 KB |
Output is correct |
15 |
Correct |
54 ms |
5732 KB |
Output is correct |
16 |
Correct |
506 ms |
33468 KB |
Output is correct |
17 |
Correct |
493 ms |
33456 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
6 ms |
1392 KB |
Output is correct |
3 |
Correct |
6 ms |
1392 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
6 ms |
1392 KB |
Output is correct |
17 |
Correct |
57 ms |
6244 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
492 KB |
Output is correct |
26 |
Correct |
1 ms |
492 KB |
Output is correct |
27 |
Correct |
1 ms |
492 KB |
Output is correct |
28 |
Correct |
377 ms |
33340 KB |
Output is correct |
29 |
Correct |
1 ms |
364 KB |
Output is correct |
30 |
Correct |
523 ms |
36156 KB |
Output is correct |
31 |
Correct |
521 ms |
33468 KB |
Output is correct |
32 |
Correct |
502 ms |
33468 KB |
Output is correct |
33 |
Correct |
1 ms |
364 KB |
Output is correct |
34 |
Correct |
516 ms |
33620 KB |
Output is correct |
35 |
Correct |
516 ms |
33468 KB |
Output is correct |
36 |
Correct |
505 ms |
33468 KB |
Output is correct |
37 |
Correct |
605 ms |
33604 KB |
Output is correct |
38 |
Correct |
1 ms |
364 KB |
Output is correct |
39 |
Correct |
50 ms |
6372 KB |
Output is correct |
40 |
Correct |
53 ms |
6244 KB |
Output is correct |
41 |
Correct |
50 ms |
6116 KB |
Output is correct |
42 |
Correct |
52 ms |
5988 KB |
Output is correct |
43 |
Correct |
52 ms |
6044 KB |
Output is correct |
44 |
Correct |
53 ms |
5988 KB |
Output is correct |
45 |
Correct |
50 ms |
5984 KB |
Output is correct |
46 |
Correct |
55 ms |
5988 KB |
Output is correct |
47 |
Correct |
49 ms |
5860 KB |
Output is correct |
48 |
Correct |
58 ms |
5860 KB |
Output is correct |
49 |
Correct |
55 ms |
5732 KB |
Output is correct |
50 |
Correct |
53 ms |
5732 KB |
Output is correct |
51 |
Correct |
515 ms |
33468 KB |
Output is correct |
52 |
Correct |
499 ms |
33612 KB |
Output is correct |
53 |
Correct |
628 ms |
33468 KB |
Output is correct |
54 |
Correct |
54 ms |
5732 KB |
Output is correct |
55 |
Correct |
47 ms |
5732 KB |
Output is correct |
56 |
Correct |
157 ms |
18024 KB |
Output is correct |
57 |
Correct |
1 ms |
364 KB |
Output is correct |
58 |
Correct |
54 ms |
5732 KB |
Output is correct |
59 |
Correct |
55 ms |
5732 KB |
Output is correct |
60 |
Correct |
649 ms |
33468 KB |
Output is correct |
61 |
Correct |
54 ms |
5732 KB |
Output is correct |
62 |
Correct |
54 ms |
5732 KB |
Output is correct |
63 |
Correct |
56 ms |
5732 KB |
Output is correct |
64 |
Correct |
57 ms |
5680 KB |
Output is correct |
65 |
Correct |
53 ms |
5672 KB |
Output is correct |
66 |
Correct |
54 ms |
5732 KB |
Output is correct |
67 |
Correct |
57 ms |
5732 KB |
Output is correct |
68 |
Correct |
48 ms |
5720 KB |
Output is correct |
69 |
Correct |
54 ms |
5732 KB |
Output is correct |
70 |
Correct |
603 ms |
33596 KB |
Output is correct |
71 |
Correct |
54 ms |
5732 KB |
Output is correct |
72 |
Correct |
506 ms |
33468 KB |
Output is correct |
73 |
Correct |
493 ms |
33456 KB |
Output is correct |
74 |
Correct |
1 ms |
364 KB |
Output is correct |
75 |
Correct |
1 ms |
364 KB |
Output is correct |
76 |
Correct |
1 ms |
364 KB |
Output is correct |
77 |
Correct |
1 ms |
364 KB |
Output is correct |
78 |
Correct |
1 ms |
364 KB |
Output is correct |
79 |
Correct |
5 ms |
1392 KB |
Output is correct |
80 |
Correct |
655 ms |
33340 KB |
Output is correct |
81 |
Correct |
651 ms |
33340 KB |
Output is correct |
82 |
Correct |
613 ms |
33340 KB |
Output is correct |
83 |
Correct |
613 ms |
33364 KB |
Output is correct |
84 |
Correct |
604 ms |
33340 KB |
Output is correct |
85 |
Correct |
604 ms |
33472 KB |
Output is correct |
86 |
Correct |
159 ms |
17360 KB |
Output is correct |
87 |
Correct |
1 ms |
364 KB |
Output is correct |