#include <bits/stdc++.h>
using namespace std;
#define int long long
// #define i128 long long
#define i128 __int128_t
int n, a, b;
vector<pair<int, int>> sg;
const int maks = 1e18;
// i128 gcd(i128 a, i128 b) {
// if (b == 0) return a;
// return gcd(b, a%b);
// }
bool comp(pair<int, int> a, pair<int, int> b) {
return (a.first < b.first or (a.first == b.first and a.second < b.second));
}
signed main() {
i128 temp;
// int temp;
i128 size;
cin >> n >> a >> b;
// temp = a*b;
temp = (a/__gcd(a,b+1))*b;
// if ((b+1 % a) == 0) size = b;
// if (temp > maks) size = maks;
// else size = temp;
size = temp;
int l, r;
for (int i = 0; i < n; i++) {
cin >> l >> r;
// cout << l << " " << r << endl;
if (r - l + 1 >= size) {
cout << (int)size << endl;
return 0;
} else if (l%size > r%size) {
sg.push_back({l%size, 1});
sg.push_back({size-1, 2});
sg.push_back({0, 1});
sg.push_back({r%size, 2});
} else {
sg.push_back({l%size, 1});
sg.push_back({r%size, 2});
}
}
sort(sg.begin(), sg.end(), comp);
int cnt = 0, l2;
vector<pair<int, int>> ans;
for (int i = 0; i < sg.size(); i++) {
// cout << sg[i].first << " " << sg[i].second << endl;
if (sg[i].second == 1) {
if (cnt == 0) l2 = sg[i].first;
cnt++;
} else cnt--;
if (cnt == 0) {
ans.push_back({l2, sg[i].first});
// ans += sg[i].first-l2+1.;
}
}
// cout << ans << endl;
int res = 0;
for (auto i: ans) {
// cout << i.first << " " << i.second << endl;
res += (i.second - i.first + 1);
}
cout << res << endl;
}
Compilation message
strange_device.cpp: In function 'int main()':
strange_device.cpp:54:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
54 | for (int i = 0; i < sg.size(); i++) {
| ~~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
12 ms |
1268 KB |
Output is correct |
3 |
Correct |
12 ms |
1300 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 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 |
288 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
296 KB |
Output is correct |
11 |
Correct |
1 ms |
212 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 |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
12 ms |
1292 KB |
Output is correct |
17 |
Correct |
143 ms |
8544 KB |
Output is correct |
18 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
300 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Incorrect |
1 ms |
300 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
2 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 |
830 ms |
33656 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1229 ms |
64132 KB |
Output is correct |
3 |
Correct |
1263 ms |
64124 KB |
Output is correct |
4 |
Correct |
1311 ms |
63760 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1229 ms |
64132 KB |
Output is correct |
3 |
Correct |
1263 ms |
64124 KB |
Output is correct |
4 |
Correct |
1311 ms |
63760 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1242 ms |
63868 KB |
Output is correct |
7 |
Correct |
1233 ms |
63720 KB |
Output is correct |
8 |
Correct |
1251 ms |
63768 KB |
Output is correct |
9 |
Correct |
1370 ms |
63768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1229 ms |
64132 KB |
Output is correct |
3 |
Correct |
1263 ms |
64124 KB |
Output is correct |
4 |
Correct |
1311 ms |
63760 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
116 ms |
7992 KB |
Output is correct |
7 |
Correct |
122 ms |
8052 KB |
Output is correct |
8 |
Correct |
117 ms |
7952 KB |
Output is correct |
9 |
Correct |
130 ms |
8032 KB |
Output is correct |
10 |
Correct |
122 ms |
8252 KB |
Output is correct |
11 |
Correct |
121 ms |
8008 KB |
Output is correct |
12 |
Correct |
128 ms |
8028 KB |
Output is correct |
13 |
Correct |
127 ms |
7972 KB |
Output is correct |
14 |
Correct |
117 ms |
8016 KB |
Output is correct |
15 |
Correct |
128 ms |
7992 KB |
Output is correct |
16 |
Correct |
130 ms |
8036 KB |
Output is correct |
17 |
Correct |
119 ms |
7960 KB |
Output is correct |
18 |
Correct |
1251 ms |
63824 KB |
Output is correct |
19 |
Correct |
1252 ms |
63812 KB |
Output is correct |
20 |
Correct |
1435 ms |
63740 KB |
Output is correct |
21 |
Correct |
134 ms |
7940 KB |
Output is correct |
22 |
Correct |
109 ms |
7908 KB |
Output is correct |
23 |
Correct |
378 ms |
17676 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
127 ms |
7884 KB |
Output is correct |
3 |
Correct |
127 ms |
7600 KB |
Output is correct |
4 |
Correct |
1395 ms |
64508 KB |
Output is correct |
5 |
Correct |
130 ms |
7592 KB |
Output is correct |
6 |
Correct |
135 ms |
7712 KB |
Output is correct |
7 |
Correct |
127 ms |
7708 KB |
Output is correct |
8 |
Correct |
142 ms |
7632 KB |
Output is correct |
9 |
Correct |
142 ms |
7628 KB |
Output is correct |
10 |
Correct |
132 ms |
7604 KB |
Output is correct |
11 |
Correct |
139 ms |
7704 KB |
Output is correct |
12 |
Correct |
144 ms |
7624 KB |
Output is correct |
13 |
Correct |
159 ms |
7620 KB |
Output is correct |
14 |
Correct |
1400 ms |
64152 KB |
Output is correct |
15 |
Correct |
139 ms |
7396 KB |
Output is correct |
16 |
Correct |
1195 ms |
63784 KB |
Output is correct |
17 |
Correct |
1280 ms |
63760 KB |
Output is correct |
18 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
12 ms |
1268 KB |
Output is correct |
3 |
Correct |
12 ms |
1300 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 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 |
288 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
296 KB |
Output is correct |
11 |
Correct |
1 ms |
212 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 |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
12 ms |
1292 KB |
Output is correct |
17 |
Correct |
143 ms |
8544 KB |
Output is correct |
18 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |