//Arayi
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <math.h>
#include <vector>
#include <cstring>
#include <ctime>
#include <set>
#include <bitset>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <ctime>
#include <climits>
#include <cassert>
#include <chrono>
#include <random>
#include <complex>
#define fr first
#define sc second
#define MP make_pair
#define ad push_back
#define PB push_back
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define lli long long int
#define y1 arayikhalatyan
#define j1 jigglypuff
#define ld long double
#define itn int
#define pir pair<int, int>
#define all(x) (x).begin(), (x).end()
#define str string
#define enl endl
#define en endl
#define cd complex<long double>
#define vcd vector<cd>
#define vii vector<int>
#define vlli vector<lli>
using namespace std;
lli gcd(lli a, lli b) { return (b == 0LL ? a : gcd(b, a % b)); }
ld dist(ld x, ld y1, ld x2, ld y2)
{
return sqrt((x - x2) * (x - x2) + (y1 - y2) * (y1 - y2));
}
lli S(lli a)
{
return (a * (a + 1LL)) / 2;
}
mt19937 rnd(363542);
char vow[] = { 'a', 'e', 'i', 'o', 'u' };
int dx[] = { 0, -1, 0, 1, -1, -1, 1, 1, 0 };
int dy[] = { -1, 0, 1, 0, -1, 1, -1, 1, 0 };
const int N = 1e6 + 30;
const lli mod = 1e9 + 7;
const ld pi = acos(-1);
const int T = 550;
lli bp(lli a, lli b = mod - 2LL)
{
lli ret = 1;
while (b)
{
if (b & 1) ret *= a, ret %= mod;
a *= a;
a %= mod;
b >>= 1;
}
return ret;
}
ostream& operator<<(ostream& c, pir a)
{
c << a.fr << " " << a.sc;
return c;
}
template<class T>
void maxi(T& a, T b)
{
a = max(a, b);
}
template <class T>
void mini(T& a, T b)
{
a = min(a, b);
}
int n;
lli A, B, x;
int main()
{
fastio;
cin >> n >> A >> B;
x = A / gcd(A, B + 1LL);
if (x > mod * mod / B) x = 1e18 + 1LL;
else x *= B;
vector<pair<lli, lli> > fp;
//cout << x << endl;
for (int i = 0; i < n; i++)
{
lli l, r;
cin >> l >> r;
if (r - l >= x)
{
cout << x << endl;
return 0;
}
if (l % x > r % x) fp.ad(MP(l % x, x - 1LL)), fp.ad(MP(0, r % x));
else fp.ad(MP(l % x, r % x));
}
sort(all(fp));
lli mx = -1, ans = x;
for (int i = 0; i < fp.size(); i++)
{
//cout << fp[i] << endl;
ans -= max(0LL, fp[i].fr - mx - 1LL);
maxi(mx, fp[i].sc);
}
ans -= max(0LL, x - mx - 1LL);
cout << ans << endl;
return 0;
}
/*
*
__
*(><)*
\/ /
||/
--||
||
/\
/ \
/ \
*/
Compilation message
strange_device.cpp: In function 'int main()':
strange_device.cpp:122: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]
122 | for (int i = 0; i < fp.size(); i++)
| ~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
320 KB |
Output is correct |
2 |
Correct |
7 ms |
1052 KB |
Output is correct |
3 |
Correct |
6 ms |
976 KB |
Output is correct |
4 |
Correct |
1 ms |
316 KB |
Output is correct |
5 |
Correct |
1 ms |
320 KB |
Output is correct |
6 |
Correct |
1 ms |
316 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 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 |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
324 KB |
Output is correct |
16 |
Correct |
7 ms |
1056 KB |
Output is correct |
17 |
Correct |
70 ms |
5632 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
324 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
404 ms |
41252 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
510 ms |
53280 KB |
Output is correct |
3 |
Correct |
505 ms |
53252 KB |
Output is correct |
4 |
Correct |
536 ms |
53260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
510 ms |
53280 KB |
Output is correct |
3 |
Correct |
505 ms |
53252 KB |
Output is correct |
4 |
Correct |
536 ms |
53260 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
528 ms |
53264 KB |
Output is correct |
7 |
Correct |
531 ms |
53300 KB |
Output is correct |
8 |
Correct |
508 ms |
53328 KB |
Output is correct |
9 |
Correct |
527 ms |
53276 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
510 ms |
53280 KB |
Output is correct |
3 |
Correct |
505 ms |
53252 KB |
Output is correct |
4 |
Correct |
536 ms |
53260 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
62 ms |
5728 KB |
Output is correct |
7 |
Correct |
58 ms |
5692 KB |
Output is correct |
8 |
Correct |
51 ms |
5652 KB |
Output is correct |
9 |
Correct |
49 ms |
5684 KB |
Output is correct |
10 |
Correct |
50 ms |
5608 KB |
Output is correct |
11 |
Correct |
56 ms |
5732 KB |
Output is correct |
12 |
Correct |
49 ms |
5732 KB |
Output is correct |
13 |
Correct |
51 ms |
5652 KB |
Output is correct |
14 |
Correct |
47 ms |
5688 KB |
Output is correct |
15 |
Correct |
55 ms |
5728 KB |
Output is correct |
16 |
Correct |
53 ms |
5736 KB |
Output is correct |
17 |
Correct |
49 ms |
5696 KB |
Output is correct |
18 |
Correct |
509 ms |
53256 KB |
Output is correct |
19 |
Correct |
567 ms |
53376 KB |
Output is correct |
20 |
Correct |
582 ms |
53376 KB |
Output is correct |
21 |
Correct |
52 ms |
5740 KB |
Output is correct |
22 |
Correct |
46 ms |
5716 KB |
Output is correct |
23 |
Correct |
164 ms |
18444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
59 ms |
5668 KB |
Output is correct |
3 |
Correct |
59 ms |
5676 KB |
Output is correct |
4 |
Correct |
571 ms |
53260 KB |
Output is correct |
5 |
Correct |
59 ms |
5848 KB |
Output is correct |
6 |
Correct |
50 ms |
5688 KB |
Output is correct |
7 |
Correct |
51 ms |
5672 KB |
Output is correct |
8 |
Correct |
52 ms |
5688 KB |
Output is correct |
9 |
Correct |
63 ms |
5728 KB |
Output is correct |
10 |
Correct |
66 ms |
5688 KB |
Output is correct |
11 |
Correct |
61 ms |
5688 KB |
Output is correct |
12 |
Correct |
52 ms |
5696 KB |
Output is correct |
13 |
Correct |
62 ms |
5668 KB |
Output is correct |
14 |
Correct |
565 ms |
53232 KB |
Output is correct |
15 |
Correct |
50 ms |
5668 KB |
Output is correct |
16 |
Correct |
500 ms |
53264 KB |
Output is correct |
17 |
Correct |
500 ms |
53264 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
320 KB |
Output is correct |
2 |
Correct |
7 ms |
1052 KB |
Output is correct |
3 |
Correct |
6 ms |
976 KB |
Output is correct |
4 |
Correct |
1 ms |
316 KB |
Output is correct |
5 |
Correct |
1 ms |
320 KB |
Output is correct |
6 |
Correct |
1 ms |
316 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 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 |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
324 KB |
Output is correct |
16 |
Correct |
7 ms |
1056 KB |
Output is correct |
17 |
Correct |
70 ms |
5632 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
324 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
1 ms |
204 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
2 ms |
340 KB |
Output is correct |
26 |
Correct |
2 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
404 ms |
41252 KB |
Output is correct |
29 |
Correct |
1 ms |
204 KB |
Output is correct |
30 |
Correct |
510 ms |
53280 KB |
Output is correct |
31 |
Correct |
505 ms |
53252 KB |
Output is correct |
32 |
Correct |
536 ms |
53260 KB |
Output is correct |
33 |
Correct |
1 ms |
204 KB |
Output is correct |
34 |
Correct |
528 ms |
53264 KB |
Output is correct |
35 |
Correct |
531 ms |
53300 KB |
Output is correct |
36 |
Correct |
508 ms |
53328 KB |
Output is correct |
37 |
Correct |
527 ms |
53276 KB |
Output is correct |
38 |
Correct |
1 ms |
204 KB |
Output is correct |
39 |
Correct |
62 ms |
5728 KB |
Output is correct |
40 |
Correct |
58 ms |
5692 KB |
Output is correct |
41 |
Correct |
51 ms |
5652 KB |
Output is correct |
42 |
Correct |
49 ms |
5684 KB |
Output is correct |
43 |
Correct |
50 ms |
5608 KB |
Output is correct |
44 |
Correct |
56 ms |
5732 KB |
Output is correct |
45 |
Correct |
49 ms |
5732 KB |
Output is correct |
46 |
Correct |
51 ms |
5652 KB |
Output is correct |
47 |
Correct |
47 ms |
5688 KB |
Output is correct |
48 |
Correct |
55 ms |
5728 KB |
Output is correct |
49 |
Correct |
53 ms |
5736 KB |
Output is correct |
50 |
Correct |
49 ms |
5696 KB |
Output is correct |
51 |
Correct |
509 ms |
53256 KB |
Output is correct |
52 |
Correct |
567 ms |
53376 KB |
Output is correct |
53 |
Correct |
582 ms |
53376 KB |
Output is correct |
54 |
Correct |
52 ms |
5740 KB |
Output is correct |
55 |
Correct |
46 ms |
5716 KB |
Output is correct |
56 |
Correct |
164 ms |
18444 KB |
Output is correct |
57 |
Correct |
1 ms |
204 KB |
Output is correct |
58 |
Correct |
59 ms |
5668 KB |
Output is correct |
59 |
Correct |
59 ms |
5676 KB |
Output is correct |
60 |
Correct |
571 ms |
53260 KB |
Output is correct |
61 |
Correct |
59 ms |
5848 KB |
Output is correct |
62 |
Correct |
50 ms |
5688 KB |
Output is correct |
63 |
Correct |
51 ms |
5672 KB |
Output is correct |
64 |
Correct |
52 ms |
5688 KB |
Output is correct |
65 |
Correct |
63 ms |
5728 KB |
Output is correct |
66 |
Correct |
66 ms |
5688 KB |
Output is correct |
67 |
Correct |
61 ms |
5688 KB |
Output is correct |
68 |
Correct |
52 ms |
5696 KB |
Output is correct |
69 |
Correct |
62 ms |
5668 KB |
Output is correct |
70 |
Correct |
565 ms |
53232 KB |
Output is correct |
71 |
Correct |
50 ms |
5668 KB |
Output is correct |
72 |
Correct |
500 ms |
53264 KB |
Output is correct |
73 |
Correct |
500 ms |
53264 KB |
Output is correct |
74 |
Correct |
1 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 |
1 ms |
204 KB |
Output is correct |
79 |
Correct |
8 ms |
972 KB |
Output is correct |
80 |
Correct |
603 ms |
53328 KB |
Output is correct |
81 |
Correct |
589 ms |
53304 KB |
Output is correct |
82 |
Correct |
530 ms |
53308 KB |
Output is correct |
83 |
Correct |
577 ms |
53300 KB |
Output is correct |
84 |
Correct |
556 ms |
53296 KB |
Output is correct |
85 |
Correct |
532 ms |
53324 KB |
Output is correct |
86 |
Correct |
159 ms |
18436 KB |
Output is correct |
87 |
Correct |
1 ms |
204 KB |
Output is correct |