#include <bits/stdc++.h>
using namespace std;
#define ll long long
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define usecppio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(x) ((x).begin()),((x).end())
#define int __int128
using pii = pair <int, int>;
#define INF 0x7f7f7f7f7f7f7f7f
const bool debug = false;
std::ostream&operator<<( std::ostream& dest, __int128_t value )
{
std::ostream::sentry s( dest );
if ( s ) {
__uint128_t tmp = value < 0 ? -value : value;
char buffer[ 128 ];
char* d = std::end( buffer );
do
{
-- d;
*d = "0123456789"[ tmp % 10 ];
tmp /= 10;
} while ( tmp != 0 );
if ( value < 0 ) {
-- d;
*d = '-';
}
int len = std::end( buffer ) - d;
if ( dest.rdbuf()->sputn( d, len ) != len ) {
dest.setstate( std::ios_base::badbit );
}
}
return dest;
}
int n, a, b;
int period;
vector <pii> v;
vector <pii> range;
int32_t main()
{
usecppio
ll _n, _a, _b;
cin >> _n >> _a >> _b;
n = _n, a = _a, b = _b;
period = (a/(__gcd(a, b+1)))*b;
for (int i = 0; i<n; i++)
{
ll l, r; cin >> l >> r;
v.push_back({l, r});
if (r - l + 1 >= period)
{
cout << period << '\n';
return 0;
}
if (l%period <= r%period)
{
range.push_back({l%period, r%period});
}
else
{
range.push_back({0, r%period});
range.push_back({l%period, period-1});
}
}
sort(all(range));
int start = range[0].first;
int end = range[0].second;
int ans = 0;
for (int i = 1; i<range.size(); i++)
{
if (range[i].first > end)
{
ans += end-start+1;
start = range[i].first;
end = range[i].second;
}
else
end = max(end, range[i].second);
}
ans += end-start+1;
cout << ans << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
11 ms |
1652 KB |
Output is correct |
3 |
Correct |
11 ms |
1780 KB |
Output is correct |
4 |
Correct |
5 ms |
380 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
248 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
4 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
11 ms |
1652 KB |
Output is correct |
17 |
Correct |
72 ms |
10560 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
380 KB |
Output is correct |
2 |
Correct |
5 ms |
504 KB |
Output is correct |
3 |
Correct |
5 ms |
504 KB |
Output is correct |
4 |
Correct |
5 ms |
504 KB |
Output is correct |
5 |
Correct |
467 ms |
88344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
609 ms |
100284 KB |
Output is correct |
3 |
Correct |
608 ms |
100316 KB |
Output is correct |
4 |
Correct |
632 ms |
100412 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
609 ms |
100284 KB |
Output is correct |
3 |
Correct |
608 ms |
100316 KB |
Output is correct |
4 |
Correct |
632 ms |
100412 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
647 ms |
100284 KB |
Output is correct |
7 |
Correct |
645 ms |
100272 KB |
Output is correct |
8 |
Correct |
622 ms |
100280 KB |
Output is correct |
9 |
Correct |
706 ms |
100284 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
609 ms |
100284 KB |
Output is correct |
3 |
Correct |
608 ms |
100316 KB |
Output is correct |
4 |
Correct |
632 ms |
100412 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
63 ms |
10572 KB |
Output is correct |
7 |
Correct |
70 ms |
10572 KB |
Output is correct |
8 |
Correct |
64 ms |
10492 KB |
Output is correct |
9 |
Correct |
68 ms |
10572 KB |
Output is correct |
10 |
Correct |
65 ms |
10572 KB |
Output is correct |
11 |
Correct |
64 ms |
10576 KB |
Output is correct |
12 |
Correct |
65 ms |
10564 KB |
Output is correct |
13 |
Correct |
66 ms |
10560 KB |
Output is correct |
14 |
Correct |
64 ms |
10560 KB |
Output is correct |
15 |
Correct |
71 ms |
10548 KB |
Output is correct |
16 |
Correct |
71 ms |
10568 KB |
Output is correct |
17 |
Correct |
72 ms |
10568 KB |
Output is correct |
18 |
Correct |
638 ms |
100360 KB |
Output is correct |
19 |
Correct |
627 ms |
100276 KB |
Output is correct |
20 |
Correct |
729 ms |
100280 KB |
Output is correct |
21 |
Correct |
71 ms |
10572 KB |
Output is correct |
22 |
Correct |
64 ms |
10560 KB |
Output is correct |
23 |
Correct |
204 ms |
34992 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
72 ms |
10572 KB |
Output is correct |
3 |
Correct |
71 ms |
10568 KB |
Output is correct |
4 |
Correct |
724 ms |
100244 KB |
Output is correct |
5 |
Correct |
70 ms |
10560 KB |
Output is correct |
6 |
Correct |
68 ms |
10572 KB |
Output is correct |
7 |
Correct |
69 ms |
10572 KB |
Output is correct |
8 |
Correct |
72 ms |
10612 KB |
Output is correct |
9 |
Correct |
68 ms |
10568 KB |
Output is correct |
10 |
Correct |
71 ms |
10560 KB |
Output is correct |
11 |
Correct |
68 ms |
10500 KB |
Output is correct |
12 |
Correct |
66 ms |
10568 KB |
Output is correct |
13 |
Correct |
70 ms |
10568 KB |
Output is correct |
14 |
Correct |
710 ms |
100280 KB |
Output is correct |
15 |
Correct |
71 ms |
10572 KB |
Output is correct |
16 |
Correct |
616 ms |
100288 KB |
Output is correct |
17 |
Correct |
617 ms |
100196 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
11 ms |
1652 KB |
Output is correct |
3 |
Correct |
11 ms |
1780 KB |
Output is correct |
4 |
Correct |
5 ms |
380 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
248 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
4 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
11 ms |
1652 KB |
Output is correct |
17 |
Correct |
72 ms |
10560 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is correct |
19 |
Correct |
5 ms |
376 KB |
Output is correct |
20 |
Correct |
5 ms |
376 KB |
Output is correct |
21 |
Correct |
5 ms |
376 KB |
Output is correct |
22 |
Correct |
5 ms |
376 KB |
Output is correct |
23 |
Correct |
5 ms |
376 KB |
Output is correct |
24 |
Correct |
5 ms |
380 KB |
Output is correct |
25 |
Correct |
5 ms |
504 KB |
Output is correct |
26 |
Correct |
5 ms |
504 KB |
Output is correct |
27 |
Correct |
5 ms |
504 KB |
Output is correct |
28 |
Correct |
467 ms |
88344 KB |
Output is correct |
29 |
Correct |
5 ms |
376 KB |
Output is correct |
30 |
Correct |
609 ms |
100284 KB |
Output is correct |
31 |
Correct |
608 ms |
100316 KB |
Output is correct |
32 |
Correct |
632 ms |
100412 KB |
Output is correct |
33 |
Correct |
5 ms |
376 KB |
Output is correct |
34 |
Correct |
647 ms |
100284 KB |
Output is correct |
35 |
Correct |
645 ms |
100272 KB |
Output is correct |
36 |
Correct |
622 ms |
100280 KB |
Output is correct |
37 |
Correct |
706 ms |
100284 KB |
Output is correct |
38 |
Correct |
5 ms |
376 KB |
Output is correct |
39 |
Correct |
63 ms |
10572 KB |
Output is correct |
40 |
Correct |
70 ms |
10572 KB |
Output is correct |
41 |
Correct |
64 ms |
10492 KB |
Output is correct |
42 |
Correct |
68 ms |
10572 KB |
Output is correct |
43 |
Correct |
65 ms |
10572 KB |
Output is correct |
44 |
Correct |
64 ms |
10576 KB |
Output is correct |
45 |
Correct |
65 ms |
10564 KB |
Output is correct |
46 |
Correct |
66 ms |
10560 KB |
Output is correct |
47 |
Correct |
64 ms |
10560 KB |
Output is correct |
48 |
Correct |
71 ms |
10548 KB |
Output is correct |
49 |
Correct |
71 ms |
10568 KB |
Output is correct |
50 |
Correct |
72 ms |
10568 KB |
Output is correct |
51 |
Correct |
638 ms |
100360 KB |
Output is correct |
52 |
Correct |
627 ms |
100276 KB |
Output is correct |
53 |
Correct |
729 ms |
100280 KB |
Output is correct |
54 |
Correct |
71 ms |
10572 KB |
Output is correct |
55 |
Correct |
64 ms |
10560 KB |
Output is correct |
56 |
Correct |
204 ms |
34992 KB |
Output is correct |
57 |
Correct |
5 ms |
376 KB |
Output is correct |
58 |
Correct |
72 ms |
10572 KB |
Output is correct |
59 |
Correct |
71 ms |
10568 KB |
Output is correct |
60 |
Correct |
724 ms |
100244 KB |
Output is correct |
61 |
Correct |
70 ms |
10560 KB |
Output is correct |
62 |
Correct |
68 ms |
10572 KB |
Output is correct |
63 |
Correct |
69 ms |
10572 KB |
Output is correct |
64 |
Correct |
72 ms |
10612 KB |
Output is correct |
65 |
Correct |
68 ms |
10568 KB |
Output is correct |
66 |
Correct |
71 ms |
10560 KB |
Output is correct |
67 |
Correct |
68 ms |
10500 KB |
Output is correct |
68 |
Correct |
66 ms |
10568 KB |
Output is correct |
69 |
Correct |
70 ms |
10568 KB |
Output is correct |
70 |
Correct |
710 ms |
100280 KB |
Output is correct |
71 |
Correct |
71 ms |
10572 KB |
Output is correct |
72 |
Correct |
616 ms |
100288 KB |
Output is correct |
73 |
Correct |
617 ms |
100196 KB |
Output is correct |
74 |
Correct |
5 ms |
376 KB |
Output is correct |
75 |
Correct |
5 ms |
376 KB |
Output is correct |
76 |
Correct |
5 ms |
376 KB |
Output is correct |
77 |
Correct |
5 ms |
376 KB |
Output is correct |
78 |
Correct |
5 ms |
376 KB |
Output is correct |
79 |
Correct |
10 ms |
1652 KB |
Output is correct |
80 |
Correct |
763 ms |
100368 KB |
Output is correct |
81 |
Correct |
755 ms |
100224 KB |
Output is correct |
82 |
Correct |
740 ms |
100256 KB |
Output is correct |
83 |
Correct |
735 ms |
100296 KB |
Output is correct |
84 |
Correct |
709 ms |
100212 KB |
Output is correct |
85 |
Correct |
703 ms |
100244 KB |
Output is correct |
86 |
Correct |
209 ms |
35092 KB |
Output is correct |
87 |
Correct |
5 ms |
376 KB |
Output is correct |