#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
int n;
ll mod, a, b;
const ll inf = 2e18;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> a >> b;
a /= __gcd(a, b+1);
if (inf/a <= b) mod = inf;
else mod = a*b;
vector<pair<ll, int> > v;
for (int i = 0; i < n; i++)
{
ll l, r;
cin >> l >> r;
if (r - l + 1 >= mod)
{
v.push_back({0, 1});
v.push_back({mod, -1});
}
else
{
l %= mod, r %= mod;
if (l <= r)
{
v.push_back({l, 1}), v.push_back({r+1, -1});
}
else
{
v.push_back({0, 1}), v.push_back({r+1, -1});
v.push_back({l, 1}), v.push_back({mod, -1});
}
}
}
//cout << "===========\n" << mod << "\n";
sort(v.begin(), v.end());
ll ans = 0; int sum = 0;
for (int i = 0; i < v.size() - 1; i++)
{
//cout << v[i].first << " " << v[i].second << "\n";
sum += v[i].second;
if (sum) ans += v[i+1].first-v[i].first;
}
cout << ans << "\n";
return 0;
}
Compilation message
strange_device.cpp: In function 'int main()':
strange_device.cpp:44:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
44 | for (int i = 0; i < v.size() - 1; i++)
| ~~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
6 ms |
848 KB |
Output is correct |
3 |
Correct |
7 ms |
976 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
312 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
0 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 |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
7 ms |
1304 KB |
Output is correct |
17 |
Correct |
76 ms |
7228 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
421 ms |
33164 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
635 ms |
33264 KB |
Output is correct |
3 |
Correct |
648 ms |
33324 KB |
Output is correct |
4 |
Correct |
606 ms |
68812 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
635 ms |
33264 KB |
Output is correct |
3 |
Correct |
648 ms |
33324 KB |
Output is correct |
4 |
Correct |
606 ms |
68812 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
677 ms |
68744 KB |
Output is correct |
7 |
Correct |
630 ms |
68804 KB |
Output is correct |
8 |
Correct |
685 ms |
68852 KB |
Output is correct |
9 |
Correct |
778 ms |
68792 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
635 ms |
33264 KB |
Output is correct |
3 |
Correct |
648 ms |
33324 KB |
Output is correct |
4 |
Correct |
606 ms |
68812 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
59 ms |
7220 KB |
Output is correct |
7 |
Correct |
63 ms |
7204 KB |
Output is correct |
8 |
Correct |
61 ms |
7168 KB |
Output is correct |
9 |
Correct |
62 ms |
7264 KB |
Output is correct |
10 |
Correct |
63 ms |
7220 KB |
Output is correct |
11 |
Correct |
63 ms |
7172 KB |
Output is correct |
12 |
Correct |
58 ms |
7224 KB |
Output is correct |
13 |
Correct |
68 ms |
7220 KB |
Output is correct |
14 |
Correct |
59 ms |
7332 KB |
Output is correct |
15 |
Correct |
71 ms |
7272 KB |
Output is correct |
16 |
Correct |
69 ms |
7180 KB |
Output is correct |
17 |
Correct |
60 ms |
7220 KB |
Output is correct |
18 |
Correct |
657 ms |
68924 KB |
Output is correct |
19 |
Correct |
616 ms |
68884 KB |
Output is correct |
20 |
Correct |
748 ms |
68752 KB |
Output is correct |
21 |
Correct |
73 ms |
7208 KB |
Output is correct |
22 |
Correct |
55 ms |
7252 KB |
Output is correct |
23 |
Correct |
177 ms |
26596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
76 ms |
4800 KB |
Output is correct |
3 |
Correct |
69 ms |
4804 KB |
Output is correct |
4 |
Correct |
764 ms |
33228 KB |
Output is correct |
5 |
Correct |
70 ms |
4952 KB |
Output is correct |
6 |
Correct |
68 ms |
4796 KB |
Output is correct |
7 |
Correct |
79 ms |
4732 KB |
Output is correct |
8 |
Correct |
71 ms |
4768 KB |
Output is correct |
9 |
Correct |
65 ms |
4696 KB |
Output is correct |
10 |
Correct |
69 ms |
4720 KB |
Output is correct |
11 |
Correct |
70 ms |
4792 KB |
Output is correct |
12 |
Correct |
61 ms |
4728 KB |
Output is correct |
13 |
Correct |
71 ms |
4796 KB |
Output is correct |
14 |
Correct |
736 ms |
33172 KB |
Output is correct |
15 |
Correct |
70 ms |
4740 KB |
Output is correct |
16 |
Correct |
616 ms |
68776 KB |
Output is correct |
17 |
Correct |
634 ms |
68988 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
6 ms |
848 KB |
Output is correct |
3 |
Correct |
7 ms |
976 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
312 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
0 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 |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
7 ms |
1304 KB |
Output is correct |
17 |
Correct |
76 ms |
7228 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
0 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
0 ms |
204 KB |
Output is correct |
24 |
Correct |
0 ms |
204 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
421 ms |
33164 KB |
Output is correct |
29 |
Correct |
0 ms |
204 KB |
Output is correct |
30 |
Correct |
635 ms |
33264 KB |
Output is correct |
31 |
Correct |
648 ms |
33324 KB |
Output is correct |
32 |
Correct |
606 ms |
68812 KB |
Output is correct |
33 |
Correct |
1 ms |
204 KB |
Output is correct |
34 |
Correct |
677 ms |
68744 KB |
Output is correct |
35 |
Correct |
630 ms |
68804 KB |
Output is correct |
36 |
Correct |
685 ms |
68852 KB |
Output is correct |
37 |
Correct |
778 ms |
68792 KB |
Output is correct |
38 |
Correct |
0 ms |
204 KB |
Output is correct |
39 |
Correct |
59 ms |
7220 KB |
Output is correct |
40 |
Correct |
63 ms |
7204 KB |
Output is correct |
41 |
Correct |
61 ms |
7168 KB |
Output is correct |
42 |
Correct |
62 ms |
7264 KB |
Output is correct |
43 |
Correct |
63 ms |
7220 KB |
Output is correct |
44 |
Correct |
63 ms |
7172 KB |
Output is correct |
45 |
Correct |
58 ms |
7224 KB |
Output is correct |
46 |
Correct |
68 ms |
7220 KB |
Output is correct |
47 |
Correct |
59 ms |
7332 KB |
Output is correct |
48 |
Correct |
71 ms |
7272 KB |
Output is correct |
49 |
Correct |
69 ms |
7180 KB |
Output is correct |
50 |
Correct |
60 ms |
7220 KB |
Output is correct |
51 |
Correct |
657 ms |
68924 KB |
Output is correct |
52 |
Correct |
616 ms |
68884 KB |
Output is correct |
53 |
Correct |
748 ms |
68752 KB |
Output is correct |
54 |
Correct |
73 ms |
7208 KB |
Output is correct |
55 |
Correct |
55 ms |
7252 KB |
Output is correct |
56 |
Correct |
177 ms |
26596 KB |
Output is correct |
57 |
Correct |
1 ms |
204 KB |
Output is correct |
58 |
Correct |
76 ms |
4800 KB |
Output is correct |
59 |
Correct |
69 ms |
4804 KB |
Output is correct |
60 |
Correct |
764 ms |
33228 KB |
Output is correct |
61 |
Correct |
70 ms |
4952 KB |
Output is correct |
62 |
Correct |
68 ms |
4796 KB |
Output is correct |
63 |
Correct |
79 ms |
4732 KB |
Output is correct |
64 |
Correct |
71 ms |
4768 KB |
Output is correct |
65 |
Correct |
65 ms |
4696 KB |
Output is correct |
66 |
Correct |
69 ms |
4720 KB |
Output is correct |
67 |
Correct |
70 ms |
4792 KB |
Output is correct |
68 |
Correct |
61 ms |
4728 KB |
Output is correct |
69 |
Correct |
71 ms |
4796 KB |
Output is correct |
70 |
Correct |
736 ms |
33172 KB |
Output is correct |
71 |
Correct |
70 ms |
4740 KB |
Output is correct |
72 |
Correct |
616 ms |
68776 KB |
Output is correct |
73 |
Correct |
634 ms |
68988 KB |
Output is correct |
74 |
Correct |
0 ms |
204 KB |
Output is correct |
75 |
Correct |
1 ms |
204 KB |
Output is correct |
76 |
Correct |
1 ms |
204 KB |
Output is correct |
77 |
Correct |
1 ms |
204 KB |
Output is correct |
78 |
Correct |
0 ms |
204 KB |
Output is correct |
79 |
Correct |
6 ms |
1232 KB |
Output is correct |
80 |
Correct |
770 ms |
68852 KB |
Output is correct |
81 |
Correct |
785 ms |
68808 KB |
Output is correct |
82 |
Correct |
738 ms |
68852 KB |
Output is correct |
83 |
Correct |
743 ms |
68836 KB |
Output is correct |
84 |
Correct |
741 ms |
68844 KB |
Output is correct |
85 |
Correct |
736 ms |
68900 KB |
Output is correct |
86 |
Correct |
172 ms |
26660 KB |
Output is correct |
87 |
Correct |
1 ms |
204 KB |
Output is correct |