#include<bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define fi first
#define se second
#define db double
using namespace std;
int const n_max=1e6+10;
int gcd(int a,int b)
{
if(b%a==0)return a;
return gcd(b%a,a);
}
int st[n_max];
int en[n_max];
signed main()
{
cin.tie(nullptr)->sync_with_stdio(false);
int n,A,B;
cin>>n>>A>>B;
int h=gcd(min(A,B+1),max(A,B+1));
int sum=0;
for(int i=0;i<n;i++)
{
cin>>st[i]>>en[i];
sum+=en[i]-st[i]+1;
}
int val=A/h;
if((db) en[n-1]/val<= (db) B)
{
cout<<sum;
return 0;
}
val*=B;
vector<pii> keep;
for(int i=0;i<n;i++)
{
if(en[i]-st[i]+1>=val)
{
cout<<val;
return 0;
}
st[i]%=val;
en[i]%=val;
if(en[i]>=st[i])
{
keep.push_back({st[i],en[i]});
}
else
{
keep.push_back({st[i],val-1});
keep.push_back({0,en[i]});
}
}
sort(keep.begin(),keep.end());
sum=0;
int maxi=-1;
for(int i=0;i<keep.size();i++)
{
int u=keep[i].fi;
int v=keep[i].se;
if(v<=maxi)continue;
sum+=v-max(u,maxi+1)+1;
maxi=max(v,maxi);
}
cout<<sum;
return 0;
}
Compilation message
strange_device.cpp: In function 'int main()':
strange_device.cpp:58:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
58 | for(int i=0;i<keep.size();i++)
| ~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
6 ms |
1236 KB |
Output is correct |
3 |
Correct |
5 ms |
1236 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
324 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
5 ms |
1236 KB |
Output is correct |
17 |
Correct |
46 ms |
7844 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 |
1 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 |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
416 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
343 ms |
34464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
499 ms |
52808 KB |
Output is correct |
3 |
Correct |
420 ms |
34512 KB |
Output is correct |
4 |
Correct |
426 ms |
46804 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
499 ms |
52808 KB |
Output is correct |
3 |
Correct |
420 ms |
34512 KB |
Output is correct |
4 |
Correct |
426 ms |
46804 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
426 ms |
46724 KB |
Output is correct |
7 |
Correct |
432 ms |
46240 KB |
Output is correct |
8 |
Correct |
436 ms |
46656 KB |
Output is correct |
9 |
Correct |
435 ms |
46144 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
499 ms |
52808 KB |
Output is correct |
3 |
Correct |
420 ms |
34512 KB |
Output is correct |
4 |
Correct |
426 ms |
46804 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
56 ms |
7720 KB |
Output is correct |
7 |
Correct |
44 ms |
7728 KB |
Output is correct |
8 |
Correct |
44 ms |
7680 KB |
Output is correct |
9 |
Correct |
54 ms |
7752 KB |
Output is correct |
10 |
Correct |
43 ms |
7732 KB |
Output is correct |
11 |
Correct |
45 ms |
7784 KB |
Output is correct |
12 |
Correct |
41 ms |
7788 KB |
Output is correct |
13 |
Correct |
45 ms |
7780 KB |
Output is correct |
14 |
Correct |
42 ms |
7800 KB |
Output is correct |
15 |
Correct |
46 ms |
7756 KB |
Output is correct |
16 |
Correct |
48 ms |
7752 KB |
Output is correct |
17 |
Correct |
42 ms |
7912 KB |
Output is correct |
18 |
Correct |
470 ms |
46736 KB |
Output is correct |
19 |
Correct |
445 ms |
46760 KB |
Output is correct |
20 |
Correct |
468 ms |
46612 KB |
Output is correct |
21 |
Correct |
45 ms |
7720 KB |
Output is correct |
22 |
Correct |
39 ms |
7728 KB |
Output is correct |
23 |
Correct |
142 ms |
26604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
44 ms |
7744 KB |
Output is correct |
3 |
Correct |
45 ms |
7764 KB |
Output is correct |
4 |
Correct |
518 ms |
45148 KB |
Output is correct |
5 |
Correct |
49 ms |
7772 KB |
Output is correct |
6 |
Correct |
57 ms |
7752 KB |
Output is correct |
7 |
Correct |
48 ms |
7688 KB |
Output is correct |
8 |
Correct |
54 ms |
7752 KB |
Output is correct |
9 |
Correct |
46 ms |
7712 KB |
Output is correct |
10 |
Correct |
47 ms |
7732 KB |
Output is correct |
11 |
Correct |
44 ms |
7788 KB |
Output is correct |
12 |
Correct |
38 ms |
7704 KB |
Output is correct |
13 |
Correct |
44 ms |
7736 KB |
Output is correct |
14 |
Correct |
501 ms |
45156 KB |
Output is correct |
15 |
Correct |
62 ms |
7792 KB |
Output is correct |
16 |
Correct |
470 ms |
46564 KB |
Output is correct |
17 |
Correct |
436 ms |
46576 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
6 ms |
1236 KB |
Output is correct |
3 |
Correct |
5 ms |
1236 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
324 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
5 ms |
1236 KB |
Output is correct |
17 |
Correct |
46 ms |
7844 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 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 |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
416 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
343 ms |
34464 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
499 ms |
52808 KB |
Output is correct |
31 |
Correct |
420 ms |
34512 KB |
Output is correct |
32 |
Correct |
426 ms |
46804 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
426 ms |
46724 KB |
Output is correct |
35 |
Correct |
432 ms |
46240 KB |
Output is correct |
36 |
Correct |
436 ms |
46656 KB |
Output is correct |
37 |
Correct |
435 ms |
46144 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
56 ms |
7720 KB |
Output is correct |
40 |
Correct |
44 ms |
7728 KB |
Output is correct |
41 |
Correct |
44 ms |
7680 KB |
Output is correct |
42 |
Correct |
54 ms |
7752 KB |
Output is correct |
43 |
Correct |
43 ms |
7732 KB |
Output is correct |
44 |
Correct |
45 ms |
7784 KB |
Output is correct |
45 |
Correct |
41 ms |
7788 KB |
Output is correct |
46 |
Correct |
45 ms |
7780 KB |
Output is correct |
47 |
Correct |
42 ms |
7800 KB |
Output is correct |
48 |
Correct |
46 ms |
7756 KB |
Output is correct |
49 |
Correct |
48 ms |
7752 KB |
Output is correct |
50 |
Correct |
42 ms |
7912 KB |
Output is correct |
51 |
Correct |
470 ms |
46736 KB |
Output is correct |
52 |
Correct |
445 ms |
46760 KB |
Output is correct |
53 |
Correct |
468 ms |
46612 KB |
Output is correct |
54 |
Correct |
45 ms |
7720 KB |
Output is correct |
55 |
Correct |
39 ms |
7728 KB |
Output is correct |
56 |
Correct |
142 ms |
26604 KB |
Output is correct |
57 |
Correct |
1 ms |
340 KB |
Output is correct |
58 |
Correct |
44 ms |
7744 KB |
Output is correct |
59 |
Correct |
45 ms |
7764 KB |
Output is correct |
60 |
Correct |
518 ms |
45148 KB |
Output is correct |
61 |
Correct |
49 ms |
7772 KB |
Output is correct |
62 |
Correct |
57 ms |
7752 KB |
Output is correct |
63 |
Correct |
48 ms |
7688 KB |
Output is correct |
64 |
Correct |
54 ms |
7752 KB |
Output is correct |
65 |
Correct |
46 ms |
7712 KB |
Output is correct |
66 |
Correct |
47 ms |
7732 KB |
Output is correct |
67 |
Correct |
44 ms |
7788 KB |
Output is correct |
68 |
Correct |
38 ms |
7704 KB |
Output is correct |
69 |
Correct |
44 ms |
7736 KB |
Output is correct |
70 |
Correct |
501 ms |
45156 KB |
Output is correct |
71 |
Correct |
62 ms |
7792 KB |
Output is correct |
72 |
Correct |
470 ms |
46564 KB |
Output is correct |
73 |
Correct |
436 ms |
46576 KB |
Output is correct |
74 |
Correct |
1 ms |
212 KB |
Output is correct |
75 |
Correct |
1 ms |
212 KB |
Output is correct |
76 |
Correct |
1 ms |
332 KB |
Output is correct |
77 |
Correct |
1 ms |
328 KB |
Output is correct |
78 |
Correct |
1 ms |
212 KB |
Output is correct |
79 |
Correct |
8 ms |
1260 KB |
Output is correct |
80 |
Correct |
578 ms |
46600 KB |
Output is correct |
81 |
Correct |
560 ms |
46612 KB |
Output is correct |
82 |
Correct |
531 ms |
46720 KB |
Output is correct |
83 |
Correct |
495 ms |
46596 KB |
Output is correct |
84 |
Correct |
515 ms |
46584 KB |
Output is correct |
85 |
Correct |
499 ms |
46724 KB |
Output is correct |
86 |
Correct |
151 ms |
26456 KB |
Output is correct |
87 |
Correct |
1 ms |
328 KB |
Output is correct |