#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define int long long
const int maxn = (int)1e6+10;
int n, A, B, mod, ans;
vector<pair<int,int>> v;
int32_t main() {
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> n >> A >> B; A/=__gcd(A, B+1);
if(A<=4*maxn*maxn*maxn/B) mod = A*B;
else mod = (int)1e18+1;
for(int i = 1; i <= n; i++){
int l, r; cin >> l >> r;
if(r-l+1>=mod){cout<<mod; return 0;}
l%=mod, r%=mod;
if(l<=r) v.pb({l,r});
else v.pb({l,mod-1}), v.pb({0,r});
}
sort(v.begin(),v.end());
int l = v[0].fi, r = v[0].se;
for(auto u : v){
if(r<u.fi) ans+=r-l+1, l=u.fi,r=u.se;
else r = max(r, u.se);
}
cout << ans+r-l+1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
5 ms |
984 KB |
Output is correct |
3 |
Correct |
5 ms |
1060 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
320 KB |
Output is correct |
8 |
Correct |
1 ms |
316 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
324 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
320 KB |
Output is correct |
16 |
Correct |
6 ms |
992 KB |
Output is correct |
17 |
Correct |
50 ms |
5668 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
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 |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
320 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
298 ms |
41276 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
397 ms |
20076 KB |
Output is correct |
3 |
Correct |
413 ms |
53100 KB |
Output is correct |
4 |
Correct |
400 ms |
53192 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
397 ms |
20076 KB |
Output is correct |
3 |
Correct |
413 ms |
53100 KB |
Output is correct |
4 |
Correct |
400 ms |
53192 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
395 ms |
53328 KB |
Output is correct |
7 |
Correct |
404 ms |
53184 KB |
Output is correct |
8 |
Correct |
391 ms |
53228 KB |
Output is correct |
9 |
Correct |
432 ms |
53204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
397 ms |
20076 KB |
Output is correct |
3 |
Correct |
413 ms |
53100 KB |
Output is correct |
4 |
Correct |
400 ms |
53192 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
40 ms |
5656 KB |
Output is correct |
7 |
Correct |
43 ms |
5608 KB |
Output is correct |
8 |
Correct |
40 ms |
5712 KB |
Output is correct |
9 |
Correct |
41 ms |
5700 KB |
Output is correct |
10 |
Correct |
39 ms |
5676 KB |
Output is correct |
11 |
Correct |
40 ms |
5608 KB |
Output is correct |
12 |
Correct |
38 ms |
5660 KB |
Output is correct |
13 |
Correct |
41 ms |
5600 KB |
Output is correct |
14 |
Correct |
48 ms |
5724 KB |
Output is correct |
15 |
Correct |
48 ms |
5720 KB |
Output is correct |
16 |
Correct |
42 ms |
5696 KB |
Output is correct |
17 |
Correct |
39 ms |
5672 KB |
Output is correct |
18 |
Correct |
397 ms |
53164 KB |
Output is correct |
19 |
Correct |
385 ms |
53216 KB |
Output is correct |
20 |
Correct |
435 ms |
53076 KB |
Output is correct |
21 |
Correct |
41 ms |
5604 KB |
Output is correct |
22 |
Correct |
37 ms |
5644 KB |
Output is correct |
23 |
Correct |
123 ms |
18412 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
42 ms |
5632 KB |
Output is correct |
3 |
Correct |
41 ms |
5700 KB |
Output is correct |
4 |
Correct |
448 ms |
53288 KB |
Output is correct |
5 |
Correct |
40 ms |
5648 KB |
Output is correct |
6 |
Correct |
41 ms |
5652 KB |
Output is correct |
7 |
Correct |
40 ms |
5724 KB |
Output is correct |
8 |
Correct |
42 ms |
5656 KB |
Output is correct |
9 |
Correct |
52 ms |
5648 KB |
Output is correct |
10 |
Correct |
42 ms |
5660 KB |
Output is correct |
11 |
Correct |
41 ms |
5652 KB |
Output is correct |
12 |
Correct |
38 ms |
5696 KB |
Output is correct |
13 |
Correct |
41 ms |
5708 KB |
Output is correct |
14 |
Correct |
430 ms |
53312 KB |
Output is correct |
15 |
Correct |
40 ms |
5636 KB |
Output is correct |
16 |
Correct |
392 ms |
53232 KB |
Output is correct |
17 |
Correct |
392 ms |
53184 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
5 ms |
984 KB |
Output is correct |
3 |
Correct |
5 ms |
1060 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
320 KB |
Output is correct |
8 |
Correct |
1 ms |
316 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
324 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
320 KB |
Output is correct |
16 |
Correct |
6 ms |
992 KB |
Output is correct |
17 |
Correct |
50 ms |
5668 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
0 ms |
320 KB |
Output is correct |
25 |
Correct |
1 ms |
328 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
298 ms |
41276 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
397 ms |
20076 KB |
Output is correct |
31 |
Correct |
413 ms |
53100 KB |
Output is correct |
32 |
Correct |
400 ms |
53192 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
395 ms |
53328 KB |
Output is correct |
35 |
Correct |
404 ms |
53184 KB |
Output is correct |
36 |
Correct |
391 ms |
53228 KB |
Output is correct |
37 |
Correct |
432 ms |
53204 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
40 ms |
5656 KB |
Output is correct |
40 |
Correct |
43 ms |
5608 KB |
Output is correct |
41 |
Correct |
40 ms |
5712 KB |
Output is correct |
42 |
Correct |
41 ms |
5700 KB |
Output is correct |
43 |
Correct |
39 ms |
5676 KB |
Output is correct |
44 |
Correct |
40 ms |
5608 KB |
Output is correct |
45 |
Correct |
38 ms |
5660 KB |
Output is correct |
46 |
Correct |
41 ms |
5600 KB |
Output is correct |
47 |
Correct |
48 ms |
5724 KB |
Output is correct |
48 |
Correct |
48 ms |
5720 KB |
Output is correct |
49 |
Correct |
42 ms |
5696 KB |
Output is correct |
50 |
Correct |
39 ms |
5672 KB |
Output is correct |
51 |
Correct |
397 ms |
53164 KB |
Output is correct |
52 |
Correct |
385 ms |
53216 KB |
Output is correct |
53 |
Correct |
435 ms |
53076 KB |
Output is correct |
54 |
Correct |
41 ms |
5604 KB |
Output is correct |
55 |
Correct |
37 ms |
5644 KB |
Output is correct |
56 |
Correct |
123 ms |
18412 KB |
Output is correct |
57 |
Correct |
0 ms |
212 KB |
Output is correct |
58 |
Correct |
42 ms |
5632 KB |
Output is correct |
59 |
Correct |
41 ms |
5700 KB |
Output is correct |
60 |
Correct |
448 ms |
53288 KB |
Output is correct |
61 |
Correct |
40 ms |
5648 KB |
Output is correct |
62 |
Correct |
41 ms |
5652 KB |
Output is correct |
63 |
Correct |
40 ms |
5724 KB |
Output is correct |
64 |
Correct |
42 ms |
5656 KB |
Output is correct |
65 |
Correct |
52 ms |
5648 KB |
Output is correct |
66 |
Correct |
42 ms |
5660 KB |
Output is correct |
67 |
Correct |
41 ms |
5652 KB |
Output is correct |
68 |
Correct |
38 ms |
5696 KB |
Output is correct |
69 |
Correct |
41 ms |
5708 KB |
Output is correct |
70 |
Correct |
430 ms |
53312 KB |
Output is correct |
71 |
Correct |
40 ms |
5636 KB |
Output is correct |
72 |
Correct |
392 ms |
53232 KB |
Output is correct |
73 |
Correct |
392 ms |
53184 KB |
Output is correct |
74 |
Correct |
1 ms |
212 KB |
Output is correct |
75 |
Correct |
0 ms |
212 KB |
Output is correct |
76 |
Correct |
1 ms |
212 KB |
Output is correct |
77 |
Correct |
1 ms |
320 KB |
Output is correct |
78 |
Correct |
0 ms |
212 KB |
Output is correct |
79 |
Correct |
5 ms |
984 KB |
Output is correct |
80 |
Correct |
448 ms |
53088 KB |
Output is correct |
81 |
Correct |
463 ms |
53244 KB |
Output is correct |
82 |
Correct |
433 ms |
53080 KB |
Output is correct |
83 |
Correct |
429 ms |
52956 KB |
Output is correct |
84 |
Correct |
445 ms |
52620 KB |
Output is correct |
85 |
Correct |
433 ms |
52636 KB |
Output is correct |
86 |
Correct |
125 ms |
18416 KB |
Output is correct |
87 |
Correct |
1 ms |
212 KB |
Output is correct |