/*
_________ .---""" """---.
:______.-': : .--------------. :
| ______ | | : : |
|:______B:| | | Little Error: | |
|:______B:| | | | |
|:______B:| | | Power not | |
| | | | found. | |
|:_____: | | | | |
| == | | : : |
| O | : '--------------' :
| o | :'---...______...---'
| o |-._.-i___/' \._
|'-.____o_| '-. '-...______...-' `-._
:_________: `.____________________ `-.___.-.
.'.eeeeeeeeeeeeeeeeee.'. :___:
fsc .'.eeeeeeeeeeeeeeeeeeeeee.'.
:____________________________:
*/
//in the name of god
//if you read this code please search about imam hussain
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define endl "\n"
#define X first
#define Y second
#define pii pair<ll,ll>
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define read freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout)
const int maxn=2e5+5;
const int mod=1e9+7;
const ll inf=1e18;
const int del=728729;
const int Pr2 = 1030294297 ;
ll poww(ll a, ll b, ll md) {return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));}
ll gcd(ll a, ll b) {
if (b == 0){
return a;
}
return gcd(b, a % b);
}
set<pii> st ;
ll n ;
ll a ;
ll b ;
ll l ;
ll r ;
ll lp ;
ll rp ;
ll ans ;
ll p ;
ll w ;
ll k ;
int main(){
migmig ;
cin >> n >> a >> b ;
if(a/gcd(a , b + 1) > inf / b){
p = inf ;
}else{
p = a / gcd(a , b + 1) * b ;
}
for(int tst=0 ; tst< n ; tst++){
cin>>l>>r ;
if(k){
continue ;
}
if(r - l + 1 >= p ){
k = 1 ;
ans = p ;
continue ;
}
l = l % p ;
r = r % p ;
if(r >= l){
st.insert({l , r}) ;
}else{
st.insert({0 , r}) ;
st.insert({l , p - 1}) ;
}
}
if(k){
cout<<ans ;
return 0;
}
st.insert({inf + 1 , inf + 1}) ;
lp = st.begin() -> X ;
rp = st.begin() -> Y ;
//cout<<lp <<" " << rp ;
auto it = next(st.begin()) ;
while(it != st.end()){
if(it -> X > rp){
//cout<<lp <<" " << rp ;
ans += rp - lp + 1 ;
lp = it -> X;
rp = it -> Y ;
//cout<<lp <<" " << rp ;
}else{
rp = max(1LL*rp ,1LL* it -> Y) ;
//cout<<lp <<" " << rp ;
}
it++ ;
}
cout<<ans << endl ;
return 0 ;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
6 ms |
1004 KB |
Output is correct |
3 |
Correct |
6 ms |
1004 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
0 ms |
364 KB |
Output is correct |
12 |
Correct |
0 ms |
364 KB |
Output is correct |
13 |
Correct |
0 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
6 ms |
1004 KB |
Output is correct |
17 |
Correct |
63 ms |
6636 KB |
Output is correct |
18 |
Correct |
0 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
396 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
291 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
653 ms |
63072 KB |
Output is correct |
3 |
Correct |
662 ms |
62956 KB |
Output is correct |
4 |
Correct |
671 ms |
72556 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
653 ms |
63072 KB |
Output is correct |
3 |
Correct |
662 ms |
62956 KB |
Output is correct |
4 |
Correct |
671 ms |
72556 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
668 ms |
72556 KB |
Output is correct |
7 |
Correct |
678 ms |
72428 KB |
Output is correct |
8 |
Correct |
669 ms |
72556 KB |
Output is correct |
9 |
Correct |
692 ms |
72428 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
653 ms |
63072 KB |
Output is correct |
3 |
Correct |
662 ms |
62956 KB |
Output is correct |
4 |
Correct |
671 ms |
72556 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
66 ms |
10348 KB |
Output is correct |
7 |
Correct |
67 ms |
10348 KB |
Output is correct |
8 |
Correct |
63 ms |
10476 KB |
Output is correct |
9 |
Correct |
65 ms |
10348 KB |
Output is correct |
10 |
Correct |
62 ms |
10476 KB |
Output is correct |
11 |
Correct |
64 ms |
10348 KB |
Output is correct |
12 |
Correct |
69 ms |
10348 KB |
Output is correct |
13 |
Correct |
64 ms |
10368 KB |
Output is correct |
14 |
Correct |
64 ms |
10348 KB |
Output is correct |
15 |
Correct |
68 ms |
10348 KB |
Output is correct |
16 |
Correct |
69 ms |
10368 KB |
Output is correct |
17 |
Correct |
66 ms |
10360 KB |
Output is correct |
18 |
Correct |
666 ms |
73608 KB |
Output is correct |
19 |
Correct |
671 ms |
81388 KB |
Output is correct |
20 |
Correct |
690 ms |
73196 KB |
Output is correct |
21 |
Correct |
64 ms |
10476 KB |
Output is correct |
22 |
Correct |
66 ms |
10476 KB |
Output is correct |
23 |
Correct |
138 ms |
12920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
64 ms |
6636 KB |
Output is correct |
3 |
Correct |
69 ms |
6636 KB |
Output is correct |
4 |
Correct |
690 ms |
78700 KB |
Output is correct |
5 |
Correct |
65 ms |
10348 KB |
Output is correct |
6 |
Correct |
66 ms |
10348 KB |
Output is correct |
7 |
Correct |
67 ms |
10348 KB |
Output is correct |
8 |
Correct |
68 ms |
10348 KB |
Output is correct |
9 |
Correct |
65 ms |
10348 KB |
Output is correct |
10 |
Correct |
64 ms |
10476 KB |
Output is correct |
11 |
Correct |
65 ms |
10348 KB |
Output is correct |
12 |
Correct |
64 ms |
10348 KB |
Output is correct |
13 |
Correct |
65 ms |
10348 KB |
Output is correct |
14 |
Correct |
695 ms |
78624 KB |
Output is correct |
15 |
Correct |
65 ms |
10348 KB |
Output is correct |
16 |
Correct |
667 ms |
73352 KB |
Output is correct |
17 |
Correct |
655 ms |
73332 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
6 ms |
1004 KB |
Output is correct |
3 |
Correct |
6 ms |
1004 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
0 ms |
364 KB |
Output is correct |
12 |
Correct |
0 ms |
364 KB |
Output is correct |
13 |
Correct |
0 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
6 ms |
1004 KB |
Output is correct |
17 |
Correct |
63 ms |
6636 KB |
Output is correct |
18 |
Correct |
0 ms |
364 KB |
Output is correct |
19 |
Correct |
0 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
0 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
0 ms |
364 KB |
Output is correct |
24 |
Correct |
0 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
396 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
1 ms |
364 KB |
Output is correct |
28 |
Correct |
291 ms |
492 KB |
Output is correct |
29 |
Correct |
1 ms |
364 KB |
Output is correct |
30 |
Correct |
653 ms |
63072 KB |
Output is correct |
31 |
Correct |
662 ms |
62956 KB |
Output is correct |
32 |
Correct |
671 ms |
72556 KB |
Output is correct |
33 |
Correct |
1 ms |
364 KB |
Output is correct |
34 |
Correct |
668 ms |
72556 KB |
Output is correct |
35 |
Correct |
678 ms |
72428 KB |
Output is correct |
36 |
Correct |
669 ms |
72556 KB |
Output is correct |
37 |
Correct |
692 ms |
72428 KB |
Output is correct |
38 |
Correct |
1 ms |
364 KB |
Output is correct |
39 |
Correct |
66 ms |
10348 KB |
Output is correct |
40 |
Correct |
67 ms |
10348 KB |
Output is correct |
41 |
Correct |
63 ms |
10476 KB |
Output is correct |
42 |
Correct |
65 ms |
10348 KB |
Output is correct |
43 |
Correct |
62 ms |
10476 KB |
Output is correct |
44 |
Correct |
64 ms |
10348 KB |
Output is correct |
45 |
Correct |
69 ms |
10348 KB |
Output is correct |
46 |
Correct |
64 ms |
10368 KB |
Output is correct |
47 |
Correct |
64 ms |
10348 KB |
Output is correct |
48 |
Correct |
68 ms |
10348 KB |
Output is correct |
49 |
Correct |
69 ms |
10368 KB |
Output is correct |
50 |
Correct |
66 ms |
10360 KB |
Output is correct |
51 |
Correct |
666 ms |
73608 KB |
Output is correct |
52 |
Correct |
671 ms |
81388 KB |
Output is correct |
53 |
Correct |
690 ms |
73196 KB |
Output is correct |
54 |
Correct |
64 ms |
10476 KB |
Output is correct |
55 |
Correct |
66 ms |
10476 KB |
Output is correct |
56 |
Correct |
138 ms |
12920 KB |
Output is correct |
57 |
Correct |
1 ms |
492 KB |
Output is correct |
58 |
Correct |
64 ms |
6636 KB |
Output is correct |
59 |
Correct |
69 ms |
6636 KB |
Output is correct |
60 |
Correct |
690 ms |
78700 KB |
Output is correct |
61 |
Correct |
65 ms |
10348 KB |
Output is correct |
62 |
Correct |
66 ms |
10348 KB |
Output is correct |
63 |
Correct |
67 ms |
10348 KB |
Output is correct |
64 |
Correct |
68 ms |
10348 KB |
Output is correct |
65 |
Correct |
65 ms |
10348 KB |
Output is correct |
66 |
Correct |
64 ms |
10476 KB |
Output is correct |
67 |
Correct |
65 ms |
10348 KB |
Output is correct |
68 |
Correct |
64 ms |
10348 KB |
Output is correct |
69 |
Correct |
65 ms |
10348 KB |
Output is correct |
70 |
Correct |
695 ms |
78624 KB |
Output is correct |
71 |
Correct |
65 ms |
10348 KB |
Output is correct |
72 |
Correct |
667 ms |
73352 KB |
Output is correct |
73 |
Correct |
655 ms |
73332 KB |
Output is correct |
74 |
Correct |
1 ms |
364 KB |
Output is correct |
75 |
Correct |
1 ms |
364 KB |
Output is correct |
76 |
Correct |
1 ms |
364 KB |
Output is correct |
77 |
Correct |
1 ms |
364 KB |
Output is correct |
78 |
Correct |
1 ms |
364 KB |
Output is correct |
79 |
Correct |
7 ms |
1388 KB |
Output is correct |
80 |
Correct |
680 ms |
77240 KB |
Output is correct |
81 |
Correct |
703 ms |
77164 KB |
Output is correct |
82 |
Correct |
708 ms |
77308 KB |
Output is correct |
83 |
Correct |
702 ms |
95336 KB |
Output is correct |
84 |
Correct |
738 ms |
81772 KB |
Output is correct |
85 |
Correct |
692 ms |
81516 KB |
Output is correct |
86 |
Correct |
128 ms |
12928 KB |
Output is correct |
87 |
Correct |
1 ms |
364 KB |
Output is correct |