//#include "tree_contest.h"
#include <iostream>
using namespace std;
#include <vector>
#define vi vector<int>
#define ll long long
//#define ll __int128
#include <algorithm>
#include <set>
#include <string>
#include <bitset>
#include <cmath>
#include <math.h>
#define pll pair<ll,ll>
#define vll vector<ll>
#define pi pair<int,int>
#include <map>
#include <queue>
#define x first
#define y second
#define pd pair<double,double>
ll gcd(ll a, ll b) {
if (a > b)swap(a, b);
if (a == 0)return b;
return gcd(b % a, a);
}
int main() {
ll n,a, b;
cin >> n>>a >> b;
ios_base::sync_with_stdio(false); cin.tie(NULL);
ll m = (a / gcd(a, b + 1)) * b;
vector<pll> seg;
for (int i = 0; i < n; i++) {
ll l, r;
cin >> l >> r;
if (2 + (l / m) <= (r / m)) {
cout << m;
return 0;
}
if (l / m < r / m) {
seg.push_back({ l % m,1 });
seg.push_back({ m ,-1 });
//seg.push_back({ l % m,m-1 });
//seg.push_back({ 0,r % m });
seg.push_back({ 0,1 });
seg.push_back({ 1+(r % m),-1 });
}
else {
seg.push_back({ l % m,1 });
seg.push_back({ 1+(r % m),-1});
//seg.push_back({ l % m,r % m });
}
}
sort(seg.begin(), seg.end());
int sum = 0;
ll ans = 0;
seg.push_back({ m,0 });
for (int i = 0; i < seg.size(); i++) {
if (sum) {
ans += seg[i].first - seg[i - 1].first;
}
sum += seg[i].second;
}
cout << ans;
}
Compilation message
strange_device.cpp: In function 'int main()':
strange_device.cpp:58:23: 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]
58 | for (int i = 0; i < seg.size(); i++) {
| ~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
5 ms |
1460 KB |
Output is correct |
3 |
Correct |
5 ms |
1440 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
5 ms |
1248 KB |
Output is correct |
17 |
Correct |
52 ms |
7776 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
436 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
416 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
251 ms |
57256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
410 ms |
70488 KB |
Output is correct |
3 |
Correct |
418 ms |
69904 KB |
Output is correct |
4 |
Correct |
390 ms |
69544 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
410 ms |
70488 KB |
Output is correct |
3 |
Correct |
418 ms |
69904 KB |
Output is correct |
4 |
Correct |
390 ms |
69544 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
414 ms |
69100 KB |
Output is correct |
7 |
Correct |
410 ms |
69944 KB |
Output is correct |
8 |
Correct |
414 ms |
70048 KB |
Output is correct |
9 |
Correct |
463 ms |
70480 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
410 ms |
70488 KB |
Output is correct |
3 |
Correct |
418 ms |
69904 KB |
Output is correct |
4 |
Correct |
390 ms |
69544 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
39 ms |
8588 KB |
Output is correct |
7 |
Correct |
42 ms |
7884 KB |
Output is correct |
8 |
Correct |
40 ms |
7380 KB |
Output is correct |
9 |
Correct |
40 ms |
9164 KB |
Output is correct |
10 |
Correct |
37 ms |
8652 KB |
Output is correct |
11 |
Correct |
41 ms |
7372 KB |
Output is correct |
12 |
Correct |
37 ms |
9164 KB |
Output is correct |
13 |
Correct |
44 ms |
7628 KB |
Output is correct |
14 |
Correct |
38 ms |
7884 KB |
Output is correct |
15 |
Correct |
50 ms |
7368 KB |
Output is correct |
16 |
Correct |
45 ms |
7380 KB |
Output is correct |
17 |
Correct |
39 ms |
8148 KB |
Output is correct |
18 |
Correct |
422 ms |
69544 KB |
Output is correct |
19 |
Correct |
393 ms |
69204 KB |
Output is correct |
20 |
Correct |
548 ms |
69832 KB |
Output is correct |
21 |
Correct |
50 ms |
7636 KB |
Output is correct |
22 |
Correct |
34 ms |
7244 KB |
Output is correct |
23 |
Correct |
104 ms |
27968 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
43 ms |
7636 KB |
Output is correct |
3 |
Correct |
44 ms |
8056 KB |
Output is correct |
4 |
Correct |
608 ms |
70336 KB |
Output is correct |
5 |
Correct |
43 ms |
8396 KB |
Output is correct |
6 |
Correct |
44 ms |
8656 KB |
Output is correct |
7 |
Correct |
44 ms |
7892 KB |
Output is correct |
8 |
Correct |
46 ms |
8396 KB |
Output is correct |
9 |
Correct |
43 ms |
8404 KB |
Output is correct |
10 |
Correct |
48 ms |
8712 KB |
Output is correct |
11 |
Correct |
45 ms |
8652 KB |
Output is correct |
12 |
Correct |
39 ms |
7884 KB |
Output is correct |
13 |
Correct |
46 ms |
7380 KB |
Output is correct |
14 |
Correct |
485 ms |
70128 KB |
Output is correct |
15 |
Correct |
48 ms |
7952 KB |
Output is correct |
16 |
Correct |
382 ms |
69288 KB |
Output is correct |
17 |
Correct |
411 ms |
69392 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
5 ms |
1460 KB |
Output is correct |
3 |
Correct |
5 ms |
1440 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
5 ms |
1248 KB |
Output is correct |
17 |
Correct |
52 ms |
7776 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
436 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
416 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
251 ms |
57256 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
410 ms |
70488 KB |
Output is correct |
31 |
Correct |
418 ms |
69904 KB |
Output is correct |
32 |
Correct |
390 ms |
69544 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
414 ms |
69100 KB |
Output is correct |
35 |
Correct |
410 ms |
69944 KB |
Output is correct |
36 |
Correct |
414 ms |
70048 KB |
Output is correct |
37 |
Correct |
463 ms |
70480 KB |
Output is correct |
38 |
Correct |
1 ms |
348 KB |
Output is correct |
39 |
Correct |
39 ms |
8588 KB |
Output is correct |
40 |
Correct |
42 ms |
7884 KB |
Output is correct |
41 |
Correct |
40 ms |
7380 KB |
Output is correct |
42 |
Correct |
40 ms |
9164 KB |
Output is correct |
43 |
Correct |
37 ms |
8652 KB |
Output is correct |
44 |
Correct |
41 ms |
7372 KB |
Output is correct |
45 |
Correct |
37 ms |
9164 KB |
Output is correct |
46 |
Correct |
44 ms |
7628 KB |
Output is correct |
47 |
Correct |
38 ms |
7884 KB |
Output is correct |
48 |
Correct |
50 ms |
7368 KB |
Output is correct |
49 |
Correct |
45 ms |
7380 KB |
Output is correct |
50 |
Correct |
39 ms |
8148 KB |
Output is correct |
51 |
Correct |
422 ms |
69544 KB |
Output is correct |
52 |
Correct |
393 ms |
69204 KB |
Output is correct |
53 |
Correct |
548 ms |
69832 KB |
Output is correct |
54 |
Correct |
50 ms |
7636 KB |
Output is correct |
55 |
Correct |
34 ms |
7244 KB |
Output is correct |
56 |
Correct |
104 ms |
27968 KB |
Output is correct |
57 |
Correct |
0 ms |
348 KB |
Output is correct |
58 |
Correct |
43 ms |
7636 KB |
Output is correct |
59 |
Correct |
44 ms |
8056 KB |
Output is correct |
60 |
Correct |
608 ms |
70336 KB |
Output is correct |
61 |
Correct |
43 ms |
8396 KB |
Output is correct |
62 |
Correct |
44 ms |
8656 KB |
Output is correct |
63 |
Correct |
44 ms |
7892 KB |
Output is correct |
64 |
Correct |
46 ms |
8396 KB |
Output is correct |
65 |
Correct |
43 ms |
8404 KB |
Output is correct |
66 |
Correct |
48 ms |
8712 KB |
Output is correct |
67 |
Correct |
45 ms |
8652 KB |
Output is correct |
68 |
Correct |
39 ms |
7884 KB |
Output is correct |
69 |
Correct |
46 ms |
7380 KB |
Output is correct |
70 |
Correct |
485 ms |
70128 KB |
Output is correct |
71 |
Correct |
48 ms |
7952 KB |
Output is correct |
72 |
Correct |
382 ms |
69288 KB |
Output is correct |
73 |
Correct |
411 ms |
69392 KB |
Output is correct |
74 |
Correct |
0 ms |
348 KB |
Output is correct |
75 |
Correct |
1 ms |
348 KB |
Output is correct |
76 |
Correct |
0 ms |
348 KB |
Output is correct |
77 |
Correct |
0 ms |
348 KB |
Output is correct |
78 |
Correct |
0 ms |
348 KB |
Output is correct |
79 |
Correct |
4 ms |
1248 KB |
Output is correct |
80 |
Correct |
595 ms |
70204 KB |
Output is correct |
81 |
Correct |
602 ms |
70420 KB |
Output is correct |
82 |
Correct |
467 ms |
69552 KB |
Output is correct |
83 |
Correct |
498 ms |
69464 KB |
Output is correct |
84 |
Correct |
461 ms |
69540 KB |
Output is correct |
85 |
Correct |
528 ms |
69440 KB |
Output is correct |
86 |
Correct |
106 ms |
27072 KB |
Output is correct |
87 |
Correct |
1 ms |
348 KB |
Output is correct |