#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6 + 1,MOD = 1e9 + 7;
ll n,l[N],r[N],a,b,ans;
__int128_t A,B,cyc,inf;
vector<pair<ll,ll>> all;
void test(){
cin >> n >> a >> b;
A = a;
B = b;
for(int i = 1;i <= n;i++){
cin >> l[i] >> r[i];
}
if(n == 1){
ll x = a / gcd(a,b + 1),val = r[1] - l[1] + 1;
if(x >= (val + b - 1) / val){
cout << (x % MOD * (b % MOD)) % MOD;
return;
}
cout << val % MOD;
return;
}
cyc = A * B / (gcd(a,b + 1));
inf = r[n];
ll _ = a * b / (gcd(a,b + 1));
for(int i = 1;i <= n;i++){
l[i] %= _;
r[i] %= _;
// cout << l[i] << ' ' << r[i] << '\n';
if(r[i] >= l[i]){
all.push_back({l[i],r[i]});
continue;
}
all.push_back({0,r[i]});
all.push_back({l[i],_ - 1});
}
ll ans = 0;
sort(all.begin(),all.end());
// for(auto [x,y]:all){
// cout << x << ' ' << y << '\n';
// }
// cout << '\n';
for(int i = 0;i < all.size();i++){
ll mx = all[i].second,_l = all[i].first;
for(int j = i + 1;j < all.size();j++){
if(mx >= all[j].first){
i = j;
mx = max(mx,all[j].second);
}else break;
}
// cout << _l << ' ' << mx << ' ' << i << '\n';
ans += (mx - _l + 1) ;
}
cout << ans;
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
int T = 1;
//cin >> T;
while(T--) test();
}
Compilation message
strange_device.cpp: In function 'void test()':
strange_device.cpp:48:21: 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 < all.size();i++){
| ~~^~~~~~~~~~~~
strange_device.cpp:50:29: 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]
50 | for(int j = i + 1;j < all.size();j++){
| ~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
4 ms |
1252 KB |
Output is correct |
3 |
Correct |
4 ms |
1260 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 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 |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
4 ms |
1236 KB |
Output is correct |
17 |
Correct |
35 ms |
7728 KB |
Output is correct |
18 |
Correct |
0 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
328 KB |
Output is correct |
2 |
Correct |
1 ms |
376 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
220 ms |
57696 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
356 ms |
46336 KB |
Output is correct |
3 |
Correct |
314 ms |
69564 KB |
Output is correct |
4 |
Correct |
313 ms |
69532 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
356 ms |
46336 KB |
Output is correct |
3 |
Correct |
314 ms |
69564 KB |
Output is correct |
4 |
Correct |
313 ms |
69532 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
323 ms |
69612 KB |
Output is correct |
7 |
Correct |
325 ms |
69548 KB |
Output is correct |
8 |
Correct |
338 ms |
69592 KB |
Output is correct |
9 |
Correct |
342 ms |
69540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
356 ms |
46336 KB |
Output is correct |
3 |
Correct |
314 ms |
69564 KB |
Output is correct |
4 |
Correct |
313 ms |
69532 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
31 ms |
7752 KB |
Output is correct |
7 |
Correct |
35 ms |
7756 KB |
Output is correct |
8 |
Correct |
30 ms |
7684 KB |
Output is correct |
9 |
Correct |
32 ms |
7740 KB |
Output is correct |
10 |
Correct |
31 ms |
7784 KB |
Output is correct |
11 |
Correct |
32 ms |
7736 KB |
Output is correct |
12 |
Correct |
33 ms |
7704 KB |
Output is correct |
13 |
Correct |
33 ms |
7736 KB |
Output is correct |
14 |
Correct |
31 ms |
7704 KB |
Output is correct |
15 |
Correct |
34 ms |
7820 KB |
Output is correct |
16 |
Correct |
43 ms |
7708 KB |
Output is correct |
17 |
Correct |
33 ms |
7756 KB |
Output is correct |
18 |
Correct |
339 ms |
69508 KB |
Output is correct |
19 |
Correct |
317 ms |
69492 KB |
Output is correct |
20 |
Correct |
366 ms |
69572 KB |
Output is correct |
21 |
Correct |
35 ms |
7752 KB |
Output is correct |
22 |
Correct |
30 ms |
7768 KB |
Output is correct |
23 |
Correct |
101 ms |
26680 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
34 ms |
7708 KB |
Output is correct |
3 |
Correct |
38 ms |
7724 KB |
Output is correct |
4 |
Correct |
383 ms |
69700 KB |
Output is correct |
5 |
Correct |
40 ms |
7776 KB |
Output is correct |
6 |
Correct |
34 ms |
7748 KB |
Output is correct |
7 |
Correct |
33 ms |
7772 KB |
Output is correct |
8 |
Correct |
36 ms |
7716 KB |
Output is correct |
9 |
Correct |
34 ms |
7728 KB |
Output is correct |
10 |
Correct |
35 ms |
7752 KB |
Output is correct |
11 |
Correct |
39 ms |
7736 KB |
Output is correct |
12 |
Correct |
31 ms |
7752 KB |
Output is correct |
13 |
Correct |
41 ms |
7764 KB |
Output is correct |
14 |
Correct |
354 ms |
69532 KB |
Output is correct |
15 |
Correct |
34 ms |
7752 KB |
Output is correct |
16 |
Correct |
327 ms |
69568 KB |
Output is correct |
17 |
Correct |
339 ms |
69752 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
4 ms |
1252 KB |
Output is correct |
3 |
Correct |
4 ms |
1260 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 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 |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
4 ms |
1236 KB |
Output is correct |
17 |
Correct |
35 ms |
7728 KB |
Output is correct |
18 |
Correct |
0 ms |
332 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
0 ms |
328 KB |
Output is correct |
25 |
Correct |
1 ms |
376 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
220 ms |
57696 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
356 ms |
46336 KB |
Output is correct |
31 |
Correct |
314 ms |
69564 KB |
Output is correct |
32 |
Correct |
313 ms |
69532 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
323 ms |
69612 KB |
Output is correct |
35 |
Correct |
325 ms |
69548 KB |
Output is correct |
36 |
Correct |
338 ms |
69592 KB |
Output is correct |
37 |
Correct |
342 ms |
69540 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
31 ms |
7752 KB |
Output is correct |
40 |
Correct |
35 ms |
7756 KB |
Output is correct |
41 |
Correct |
30 ms |
7684 KB |
Output is correct |
42 |
Correct |
32 ms |
7740 KB |
Output is correct |
43 |
Correct |
31 ms |
7784 KB |
Output is correct |
44 |
Correct |
32 ms |
7736 KB |
Output is correct |
45 |
Correct |
33 ms |
7704 KB |
Output is correct |
46 |
Correct |
33 ms |
7736 KB |
Output is correct |
47 |
Correct |
31 ms |
7704 KB |
Output is correct |
48 |
Correct |
34 ms |
7820 KB |
Output is correct |
49 |
Correct |
43 ms |
7708 KB |
Output is correct |
50 |
Correct |
33 ms |
7756 KB |
Output is correct |
51 |
Correct |
339 ms |
69508 KB |
Output is correct |
52 |
Correct |
317 ms |
69492 KB |
Output is correct |
53 |
Correct |
366 ms |
69572 KB |
Output is correct |
54 |
Correct |
35 ms |
7752 KB |
Output is correct |
55 |
Correct |
30 ms |
7768 KB |
Output is correct |
56 |
Correct |
101 ms |
26680 KB |
Output is correct |
57 |
Correct |
1 ms |
332 KB |
Output is correct |
58 |
Correct |
34 ms |
7708 KB |
Output is correct |
59 |
Correct |
38 ms |
7724 KB |
Output is correct |
60 |
Correct |
383 ms |
69700 KB |
Output is correct |
61 |
Correct |
40 ms |
7776 KB |
Output is correct |
62 |
Correct |
34 ms |
7748 KB |
Output is correct |
63 |
Correct |
33 ms |
7772 KB |
Output is correct |
64 |
Correct |
36 ms |
7716 KB |
Output is correct |
65 |
Correct |
34 ms |
7728 KB |
Output is correct |
66 |
Correct |
35 ms |
7752 KB |
Output is correct |
67 |
Correct |
39 ms |
7736 KB |
Output is correct |
68 |
Correct |
31 ms |
7752 KB |
Output is correct |
69 |
Correct |
41 ms |
7764 KB |
Output is correct |
70 |
Correct |
354 ms |
69532 KB |
Output is correct |
71 |
Correct |
34 ms |
7752 KB |
Output is correct |
72 |
Correct |
327 ms |
69568 KB |
Output is correct |
73 |
Correct |
339 ms |
69752 KB |
Output is correct |
74 |
Correct |
1 ms |
340 KB |
Output is correct |
75 |
Correct |
0 ms |
340 KB |
Output is correct |
76 |
Correct |
0 ms |
336 KB |
Output is correct |
77 |
Correct |
0 ms |
212 KB |
Output is correct |
78 |
Correct |
0 ms |
212 KB |
Output is correct |
79 |
Correct |
3 ms |
1256 KB |
Output is correct |
80 |
Correct |
382 ms |
69556 KB |
Output is correct |
81 |
Correct |
386 ms |
69532 KB |
Output is correct |
82 |
Correct |
366 ms |
69272 KB |
Output is correct |
83 |
Correct |
361 ms |
69048 KB |
Output is correct |
84 |
Correct |
378 ms |
69060 KB |
Output is correct |
85 |
Correct |
356 ms |
69144 KB |
Output is correct |
86 |
Correct |
98 ms |
26468 KB |
Output is correct |
87 |
Correct |
1 ms |
340 KB |
Output is correct |