#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
const ll MAX = 1e18;
vector<pll> vec;
// {Left, Right}
ll n, a, b, length, ans = 0;
void opr(ll l, ll r) {
ll pushl = min(l, r);
ll pushr = max(l, r);
if (pushl == 0) {
// pushl = length;
}
if (pushr == 0) {
// pushr = length;
}
vec.push_back({pushl, pushr});
}
void answer() {
sort(vec.begin(), vec.end());
ll idx = -1;
for (int i = 0; i < vec.size(); ++i)
{
// cout << vec[i].first << " " << vec[i].second << "\n";
pll now = vec[i];
if (now.second < now.first)
{
continue ;
}
if (idx >= now.first)
{
if (now.second <= idx)
{
continue ;
} else {
idx++;
ans += now.second - idx + 1;
idx = now.second;
}
} else {
idx = now.first;
ans += now.second - idx + 1;
idx = now.second;
}
}
cout << ans << "\n";
}
ll fpb(ll a, ll b) {
if (a == 0)
{
return b;
}
return fpb(b%a, a);
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> n >> a >> b;
// unsigned long long lebek;
// if (a == 1) {
// lebek = b;
// } else {
// if (a % 2)
// {
// lebek = a * b;
// } else {
// lebek = (a/2) * b;
// }
// }
length = a / fpb(a, b+1) * b;
// length = lebek;
length = min(length, MAX);
for (int i = 0; i < n; ++i)
{
ll nowl, nowr;
cin >> nowl >> nowr;
if (nowr-nowl+1 >= length)
{
cout << length << "\n";
return 0;
}
if (nowl/length != nowr/length) {
opr(nowl % length + 1, length);
opr(1, nowr % length + 1);
} else {
opr(nowl % length + 1, nowr % length + 1);
}
}
answer();
return 0;
}
Compilation message
strange_device.cpp: In function 'void answer()':
strange_device.cpp:30:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
30 | for (int i = 0; i < vec.size(); ++i)
| ~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
316 KB |
Output is correct |
2 |
Correct |
4 ms |
972 KB |
Output is correct |
3 |
Correct |
4 ms |
876 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
316 KB |
Output is correct |
6 |
Correct |
1 ms |
324 KB |
Output is correct |
7 |
Correct |
1 ms |
320 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
324 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
324 KB |
Output is correct |
16 |
Correct |
4 ms |
856 KB |
Output is correct |
17 |
Correct |
35 ms |
2924 KB |
Output is correct |
18 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Incorrect |
1 ms |
320 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 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 |
217 ms |
16784 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
329 ms |
16944 KB |
Output is correct |
3 |
Correct |
343 ms |
18900 KB |
Output is correct |
4 |
Correct |
317 ms |
18876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
329 ms |
16944 KB |
Output is correct |
3 |
Correct |
343 ms |
18900 KB |
Output is correct |
4 |
Correct |
317 ms |
18876 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
322 ms |
18904 KB |
Output is correct |
7 |
Correct |
322 ms |
18644 KB |
Output is correct |
8 |
Correct |
312 ms |
18460 KB |
Output is correct |
9 |
Correct |
366 ms |
18916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
329 ms |
16944 KB |
Output is correct |
3 |
Correct |
343 ms |
18900 KB |
Output is correct |
4 |
Correct |
317 ms |
18876 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
36 ms |
4292 KB |
Output is correct |
7 |
Correct |
35 ms |
3940 KB |
Output is correct |
8 |
Correct |
39 ms |
4024 KB |
Output is correct |
9 |
Correct |
33 ms |
3960 KB |
Output is correct |
10 |
Correct |
31 ms |
4084 KB |
Output is correct |
11 |
Correct |
35 ms |
3972 KB |
Output is correct |
12 |
Correct |
33 ms |
3936 KB |
Output is correct |
13 |
Correct |
34 ms |
4052 KB |
Output is correct |
14 |
Correct |
34 ms |
4184 KB |
Output is correct |
15 |
Correct |
36 ms |
3976 KB |
Output is correct |
16 |
Correct |
34 ms |
4040 KB |
Output is correct |
17 |
Correct |
33 ms |
4056 KB |
Output is correct |
18 |
Correct |
318 ms |
18880 KB |
Output is correct |
19 |
Correct |
317 ms |
18660 KB |
Output is correct |
20 |
Correct |
345 ms |
18860 KB |
Output is correct |
21 |
Correct |
38 ms |
4068 KB |
Output is correct |
22 |
Correct |
35 ms |
4348 KB |
Output is correct |
23 |
Correct |
91 ms |
10692 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
33 ms |
3356 KB |
Output is correct |
3 |
Correct |
41 ms |
4112 KB |
Output is correct |
4 |
Correct |
361 ms |
18696 KB |
Output is correct |
5 |
Correct |
36 ms |
3976 KB |
Output is correct |
6 |
Correct |
34 ms |
4128 KB |
Output is correct |
7 |
Correct |
34 ms |
4028 KB |
Output is correct |
8 |
Correct |
37 ms |
4008 KB |
Output is correct |
9 |
Correct |
34 ms |
4124 KB |
Output is correct |
10 |
Correct |
33 ms |
4152 KB |
Output is correct |
11 |
Correct |
34 ms |
3992 KB |
Output is correct |
12 |
Correct |
31 ms |
4032 KB |
Output is correct |
13 |
Correct |
34 ms |
3988 KB |
Output is correct |
14 |
Correct |
324 ms |
18432 KB |
Output is correct |
15 |
Correct |
33 ms |
4012 KB |
Output is correct |
16 |
Correct |
324 ms |
18164 KB |
Output is correct |
17 |
Correct |
312 ms |
18876 KB |
Output is correct |
18 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
316 KB |
Output is correct |
2 |
Correct |
4 ms |
972 KB |
Output is correct |
3 |
Correct |
4 ms |
876 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
316 KB |
Output is correct |
6 |
Correct |
1 ms |
324 KB |
Output is correct |
7 |
Correct |
1 ms |
320 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
324 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
324 KB |
Output is correct |
16 |
Correct |
4 ms |
856 KB |
Output is correct |
17 |
Correct |
35 ms |
2924 KB |
Output is correct |
18 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |