#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define pb push_back
#define fi first
#define se second
//*AC BERSAMA ALLAH FORTIS FORTUNA ADIUVAT
//# nyampah
__int128_t sz;
vector<pair<ll,bool> > lr;
vector<pair<ll,ll> > lr1;
ll n, a, b;
ll gcd(ll x, ll y){
if(y==0) return x;
else return gcd(y,x%y);
}
bool comp(pair<ll,bool> a, pair<ll,bool> b){
if(a.fi==b.fi) return a.se<b.se;
else return a.fi<b.fi;
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> a >> b;
// sz = abs(szz(a,b));
sz = (__int128_t) a / gcd(a,b+1) * b ;
// cout<<sz<<'\n';
for(int i=0;i<n;i++){
ll l,r; cin>>l>>r;
if(r-l+1>=sz){
cout << (ll) sz << '\n';
return 0;
}
l%=sz; r%=sz;
if(l>r){
lr.pb(make_pair(0,0)); lr.pb(make_pair(r,1));
lr.pb(make_pair(l,0)); lr.pb(make_pair(sz-1,1));
}
else {
lr.pb(make_pair(l,0)); lr.pb(make_pair(r,1));
}
}
sort(lr.begin(),lr.end(),comp);
ll cnt=0, l, r;
for(auto i : lr){
if(i.se == 0){
if(cnt==0) l=i.fi;
cnt++;
}
else cnt--;
if(cnt==0){
r = i.fi;
lr1.pb(make_pair(l,r));
}
}
ll ans=0;
for(auto i : lr1){
ans+=(i.second-i.first+1);
}
cout<<ans<<'\n';
return 0;
}
Compilation message
strange_device.cpp: In function 'int main()':
strange_device.cpp:60:33: warning: 'l' may be used uninitialized in this function [-Wmaybe-uninitialized]
60 | lr1.pb(make_pair(l,r));
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
5 ms |
984 KB |
Output is correct |
3 |
Correct |
5 ms |
984 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 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 |
212 KB |
Output is correct |
16 |
Correct |
5 ms |
980 KB |
Output is correct |
17 |
Correct |
62 ms |
7032 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
358 ms |
33256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
537 ms |
63632 KB |
Output is correct |
3 |
Correct |
598 ms |
63712 KB |
Output is correct |
4 |
Correct |
533 ms |
63628 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
537 ms |
63632 KB |
Output is correct |
3 |
Correct |
598 ms |
63712 KB |
Output is correct |
4 |
Correct |
533 ms |
63628 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
570 ms |
63632 KB |
Output is correct |
7 |
Correct |
524 ms |
63696 KB |
Output is correct |
8 |
Correct |
568 ms |
63640 KB |
Output is correct |
9 |
Correct |
664 ms |
63588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
537 ms |
63632 KB |
Output is correct |
3 |
Correct |
598 ms |
63712 KB |
Output is correct |
4 |
Correct |
533 ms |
63628 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
47 ms |
7044 KB |
Output is correct |
7 |
Correct |
53 ms |
7036 KB |
Output is correct |
8 |
Correct |
47 ms |
7056 KB |
Output is correct |
9 |
Correct |
50 ms |
7048 KB |
Output is correct |
10 |
Correct |
45 ms |
6968 KB |
Output is correct |
11 |
Correct |
49 ms |
6980 KB |
Output is correct |
12 |
Correct |
46 ms |
7016 KB |
Output is correct |
13 |
Correct |
62 ms |
7048 KB |
Output is correct |
14 |
Correct |
46 ms |
6940 KB |
Output is correct |
15 |
Correct |
59 ms |
7040 KB |
Output is correct |
16 |
Correct |
68 ms |
7036 KB |
Output is correct |
17 |
Correct |
51 ms |
7040 KB |
Output is correct |
18 |
Correct |
558 ms |
63628 KB |
Output is correct |
19 |
Correct |
512 ms |
63644 KB |
Output is correct |
20 |
Correct |
663 ms |
63624 KB |
Output is correct |
21 |
Correct |
66 ms |
7040 KB |
Output is correct |
22 |
Correct |
42 ms |
7036 KB |
Output is correct |
23 |
Correct |
122 ms |
16868 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
56 ms |
7036 KB |
Output is correct |
3 |
Correct |
56 ms |
7036 KB |
Output is correct |
4 |
Correct |
690 ms |
63628 KB |
Output is correct |
5 |
Correct |
70 ms |
7040 KB |
Output is correct |
6 |
Correct |
61 ms |
7032 KB |
Output is correct |
7 |
Correct |
57 ms |
7036 KB |
Output is correct |
8 |
Correct |
64 ms |
7224 KB |
Output is correct |
9 |
Correct |
54 ms |
6968 KB |
Output is correct |
10 |
Correct |
59 ms |
7056 KB |
Output is correct |
11 |
Correct |
56 ms |
7036 KB |
Output is correct |
12 |
Correct |
49 ms |
7020 KB |
Output is correct |
13 |
Correct |
73 ms |
7040 KB |
Output is correct |
14 |
Correct |
669 ms |
63636 KB |
Output is correct |
15 |
Correct |
59 ms |
6840 KB |
Output is correct |
16 |
Correct |
497 ms |
63636 KB |
Output is correct |
17 |
Correct |
642 ms |
63632 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
5 ms |
984 KB |
Output is correct |
3 |
Correct |
5 ms |
984 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 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 |
212 KB |
Output is correct |
16 |
Correct |
5 ms |
980 KB |
Output is correct |
17 |
Correct |
62 ms |
7032 KB |
Output is correct |
18 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
320 KB |
Output is correct |
24 |
Correct |
0 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
358 ms |
33256 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
537 ms |
63632 KB |
Output is correct |
31 |
Correct |
598 ms |
63712 KB |
Output is correct |
32 |
Correct |
533 ms |
63628 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
570 ms |
63632 KB |
Output is correct |
35 |
Correct |
524 ms |
63696 KB |
Output is correct |
36 |
Correct |
568 ms |
63640 KB |
Output is correct |
37 |
Correct |
664 ms |
63588 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
47 ms |
7044 KB |
Output is correct |
40 |
Correct |
53 ms |
7036 KB |
Output is correct |
41 |
Correct |
47 ms |
7056 KB |
Output is correct |
42 |
Correct |
50 ms |
7048 KB |
Output is correct |
43 |
Correct |
45 ms |
6968 KB |
Output is correct |
44 |
Correct |
49 ms |
6980 KB |
Output is correct |
45 |
Correct |
46 ms |
7016 KB |
Output is correct |
46 |
Correct |
62 ms |
7048 KB |
Output is correct |
47 |
Correct |
46 ms |
6940 KB |
Output is correct |
48 |
Correct |
59 ms |
7040 KB |
Output is correct |
49 |
Correct |
68 ms |
7036 KB |
Output is correct |
50 |
Correct |
51 ms |
7040 KB |
Output is correct |
51 |
Correct |
558 ms |
63628 KB |
Output is correct |
52 |
Correct |
512 ms |
63644 KB |
Output is correct |
53 |
Correct |
663 ms |
63624 KB |
Output is correct |
54 |
Correct |
66 ms |
7040 KB |
Output is correct |
55 |
Correct |
42 ms |
7036 KB |
Output is correct |
56 |
Correct |
122 ms |
16868 KB |
Output is correct |
57 |
Correct |
0 ms |
212 KB |
Output is correct |
58 |
Correct |
56 ms |
7036 KB |
Output is correct |
59 |
Correct |
56 ms |
7036 KB |
Output is correct |
60 |
Correct |
690 ms |
63628 KB |
Output is correct |
61 |
Correct |
70 ms |
7040 KB |
Output is correct |
62 |
Correct |
61 ms |
7032 KB |
Output is correct |
63 |
Correct |
57 ms |
7036 KB |
Output is correct |
64 |
Correct |
64 ms |
7224 KB |
Output is correct |
65 |
Correct |
54 ms |
6968 KB |
Output is correct |
66 |
Correct |
59 ms |
7056 KB |
Output is correct |
67 |
Correct |
56 ms |
7036 KB |
Output is correct |
68 |
Correct |
49 ms |
7020 KB |
Output is correct |
69 |
Correct |
73 ms |
7040 KB |
Output is correct |
70 |
Correct |
669 ms |
63636 KB |
Output is correct |
71 |
Correct |
59 ms |
6840 KB |
Output is correct |
72 |
Correct |
497 ms |
63636 KB |
Output is correct |
73 |
Correct |
642 ms |
63632 KB |
Output is correct |
74 |
Correct |
0 ms |
212 KB |
Output is correct |
75 |
Correct |
1 ms |
212 KB |
Output is correct |
76 |
Correct |
1 ms |
212 KB |
Output is correct |
77 |
Correct |
1 ms |
212 KB |
Output is correct |
78 |
Correct |
0 ms |
212 KB |
Output is correct |
79 |
Correct |
5 ms |
1420 KB |
Output is correct |
80 |
Correct |
755 ms |
74776 KB |
Output is correct |
81 |
Correct |
730 ms |
74756 KB |
Output is correct |
82 |
Correct |
705 ms |
74792 KB |
Output is correct |
83 |
Correct |
668 ms |
74916 KB |
Output is correct |
84 |
Correct |
691 ms |
74796 KB |
Output is correct |
85 |
Correct |
679 ms |
74812 KB |
Output is correct |
86 |
Correct |
126 ms |
25576 KB |
Output is correct |
87 |
Correct |
0 ms |
324 KB |
Output is correct |