#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define FOR(i,l,r) for(ll i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,l,r) for(ll i=r-1;i>=l;i--)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define PA pair<ll,ll>
#define F first
#define S second
#define BS(A,x) binary_search(ALL(A),x)
#define LB(A,x) (ll)(lower_bound(ALL(A),x)-A.begin())
#define UB(A,x) (ll)(upper_bound(ALL(A),x)-A.begin())
#define COU(A,x) (UB(A,x)-LB(A,x))
#define sz(c) ((ll)(c).size())
template<typename T>using min_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<class T>bool chmax(T&a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T&a,T b){if(b<a){a=b;return 1;}return 0;}
template<class T>void print(vector<T>A){REP(i,A.size()){if(i)cout<<" ";cout<<A[i];}cout<<endl;}
ld dist(ld x1,ld y1,ld x2,ld y2){return sqrtl((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));}
//const ll mod=1000000007;
//const ll mod=998244353;
int main(){
ll N,A,B;cin>>N>>A>>B;
vector<PA>S;
A/=__gcd(A,B+1);
ll X=2e18;
if(B<=2e18/A)X=A*B;
REP(i,N){
ll L,R;cin>>L>>R;
if(R-L>=X){cout<<X<<endl;return 0;}
L%=X;R%=X;
if(L>R){
S.emplace_back(PA(L,X));
S.emplace_back(PA(0,R+1));
}
else S.emplace_back(PA(L,R+1));
}
set<ll>Q;
for(auto[l,r]:S)Q.insert(l),Q.insert(r);
vector<ll>R;
for(auto q:Q)R.emplace_back(q);
ll M=sz(R);
vector<ll>D(M);
for(auto[l,r]:S)D[LB(R,l)]++,D[LB(R,r)]--;
REP(i,M)D[i+1]+=D[i];
ll ans=0;
REP(i,M-1)if(D[i])ans+=R[i+1]-R[i];
cout<<ans<<endl;
return 0;
}
Compilation message
strange_device.cpp: In function 'int main()':
strange_device.cpp:42:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
42 | for(auto[l,r]:S)Q.insert(l),Q.insert(r);
| ^
strange_device.cpp:47:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
47 | for(auto[l,r]:S)D[LB(R,l)]++,D[LB(R,r)]--;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
17 ms |
1460 KB |
Output is correct |
3 |
Correct |
20 ms |
1540 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 |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
300 KB |
Output is correct |
16 |
Correct |
16 ms |
1460 KB |
Output is correct |
17 |
Correct |
218 ms |
10192 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 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 |
1 ms |
300 KB |
Output is correct |
2 |
Correct |
3 ms |
440 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
440 KB |
Output is correct |
5 |
Correct |
994 ms |
18228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1695 ms |
84052 KB |
Output is correct |
3 |
Correct |
1708 ms |
80940 KB |
Output is correct |
4 |
Correct |
1759 ms |
81972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1695 ms |
84052 KB |
Output is correct |
3 |
Correct |
1708 ms |
80940 KB |
Output is correct |
4 |
Correct |
1759 ms |
81972 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1746 ms |
82116 KB |
Output is correct |
7 |
Correct |
1690 ms |
81916 KB |
Output is correct |
8 |
Correct |
1692 ms |
81972 KB |
Output is correct |
9 |
Correct |
1851 ms |
81764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1695 ms |
84052 KB |
Output is correct |
3 |
Correct |
1708 ms |
80940 KB |
Output is correct |
4 |
Correct |
1759 ms |
81972 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
192 ms |
10152 KB |
Output is correct |
7 |
Correct |
175 ms |
10112 KB |
Output is correct |
8 |
Correct |
175 ms |
10192 KB |
Output is correct |
9 |
Correct |
181 ms |
10296 KB |
Output is correct |
10 |
Correct |
177 ms |
10388 KB |
Output is correct |
11 |
Correct |
171 ms |
10488 KB |
Output is correct |
12 |
Correct |
169 ms |
10364 KB |
Output is correct |
13 |
Correct |
180 ms |
10400 KB |
Output is correct |
14 |
Correct |
183 ms |
10428 KB |
Output is correct |
15 |
Correct |
182 ms |
10428 KB |
Output is correct |
16 |
Correct |
188 ms |
10428 KB |
Output is correct |
17 |
Correct |
182 ms |
10316 KB |
Output is correct |
18 |
Correct |
1797 ms |
82496 KB |
Output is correct |
19 |
Correct |
1888 ms |
82484 KB |
Output is correct |
20 |
Correct |
1916 ms |
82108 KB |
Output is correct |
21 |
Correct |
181 ms |
10424 KB |
Output is correct |
22 |
Correct |
172 ms |
10380 KB |
Output is correct |
23 |
Correct |
479 ms |
10416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
185 ms |
10816 KB |
Output is correct |
3 |
Correct |
190 ms |
10756 KB |
Output is correct |
4 |
Correct |
1857 ms |
81180 KB |
Output is correct |
5 |
Correct |
172 ms |
10784 KB |
Output is correct |
6 |
Correct |
174 ms |
10732 KB |
Output is correct |
7 |
Correct |
178 ms |
10692 KB |
Output is correct |
8 |
Correct |
169 ms |
10808 KB |
Output is correct |
9 |
Correct |
174 ms |
10700 KB |
Output is correct |
10 |
Correct |
159 ms |
10772 KB |
Output is correct |
11 |
Correct |
168 ms |
10804 KB |
Output is correct |
12 |
Correct |
167 ms |
10684 KB |
Output is correct |
13 |
Correct |
174 ms |
10772 KB |
Output is correct |
14 |
Correct |
1735 ms |
81480 KB |
Output is correct |
15 |
Correct |
164 ms |
10776 KB |
Output is correct |
16 |
Correct |
1649 ms |
81424 KB |
Output is correct |
17 |
Correct |
1714 ms |
85880 KB |
Output is correct |
18 |
Correct |
1 ms |
296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
17 ms |
1460 KB |
Output is correct |
3 |
Correct |
20 ms |
1540 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 |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
300 KB |
Output is correct |
16 |
Correct |
16 ms |
1460 KB |
Output is correct |
17 |
Correct |
218 ms |
10192 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 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 |
1 ms |
300 KB |
Output is correct |
25 |
Correct |
3 ms |
440 KB |
Output is correct |
26 |
Correct |
2 ms |
340 KB |
Output is correct |
27 |
Correct |
2 ms |
440 KB |
Output is correct |
28 |
Correct |
994 ms |
18228 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1695 ms |
84052 KB |
Output is correct |
31 |
Correct |
1708 ms |
80940 KB |
Output is correct |
32 |
Correct |
1759 ms |
81972 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
1746 ms |
82116 KB |
Output is correct |
35 |
Correct |
1690 ms |
81916 KB |
Output is correct |
36 |
Correct |
1692 ms |
81972 KB |
Output is correct |
37 |
Correct |
1851 ms |
81764 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
192 ms |
10152 KB |
Output is correct |
40 |
Correct |
175 ms |
10112 KB |
Output is correct |
41 |
Correct |
175 ms |
10192 KB |
Output is correct |
42 |
Correct |
181 ms |
10296 KB |
Output is correct |
43 |
Correct |
177 ms |
10388 KB |
Output is correct |
44 |
Correct |
171 ms |
10488 KB |
Output is correct |
45 |
Correct |
169 ms |
10364 KB |
Output is correct |
46 |
Correct |
180 ms |
10400 KB |
Output is correct |
47 |
Correct |
183 ms |
10428 KB |
Output is correct |
48 |
Correct |
182 ms |
10428 KB |
Output is correct |
49 |
Correct |
188 ms |
10428 KB |
Output is correct |
50 |
Correct |
182 ms |
10316 KB |
Output is correct |
51 |
Correct |
1797 ms |
82496 KB |
Output is correct |
52 |
Correct |
1888 ms |
82484 KB |
Output is correct |
53 |
Correct |
1916 ms |
82108 KB |
Output is correct |
54 |
Correct |
181 ms |
10424 KB |
Output is correct |
55 |
Correct |
172 ms |
10380 KB |
Output is correct |
56 |
Correct |
479 ms |
10416 KB |
Output is correct |
57 |
Correct |
1 ms |
212 KB |
Output is correct |
58 |
Correct |
185 ms |
10816 KB |
Output is correct |
59 |
Correct |
190 ms |
10756 KB |
Output is correct |
60 |
Correct |
1857 ms |
81180 KB |
Output is correct |
61 |
Correct |
172 ms |
10784 KB |
Output is correct |
62 |
Correct |
174 ms |
10732 KB |
Output is correct |
63 |
Correct |
178 ms |
10692 KB |
Output is correct |
64 |
Correct |
169 ms |
10808 KB |
Output is correct |
65 |
Correct |
174 ms |
10700 KB |
Output is correct |
66 |
Correct |
159 ms |
10772 KB |
Output is correct |
67 |
Correct |
168 ms |
10804 KB |
Output is correct |
68 |
Correct |
167 ms |
10684 KB |
Output is correct |
69 |
Correct |
174 ms |
10772 KB |
Output is correct |
70 |
Correct |
1735 ms |
81480 KB |
Output is correct |
71 |
Correct |
164 ms |
10776 KB |
Output is correct |
72 |
Correct |
1649 ms |
81424 KB |
Output is correct |
73 |
Correct |
1714 ms |
85880 KB |
Output is correct |
74 |
Correct |
1 ms |
296 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 |
296 KB |
Output is correct |
78 |
Correct |
1 ms |
212 KB |
Output is correct |
79 |
Correct |
16 ms |
1512 KB |
Output is correct |
80 |
Correct |
1758 ms |
79912 KB |
Output is correct |
81 |
Correct |
1765 ms |
80036 KB |
Output is correct |
82 |
Correct |
1794 ms |
80028 KB |
Output is correct |
83 |
Correct |
1734 ms |
79844 KB |
Output is correct |
84 |
Correct |
1744 ms |
79920 KB |
Output is correct |
85 |
Correct |
1741 ms |
79884 KB |
Output is correct |
86 |
Correct |
433 ms |
11568 KB |
Output is correct |
87 |
Correct |
1 ms |
212 KB |
Output is correct |