#include<bits/stdc++.h>
#define MAXN 1000007
using namespace std;
const long long inf=1e18+7;
int n;
pair<long long,long long> p[MAXN];
long long A,B;
vector< pair<long long,long long> > v;
long long ans,last;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>A>>B;
long long cycle=A/__gcd(A,B+1);
if(cycle>inf/B)cycle=inf;
else cycle*=B;
for(int i=1;i<=n;i++){
cin>>p[i].first>>p[i].second;
if(p[i].second-p[i].first+1>=cycle){
cout<<cycle<<"\n";
return 0;
}
p[i].first%=cycle; p[i].second%=cycle;
if(p[i].first<=p[i].second){
v.push_back({p[i].first,p[i].second});
}else{
v.push_back({0,p[i].second});
v.push_back({p[i].first,cycle-1});
}
}
sort(v.begin(),v.end());
last=-1;
for(int i=0;i<v.size();i++){
ans+=max(0LL , v[i].second-max(v[i].first-1,last));
last=max(last,v[i].second);
}
cout<<ans<<"\n";
return 0;
}
Compilation message
strange_device.cpp: In function 'int main()':
strange_device.cpp:48:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
48 | for(int i=0;i<v.size();i++){
| ~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
4 ms |
1248 KB |
Output is correct |
3 |
Correct |
4 ms |
1248 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
1248 KB |
Output is correct |
17 |
Correct |
35 ms |
7296 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
211 ms |
57032 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
287 ms |
68980 KB |
Output is correct |
3 |
Correct |
287 ms |
68804 KB |
Output is correct |
4 |
Correct |
286 ms |
69020 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
287 ms |
68980 KB |
Output is correct |
3 |
Correct |
287 ms |
68804 KB |
Output is correct |
4 |
Correct |
286 ms |
69020 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
286 ms |
68956 KB |
Output is correct |
7 |
Correct |
281 ms |
69088 KB |
Output is correct |
8 |
Correct |
285 ms |
68768 KB |
Output is correct |
9 |
Correct |
334 ms |
69000 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
287 ms |
68980 KB |
Output is correct |
3 |
Correct |
287 ms |
68804 KB |
Output is correct |
4 |
Correct |
286 ms |
69020 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
32 ms |
7336 KB |
Output is correct |
7 |
Correct |
29 ms |
7396 KB |
Output is correct |
8 |
Correct |
27 ms |
7368 KB |
Output is correct |
9 |
Correct |
35 ms |
7364 KB |
Output is correct |
10 |
Correct |
27 ms |
7372 KB |
Output is correct |
11 |
Correct |
28 ms |
7380 KB |
Output is correct |
12 |
Correct |
28 ms |
7232 KB |
Output is correct |
13 |
Correct |
30 ms |
7364 KB |
Output is correct |
14 |
Correct |
35 ms |
7368 KB |
Output is correct |
15 |
Correct |
37 ms |
7364 KB |
Output is correct |
16 |
Correct |
30 ms |
7200 KB |
Output is correct |
17 |
Correct |
31 ms |
7376 KB |
Output is correct |
18 |
Correct |
300 ms |
68960 KB |
Output is correct |
19 |
Correct |
289 ms |
68764 KB |
Output is correct |
20 |
Correct |
311 ms |
68764 KB |
Output is correct |
21 |
Correct |
32 ms |
7368 KB |
Output is correct |
22 |
Correct |
26 ms |
7372 KB |
Output is correct |
23 |
Correct |
88 ms |
23780 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
29 ms |
7404 KB |
Output is correct |
3 |
Correct |
31 ms |
7372 KB |
Output is correct |
4 |
Correct |
329 ms |
68948 KB |
Output is correct |
5 |
Correct |
31 ms |
7256 KB |
Output is correct |
6 |
Correct |
31 ms |
7376 KB |
Output is correct |
7 |
Correct |
38 ms |
7372 KB |
Output is correct |
8 |
Correct |
32 ms |
7368 KB |
Output is correct |
9 |
Correct |
34 ms |
7368 KB |
Output is correct |
10 |
Correct |
31 ms |
7372 KB |
Output is correct |
11 |
Correct |
33 ms |
7208 KB |
Output is correct |
12 |
Correct |
26 ms |
7368 KB |
Output is correct |
13 |
Correct |
37 ms |
7372 KB |
Output is correct |
14 |
Correct |
306 ms |
68900 KB |
Output is correct |
15 |
Correct |
32 ms |
7288 KB |
Output is correct |
16 |
Correct |
300 ms |
69024 KB |
Output is correct |
17 |
Correct |
291 ms |
68900 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
4 ms |
1248 KB |
Output is correct |
3 |
Correct |
4 ms |
1248 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
1248 KB |
Output is correct |
17 |
Correct |
35 ms |
7296 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
211 ms |
57032 KB |
Output is correct |
29 |
Correct |
0 ms |
344 KB |
Output is correct |
30 |
Correct |
287 ms |
68980 KB |
Output is correct |
31 |
Correct |
287 ms |
68804 KB |
Output is correct |
32 |
Correct |
286 ms |
69020 KB |
Output is correct |
33 |
Correct |
1 ms |
344 KB |
Output is correct |
34 |
Correct |
286 ms |
68956 KB |
Output is correct |
35 |
Correct |
281 ms |
69088 KB |
Output is correct |
36 |
Correct |
285 ms |
68768 KB |
Output is correct |
37 |
Correct |
334 ms |
69000 KB |
Output is correct |
38 |
Correct |
1 ms |
348 KB |
Output is correct |
39 |
Correct |
32 ms |
7336 KB |
Output is correct |
40 |
Correct |
29 ms |
7396 KB |
Output is correct |
41 |
Correct |
27 ms |
7368 KB |
Output is correct |
42 |
Correct |
35 ms |
7364 KB |
Output is correct |
43 |
Correct |
27 ms |
7372 KB |
Output is correct |
44 |
Correct |
28 ms |
7380 KB |
Output is correct |
45 |
Correct |
28 ms |
7232 KB |
Output is correct |
46 |
Correct |
30 ms |
7364 KB |
Output is correct |
47 |
Correct |
35 ms |
7368 KB |
Output is correct |
48 |
Correct |
37 ms |
7364 KB |
Output is correct |
49 |
Correct |
30 ms |
7200 KB |
Output is correct |
50 |
Correct |
31 ms |
7376 KB |
Output is correct |
51 |
Correct |
300 ms |
68960 KB |
Output is correct |
52 |
Correct |
289 ms |
68764 KB |
Output is correct |
53 |
Correct |
311 ms |
68764 KB |
Output is correct |
54 |
Correct |
32 ms |
7368 KB |
Output is correct |
55 |
Correct |
26 ms |
7372 KB |
Output is correct |
56 |
Correct |
88 ms |
23780 KB |
Output is correct |
57 |
Correct |
1 ms |
344 KB |
Output is correct |
58 |
Correct |
29 ms |
7404 KB |
Output is correct |
59 |
Correct |
31 ms |
7372 KB |
Output is correct |
60 |
Correct |
329 ms |
68948 KB |
Output is correct |
61 |
Correct |
31 ms |
7256 KB |
Output is correct |
62 |
Correct |
31 ms |
7376 KB |
Output is correct |
63 |
Correct |
38 ms |
7372 KB |
Output is correct |
64 |
Correct |
32 ms |
7368 KB |
Output is correct |
65 |
Correct |
34 ms |
7368 KB |
Output is correct |
66 |
Correct |
31 ms |
7372 KB |
Output is correct |
67 |
Correct |
33 ms |
7208 KB |
Output is correct |
68 |
Correct |
26 ms |
7368 KB |
Output is correct |
69 |
Correct |
37 ms |
7372 KB |
Output is correct |
70 |
Correct |
306 ms |
68900 KB |
Output is correct |
71 |
Correct |
32 ms |
7288 KB |
Output is correct |
72 |
Correct |
300 ms |
69024 KB |
Output is correct |
73 |
Correct |
291 ms |
68900 KB |
Output is correct |
74 |
Correct |
0 ms |
348 KB |
Output is correct |
75 |
Correct |
0 ms |
348 KB |
Output is correct |
76 |
Correct |
1 ms |
464 KB |
Output is correct |
77 |
Correct |
0 ms |
344 KB |
Output is correct |
78 |
Correct |
0 ms |
348 KB |
Output is correct |
79 |
Correct |
3 ms |
1248 KB |
Output is correct |
80 |
Correct |
321 ms |
68884 KB |
Output is correct |
81 |
Correct |
332 ms |
68900 KB |
Output is correct |
82 |
Correct |
353 ms |
68888 KB |
Output is correct |
83 |
Correct |
339 ms |
68764 KB |
Output is correct |
84 |
Correct |
308 ms |
68776 KB |
Output is correct |
85 |
Correct |
310 ms |
68808 KB |
Output is correct |
86 |
Correct |
85 ms |
23600 KB |
Output is correct |
87 |
Correct |
1 ms |
348 KB |
Output is correct |