#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<int, int> pii;
typedef pair<ld, ld> pld;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
ll n, a, b;
ll mod;
cin >> n >> a >> b;
ll na = a/__gcd(a, b+1);
if(na > (ll(1e18+5))/b+1)
mod = 1e18+5;
else
mod = min(b*na, ll(1e18+5));
vector<pll> seg;
for(ll i = 0; i < n; ++i){
pll tmp;
cin >> tmp.ff >> tmp.ss;
if(tmp.ss - tmp.ff + 1 >= mod){
cout << mod << '\n';
return 0;
}
tmp.ff %= mod;
tmp.ss %= mod;
//cout << i << ' ' << tmp.ff << ' ' << tmp.ss << '\n';
if(tmp.ss >= tmp.ff)
seg.pb({tmp.ff, tmp.ss});
else{
seg.pb({tmp.ff, mod-1});
seg.pb({0, tmp.ss});
}
}
//for(auto u : seg)
// cout << u.ff << ' ' << u.ss << '\n';
sort(seg.begin(), seg.end());
vector<pll> v;
for(auto u : seg){
//cout << u.ff << ' ' << u.ss << '\n';
if(!v.empty() && v.back().ss >= u.ff)
v.back().ss = max(v.back().ss, u.ss);
else
v.pb(u);
}
ll ans = 0;
for(auto u : v){
ans += u.ss-u.ff+1;
//cout << u.ff << ' ' << u.ss << '\n';
}
cout << ans << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
11 ms |
888 KB |
Output is correct |
3 |
Correct |
10 ms |
888 KB |
Output is correct |
4 |
Correct |
5 ms |
376 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 |
376 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 |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
6 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 |
1012 KB |
Output is correct |
17 |
Correct |
63 ms |
5104 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
4 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
4 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
382 ms |
17108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
545 ms |
40616 KB |
Output is correct |
3 |
Correct |
541 ms |
40636 KB |
Output is correct |
4 |
Correct |
528 ms |
61436 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
545 ms |
40616 KB |
Output is correct |
3 |
Correct |
541 ms |
40636 KB |
Output is correct |
4 |
Correct |
528 ms |
61436 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
550 ms |
67008 KB |
Output is correct |
7 |
Correct |
555 ms |
77688 KB |
Output is correct |
8 |
Correct |
545 ms |
61504 KB |
Output is correct |
9 |
Correct |
605 ms |
77792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
545 ms |
40616 KB |
Output is correct |
3 |
Correct |
541 ms |
40636 KB |
Output is correct |
4 |
Correct |
528 ms |
61436 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
59 ms |
8680 KB |
Output is correct |
7 |
Correct |
62 ms |
8680 KB |
Output is correct |
8 |
Correct |
59 ms |
8680 KB |
Output is correct |
9 |
Correct |
59 ms |
8680 KB |
Output is correct |
10 |
Correct |
58 ms |
8680 KB |
Output is correct |
11 |
Correct |
60 ms |
8680 KB |
Output is correct |
12 |
Correct |
61 ms |
8680 KB |
Output is correct |
13 |
Correct |
63 ms |
8680 KB |
Output is correct |
14 |
Correct |
58 ms |
8688 KB |
Output is correct |
15 |
Correct |
61 ms |
8744 KB |
Output is correct |
16 |
Correct |
64 ms |
8680 KB |
Output is correct |
17 |
Correct |
59 ms |
8752 KB |
Output is correct |
18 |
Correct |
536 ms |
66020 KB |
Output is correct |
19 |
Correct |
540 ms |
75516 KB |
Output is correct |
20 |
Correct |
584 ms |
66276 KB |
Output is correct |
21 |
Correct |
63 ms |
8680 KB |
Output is correct |
22 |
Correct |
55 ms |
8680 KB |
Output is correct |
23 |
Correct |
175 ms |
18504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
60 ms |
4972 KB |
Output is correct |
3 |
Correct |
60 ms |
4968 KB |
Output is correct |
4 |
Correct |
609 ms |
40596 KB |
Output is correct |
5 |
Correct |
73 ms |
5124 KB |
Output is correct |
6 |
Correct |
58 ms |
4968 KB |
Output is correct |
7 |
Correct |
60 ms |
4968 KB |
Output is correct |
8 |
Correct |
69 ms |
5252 KB |
Output is correct |
9 |
Correct |
60 ms |
4968 KB |
Output is correct |
10 |
Correct |
60 ms |
4972 KB |
Output is correct |
11 |
Correct |
63 ms |
4972 KB |
Output is correct |
12 |
Correct |
55 ms |
4968 KB |
Output is correct |
13 |
Correct |
60 ms |
4964 KB |
Output is correct |
14 |
Correct |
580 ms |
40636 KB |
Output is correct |
15 |
Correct |
58 ms |
4968 KB |
Output is correct |
16 |
Correct |
549 ms |
40640 KB |
Output is correct |
17 |
Correct |
525 ms |
40768 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
11 ms |
888 KB |
Output is correct |
3 |
Correct |
10 ms |
888 KB |
Output is correct |
4 |
Correct |
5 ms |
376 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 |
376 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 |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
6 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 |
1012 KB |
Output is correct |
17 |
Correct |
63 ms |
5104 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 |
4 ms |
376 KB |
Output is correct |
22 |
Correct |
5 ms |
256 KB |
Output is correct |
23 |
Correct |
4 ms |
376 KB |
Output is correct |
24 |
Correct |
5 ms |
376 KB |
Output is correct |
25 |
Correct |
5 ms |
376 KB |
Output is correct |
26 |
Correct |
5 ms |
376 KB |
Output is correct |
27 |
Correct |
5 ms |
376 KB |
Output is correct |
28 |
Correct |
382 ms |
17108 KB |
Output is correct |
29 |
Correct |
5 ms |
376 KB |
Output is correct |
30 |
Correct |
545 ms |
40616 KB |
Output is correct |
31 |
Correct |
541 ms |
40636 KB |
Output is correct |
32 |
Correct |
528 ms |
61436 KB |
Output is correct |
33 |
Correct |
5 ms |
376 KB |
Output is correct |
34 |
Correct |
550 ms |
67008 KB |
Output is correct |
35 |
Correct |
555 ms |
77688 KB |
Output is correct |
36 |
Correct |
545 ms |
61504 KB |
Output is correct |
37 |
Correct |
605 ms |
77792 KB |
Output is correct |
38 |
Correct |
5 ms |
376 KB |
Output is correct |
39 |
Correct |
59 ms |
8680 KB |
Output is correct |
40 |
Correct |
62 ms |
8680 KB |
Output is correct |
41 |
Correct |
59 ms |
8680 KB |
Output is correct |
42 |
Correct |
59 ms |
8680 KB |
Output is correct |
43 |
Correct |
58 ms |
8680 KB |
Output is correct |
44 |
Correct |
60 ms |
8680 KB |
Output is correct |
45 |
Correct |
61 ms |
8680 KB |
Output is correct |
46 |
Correct |
63 ms |
8680 KB |
Output is correct |
47 |
Correct |
58 ms |
8688 KB |
Output is correct |
48 |
Correct |
61 ms |
8744 KB |
Output is correct |
49 |
Correct |
64 ms |
8680 KB |
Output is correct |
50 |
Correct |
59 ms |
8752 KB |
Output is correct |
51 |
Correct |
536 ms |
66020 KB |
Output is correct |
52 |
Correct |
540 ms |
75516 KB |
Output is correct |
53 |
Correct |
584 ms |
66276 KB |
Output is correct |
54 |
Correct |
63 ms |
8680 KB |
Output is correct |
55 |
Correct |
55 ms |
8680 KB |
Output is correct |
56 |
Correct |
175 ms |
18504 KB |
Output is correct |
57 |
Correct |
5 ms |
376 KB |
Output is correct |
58 |
Correct |
60 ms |
4972 KB |
Output is correct |
59 |
Correct |
60 ms |
4968 KB |
Output is correct |
60 |
Correct |
609 ms |
40596 KB |
Output is correct |
61 |
Correct |
73 ms |
5124 KB |
Output is correct |
62 |
Correct |
58 ms |
4968 KB |
Output is correct |
63 |
Correct |
60 ms |
4968 KB |
Output is correct |
64 |
Correct |
69 ms |
5252 KB |
Output is correct |
65 |
Correct |
60 ms |
4968 KB |
Output is correct |
66 |
Correct |
60 ms |
4972 KB |
Output is correct |
67 |
Correct |
63 ms |
4972 KB |
Output is correct |
68 |
Correct |
55 ms |
4968 KB |
Output is correct |
69 |
Correct |
60 ms |
4964 KB |
Output is correct |
70 |
Correct |
580 ms |
40636 KB |
Output is correct |
71 |
Correct |
58 ms |
4968 KB |
Output is correct |
72 |
Correct |
549 ms |
40640 KB |
Output is correct |
73 |
Correct |
525 ms |
40768 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 |
380 KB |
Output is correct |
78 |
Correct |
5 ms |
376 KB |
Output is correct |
79 |
Correct |
11 ms |
1272 KB |
Output is correct |
80 |
Correct |
629 ms |
62760 KB |
Output is correct |
81 |
Correct |
620 ms |
61336 KB |
Output is correct |
82 |
Correct |
571 ms |
68996 KB |
Output is correct |
83 |
Correct |
594 ms |
68832 KB |
Output is correct |
84 |
Correct |
599 ms |
66880 KB |
Output is correct |
85 |
Correct |
586 ms |
77756 KB |
Output is correct |
86 |
Correct |
178 ms |
18528 KB |
Output is correct |
87 |
Correct |
5 ms |
376 KB |
Output is correct |