#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define Sz(x) int((x).size())
#define All(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
const int N = 1e5 + 10;
const ll INF = 1e18;
const int MOD = 1e9 + 7;
ll gcd(ll a, ll b) {
return !b ? a : gcd(b, a % b);
}
map<ll, ll> PS;
ll n, l, r, A, B, G, P, pos, ans, last;
int main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
scanf("%lld%lld%lld", &n, &A, &B);
G = gcd(A, B + 1);
P = (INF / B < A / G ? INF : A / G * B);
for(int i = 0; i < n; i++) {
scanf("%lld%lld", &l, &r);
if(r - l + 1 >= P)
return !(printf("%lld", P));
l %= P, r %= P;
if(l <= r)
PS[l]++, PS[r + 1]--;
else
PS[0]++, PS[r + 1]--, PS[l]++, PS[P]--;
}
for(auto x : PS) {
if(pos) ans += x.F - last;
pos += x.S;
if(pos) last = x.F;
}
printf("%lld", ans);
return 0;
}
Compilation message
strange_device.cpp: In function 'int main()':
strange_device.cpp:27:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
27 | scanf("%lld%lld%lld", &n, &A, &B);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
strange_device.cpp:31:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
31 | scanf("%lld%lld", &l, &r);
| ~~~~~^~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
6 ms |
852 KB |
Output is correct |
3 |
Correct |
6 ms |
852 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 |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
340 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 |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
5 ms |
852 KB |
Output is correct |
17 |
Correct |
64 ms |
6532 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 |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 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 |
246 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
634 ms |
62960 KB |
Output is correct |
3 |
Correct |
646 ms |
62880 KB |
Output is correct |
4 |
Correct |
701 ms |
63224 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
634 ms |
62960 KB |
Output is correct |
3 |
Correct |
646 ms |
62880 KB |
Output is correct |
4 |
Correct |
701 ms |
63224 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
649 ms |
63224 KB |
Output is correct |
7 |
Correct |
712 ms |
63232 KB |
Output is correct |
8 |
Correct |
638 ms |
63136 KB |
Output is correct |
9 |
Correct |
733 ms |
63184 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
634 ms |
62960 KB |
Output is correct |
3 |
Correct |
646 ms |
62880 KB |
Output is correct |
4 |
Correct |
701 ms |
63224 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
58 ms |
6696 KB |
Output is correct |
7 |
Correct |
56 ms |
6688 KB |
Output is correct |
8 |
Correct |
62 ms |
6776 KB |
Output is correct |
9 |
Correct |
65 ms |
6732 KB |
Output is correct |
10 |
Correct |
71 ms |
6768 KB |
Output is correct |
11 |
Correct |
58 ms |
6728 KB |
Output is correct |
12 |
Correct |
59 ms |
6712 KB |
Output is correct |
13 |
Correct |
64 ms |
6760 KB |
Output is correct |
14 |
Correct |
57 ms |
6668 KB |
Output is correct |
15 |
Correct |
79 ms |
6720 KB |
Output is correct |
16 |
Correct |
69 ms |
6732 KB |
Output is correct |
17 |
Correct |
69 ms |
6776 KB |
Output is correct |
18 |
Correct |
631 ms |
63076 KB |
Output is correct |
19 |
Correct |
760 ms |
63136 KB |
Output is correct |
20 |
Correct |
743 ms |
63172 KB |
Output is correct |
21 |
Correct |
73 ms |
6760 KB |
Output is correct |
22 |
Correct |
63 ms |
6716 KB |
Output is correct |
23 |
Correct |
113 ms |
500 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
69 ms |
6492 KB |
Output is correct |
3 |
Correct |
68 ms |
6748 KB |
Output is correct |
4 |
Correct |
736 ms |
63228 KB |
Output is correct |
5 |
Correct |
66 ms |
6788 KB |
Output is correct |
6 |
Correct |
71 ms |
6708 KB |
Output is correct |
7 |
Correct |
69 ms |
6676 KB |
Output is correct |
8 |
Correct |
78 ms |
6756 KB |
Output is correct |
9 |
Correct |
72 ms |
6736 KB |
Output is correct |
10 |
Correct |
62 ms |
6728 KB |
Output is correct |
11 |
Correct |
62 ms |
6744 KB |
Output is correct |
12 |
Correct |
67 ms |
6780 KB |
Output is correct |
13 |
Correct |
74 ms |
6684 KB |
Output is correct |
14 |
Correct |
1094 ms |
63096 KB |
Output is correct |
15 |
Correct |
58 ms |
6784 KB |
Output is correct |
16 |
Correct |
702 ms |
63180 KB |
Output is correct |
17 |
Correct |
684 ms |
63124 KB |
Output is correct |
18 |
Correct |
1 ms |
320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
6 ms |
852 KB |
Output is correct |
3 |
Correct |
6 ms |
852 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 |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
340 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 |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
5 ms |
852 KB |
Output is correct |
17 |
Correct |
64 ms |
6532 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 |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 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 |
246 ms |
340 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
634 ms |
62960 KB |
Output is correct |
31 |
Correct |
646 ms |
62880 KB |
Output is correct |
32 |
Correct |
701 ms |
63224 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
649 ms |
63224 KB |
Output is correct |
35 |
Correct |
712 ms |
63232 KB |
Output is correct |
36 |
Correct |
638 ms |
63136 KB |
Output is correct |
37 |
Correct |
733 ms |
63184 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
58 ms |
6696 KB |
Output is correct |
40 |
Correct |
56 ms |
6688 KB |
Output is correct |
41 |
Correct |
62 ms |
6776 KB |
Output is correct |
42 |
Correct |
65 ms |
6732 KB |
Output is correct |
43 |
Correct |
71 ms |
6768 KB |
Output is correct |
44 |
Correct |
58 ms |
6728 KB |
Output is correct |
45 |
Correct |
59 ms |
6712 KB |
Output is correct |
46 |
Correct |
64 ms |
6760 KB |
Output is correct |
47 |
Correct |
57 ms |
6668 KB |
Output is correct |
48 |
Correct |
79 ms |
6720 KB |
Output is correct |
49 |
Correct |
69 ms |
6732 KB |
Output is correct |
50 |
Correct |
69 ms |
6776 KB |
Output is correct |
51 |
Correct |
631 ms |
63076 KB |
Output is correct |
52 |
Correct |
760 ms |
63136 KB |
Output is correct |
53 |
Correct |
743 ms |
63172 KB |
Output is correct |
54 |
Correct |
73 ms |
6760 KB |
Output is correct |
55 |
Correct |
63 ms |
6716 KB |
Output is correct |
56 |
Correct |
113 ms |
500 KB |
Output is correct |
57 |
Correct |
0 ms |
212 KB |
Output is correct |
58 |
Correct |
69 ms |
6492 KB |
Output is correct |
59 |
Correct |
68 ms |
6748 KB |
Output is correct |
60 |
Correct |
736 ms |
63228 KB |
Output is correct |
61 |
Correct |
66 ms |
6788 KB |
Output is correct |
62 |
Correct |
71 ms |
6708 KB |
Output is correct |
63 |
Correct |
69 ms |
6676 KB |
Output is correct |
64 |
Correct |
78 ms |
6756 KB |
Output is correct |
65 |
Correct |
72 ms |
6736 KB |
Output is correct |
66 |
Correct |
62 ms |
6728 KB |
Output is correct |
67 |
Correct |
62 ms |
6744 KB |
Output is correct |
68 |
Correct |
67 ms |
6780 KB |
Output is correct |
69 |
Correct |
74 ms |
6684 KB |
Output is correct |
70 |
Correct |
1094 ms |
63096 KB |
Output is correct |
71 |
Correct |
58 ms |
6784 KB |
Output is correct |
72 |
Correct |
702 ms |
63180 KB |
Output is correct |
73 |
Correct |
684 ms |
63124 KB |
Output is correct |
74 |
Correct |
1 ms |
320 KB |
Output is correct |
75 |
Correct |
1 ms |
212 KB |
Output is correct |
76 |
Correct |
1 ms |
212 KB |
Output is correct |
77 |
Correct |
0 ms |
324 KB |
Output is correct |
78 |
Correct |
1 ms |
212 KB |
Output is correct |
79 |
Correct |
7 ms |
1104 KB |
Output is correct |
80 |
Correct |
818 ms |
63196 KB |
Output is correct |
81 |
Correct |
835 ms |
63216 KB |
Output is correct |
82 |
Correct |
774 ms |
63188 KB |
Output is correct |
83 |
Correct |
768 ms |
63188 KB |
Output is correct |
84 |
Correct |
865 ms |
63244 KB |
Output is correct |
85 |
Correct |
859 ms |
63256 KB |
Output is correct |
86 |
Correct |
142 ms |
500 KB |
Output is correct |
87 |
Correct |
1 ms |
212 KB |
Output is correct |