#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <set>
#include <map>
#include <queue>
#include <cstring>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <functional>
//#include <unordered_map>
using namespace std;
template<typename T> void uin(T &a, T b) {if (b < a) a = b;}
template<typename T> void uax(T &a, T b) {if (b > a) a = b;}
#define int long long
#define double long double
#define left left228
#define right right228
#define mp make_pair
#define all(v) v.begin(), v.end()
const int INF = 1100LL * 1000LL * 1000LL * 1000LL * 1000LL * 1000LL;
int gcd(int a, int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int mult(int a, int b) {
if (a > INF / b) {
return INF;
}
return min( INF, a * b );
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, A, B;
cin >> n >> A >> B;
int MOD = mult(A, B);
MOD /= gcd(A, B + 1);
set< pair<int,int> > s;
map<int,int>bal;
int ans = 0;
bool all = 0;
for (int i = 0; i < n; ++i) {
int l, r;
cin >> l >> r;
if (r - l + 1 >= MOD) {
all = 1;
}
int lm = l % MOD;
int rm = r % MOD;
if (lm <= rm) {
++bal[lm];
--bal[rm + 1];
} else {
++bal[lm];
--bal[MOD];
++bal[0];
--bal[rm + 1];
}
}
if (all) {
cout << MOD << '\n';
return 0;
}
vector< pair<int, int> > v;
for (auto p : bal) {
v.emplace_back(p);
}
int balance = 0;
for (int i = 0; i < (int)v.size() - 1; ++i) {
balance += v[i].second;
if (balance > 0) {
ans += v[i + 1].first - v[i].first;
}
}
cout << ans << '\n';
return 0;
}
/*
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
7 ms |
1408 KB |
Output is correct |
3 |
Correct |
7 ms |
1408 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
7 ms |
1408 KB |
Output is correct |
17 |
Correct |
84 ms |
8812 KB |
Output is correct |
18 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
512 KB |
Output is correct |
3 |
Correct |
1 ms |
512 KB |
Output is correct |
4 |
Correct |
1 ms |
512 KB |
Output is correct |
5 |
Correct |
311 ms |
1040 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
810 ms |
79532 KB |
Output is correct |
3 |
Correct |
860 ms |
80244 KB |
Output is correct |
4 |
Correct |
896 ms |
83544 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
810 ms |
79532 KB |
Output is correct |
3 |
Correct |
860 ms |
80244 KB |
Output is correct |
4 |
Correct |
896 ms |
83544 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
862 ms |
83664 KB |
Output is correct |
7 |
Correct |
854 ms |
83544 KB |
Output is correct |
8 |
Correct |
853 ms |
83684 KB |
Output is correct |
9 |
Correct |
939 ms |
83800 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
810 ms |
79532 KB |
Output is correct |
3 |
Correct |
860 ms |
80244 KB |
Output is correct |
4 |
Correct |
896 ms |
83544 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
76 ms |
12564 KB |
Output is correct |
7 |
Correct |
74 ms |
12524 KB |
Output is correct |
8 |
Correct |
101 ms |
12524 KB |
Output is correct |
9 |
Correct |
82 ms |
12524 KB |
Output is correct |
10 |
Correct |
75 ms |
12524 KB |
Output is correct |
11 |
Correct |
74 ms |
12524 KB |
Output is correct |
12 |
Correct |
78 ms |
12524 KB |
Output is correct |
13 |
Correct |
82 ms |
12524 KB |
Output is correct |
14 |
Correct |
76 ms |
12524 KB |
Output is correct |
15 |
Correct |
89 ms |
12528 KB |
Output is correct |
16 |
Correct |
87 ms |
12524 KB |
Output is correct |
17 |
Correct |
78 ms |
12524 KB |
Output is correct |
18 |
Correct |
850 ms |
83692 KB |
Output is correct |
19 |
Correct |
888 ms |
84564 KB |
Output is correct |
20 |
Correct |
932 ms |
84516 KB |
Output is correct |
21 |
Correct |
77 ms |
12524 KB |
Output is correct |
22 |
Correct |
81 ms |
12524 KB |
Output is correct |
23 |
Correct |
147 ms |
5240 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
86 ms |
9448 KB |
Output is correct |
3 |
Correct |
83 ms |
9452 KB |
Output is correct |
4 |
Correct |
907 ms |
81128 KB |
Output is correct |
5 |
Correct |
99 ms |
9452 KB |
Output is correct |
6 |
Correct |
87 ms |
9408 KB |
Output is correct |
7 |
Correct |
87 ms |
9452 KB |
Output is correct |
8 |
Correct |
83 ms |
9480 KB |
Output is correct |
9 |
Correct |
84 ms |
9452 KB |
Output is correct |
10 |
Correct |
84 ms |
9452 KB |
Output is correct |
11 |
Correct |
81 ms |
9452 KB |
Output is correct |
12 |
Correct |
79 ms |
9452 KB |
Output is correct |
13 |
Correct |
86 ms |
9452 KB |
Output is correct |
14 |
Correct |
969 ms |
81224 KB |
Output is correct |
15 |
Correct |
76 ms |
9836 KB |
Output is correct |
16 |
Correct |
828 ms |
84568 KB |
Output is correct |
17 |
Correct |
833 ms |
84560 KB |
Output is correct |
18 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
7 ms |
1408 KB |
Output is correct |
3 |
Correct |
7 ms |
1408 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
7 ms |
1408 KB |
Output is correct |
17 |
Correct |
84 ms |
8812 KB |
Output is correct |
18 |
Correct |
0 ms |
384 KB |
Output is correct |
19 |
Correct |
0 ms |
384 KB |
Output is correct |
20 |
Correct |
0 ms |
384 KB |
Output is correct |
21 |
Correct |
0 ms |
384 KB |
Output is correct |
22 |
Correct |
0 ms |
384 KB |
Output is correct |
23 |
Correct |
0 ms |
384 KB |
Output is correct |
24 |
Correct |
0 ms |
384 KB |
Output is correct |
25 |
Correct |
1 ms |
512 KB |
Output is correct |
26 |
Correct |
1 ms |
512 KB |
Output is correct |
27 |
Correct |
1 ms |
512 KB |
Output is correct |
28 |
Correct |
311 ms |
1040 KB |
Output is correct |
29 |
Correct |
0 ms |
384 KB |
Output is correct |
30 |
Correct |
810 ms |
79532 KB |
Output is correct |
31 |
Correct |
860 ms |
80244 KB |
Output is correct |
32 |
Correct |
896 ms |
83544 KB |
Output is correct |
33 |
Correct |
1 ms |
384 KB |
Output is correct |
34 |
Correct |
862 ms |
83664 KB |
Output is correct |
35 |
Correct |
854 ms |
83544 KB |
Output is correct |
36 |
Correct |
853 ms |
83684 KB |
Output is correct |
37 |
Correct |
939 ms |
83800 KB |
Output is correct |
38 |
Correct |
1 ms |
384 KB |
Output is correct |
39 |
Correct |
76 ms |
12564 KB |
Output is correct |
40 |
Correct |
74 ms |
12524 KB |
Output is correct |
41 |
Correct |
101 ms |
12524 KB |
Output is correct |
42 |
Correct |
82 ms |
12524 KB |
Output is correct |
43 |
Correct |
75 ms |
12524 KB |
Output is correct |
44 |
Correct |
74 ms |
12524 KB |
Output is correct |
45 |
Correct |
78 ms |
12524 KB |
Output is correct |
46 |
Correct |
82 ms |
12524 KB |
Output is correct |
47 |
Correct |
76 ms |
12524 KB |
Output is correct |
48 |
Correct |
89 ms |
12528 KB |
Output is correct |
49 |
Correct |
87 ms |
12524 KB |
Output is correct |
50 |
Correct |
78 ms |
12524 KB |
Output is correct |
51 |
Correct |
850 ms |
83692 KB |
Output is correct |
52 |
Correct |
888 ms |
84564 KB |
Output is correct |
53 |
Correct |
932 ms |
84516 KB |
Output is correct |
54 |
Correct |
77 ms |
12524 KB |
Output is correct |
55 |
Correct |
81 ms |
12524 KB |
Output is correct |
56 |
Correct |
147 ms |
5240 KB |
Output is correct |
57 |
Correct |
0 ms |
384 KB |
Output is correct |
58 |
Correct |
86 ms |
9448 KB |
Output is correct |
59 |
Correct |
83 ms |
9452 KB |
Output is correct |
60 |
Correct |
907 ms |
81128 KB |
Output is correct |
61 |
Correct |
99 ms |
9452 KB |
Output is correct |
62 |
Correct |
87 ms |
9408 KB |
Output is correct |
63 |
Correct |
87 ms |
9452 KB |
Output is correct |
64 |
Correct |
83 ms |
9480 KB |
Output is correct |
65 |
Correct |
84 ms |
9452 KB |
Output is correct |
66 |
Correct |
84 ms |
9452 KB |
Output is correct |
67 |
Correct |
81 ms |
9452 KB |
Output is correct |
68 |
Correct |
79 ms |
9452 KB |
Output is correct |
69 |
Correct |
86 ms |
9452 KB |
Output is correct |
70 |
Correct |
969 ms |
81224 KB |
Output is correct |
71 |
Correct |
76 ms |
9836 KB |
Output is correct |
72 |
Correct |
828 ms |
84568 KB |
Output is correct |
73 |
Correct |
833 ms |
84560 KB |
Output is correct |
74 |
Correct |
0 ms |
384 KB |
Output is correct |
75 |
Correct |
0 ms |
384 KB |
Output is correct |
76 |
Correct |
0 ms |
384 KB |
Output is correct |
77 |
Correct |
0 ms |
384 KB |
Output is correct |
78 |
Correct |
0 ms |
512 KB |
Output is correct |
79 |
Correct |
11 ms |
1792 KB |
Output is correct |
80 |
Correct |
922 ms |
84440 KB |
Output is correct |
81 |
Correct |
920 ms |
84304 KB |
Output is correct |
82 |
Correct |
916 ms |
84312 KB |
Output is correct |
83 |
Correct |
893 ms |
84064 KB |
Output is correct |
84 |
Correct |
904 ms |
84128 KB |
Output is correct |
85 |
Correct |
877 ms |
84184 KB |
Output is correct |
86 |
Correct |
142 ms |
4856 KB |
Output is correct |
87 |
Correct |
1 ms |
384 KB |
Output is correct |