#include<bits/stdc++.h>
#define TASKNAME "codeforce"
#define pb push_back
#define pli pair<ll,ll>
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
using ll=long long;
const ll maxN=2e5;
const ll inf=3e18;
const ll mod=1e9+7;
ll n,A,B;
vector<pli>vec;
void solve()
{
cin >> n >> A >> B;
ll x=(A/__gcd(A,B+1))*B;
bool ok=true;
ll sum=0;
for(int i=1;i<=n;i++)
{
ll l,r;
cin >> l >> r;
sum+=r-l+1;
if((r-l+1)>=x)
{
ok=false;
}
l%=x;
r%=x;
if(l<=r)
{
vec.pb({l,r});
}
else
{
vec.pb({l,x-1});
vec.pb({0,r});
}
}
ll cc=A/(__gcd(A,B+1));
if(inf/cc<B)
{
cout << sum;
return;
}
if(ok==false)
{
cout << x;
return;
}
sort(vec.begin(),vec.end());
ll s = 0, hi = -1;
for(int i = 0; i < vec.size(); i++){
if(vec[i].fi > hi){
s += (vec[i].se - vec[i].fi + 1);
hi = vec[i].se;
}
else
{
s+=max(0ll,vec[i].se-hi);
hi=max(hi,vec[i].se);
}
}
cout << s << "\n";
}
int main()
{
fastio
//freopen(TASKNAME".INP","r",stdin);
//freopen(TASKNAME".OUT","w",stdout);
solve();
}
Compilation message
strange_device.cpp: In function 'void solve()':
strange_device.cpp:55:22: 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]
55 | for(int i = 0; i < vec.size(); i++){
| ~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
3 ms |
1116 KB |
Output is correct |
3 |
Correct |
3 ms |
1116 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 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 |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
1116 KB |
Output is correct |
17 |
Correct |
30 ms |
5664 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
452 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 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 |
195 ms |
41392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
260 ms |
53280 KB |
Output is correct |
3 |
Correct |
274 ms |
53416 KB |
Output is correct |
4 |
Correct |
266 ms |
53676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
260 ms |
53280 KB |
Output is correct |
3 |
Correct |
274 ms |
53416 KB |
Output is correct |
4 |
Correct |
266 ms |
53676 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
272 ms |
53268 KB |
Output is correct |
7 |
Correct |
262 ms |
53196 KB |
Output is correct |
8 |
Correct |
282 ms |
53416 KB |
Output is correct |
9 |
Correct |
289 ms |
53240 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
260 ms |
53280 KB |
Output is correct |
3 |
Correct |
274 ms |
53416 KB |
Output is correct |
4 |
Correct |
266 ms |
53676 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
28 ms |
5832 KB |
Output is correct |
7 |
Correct |
30 ms |
5832 KB |
Output is correct |
8 |
Correct |
25 ms |
5648 KB |
Output is correct |
9 |
Correct |
28 ms |
5844 KB |
Output is correct |
10 |
Correct |
26 ms |
5708 KB |
Output is correct |
11 |
Correct |
27 ms |
5832 KB |
Output is correct |
12 |
Correct |
27 ms |
5808 KB |
Output is correct |
13 |
Correct |
28 ms |
5836 KB |
Output is correct |
14 |
Correct |
28 ms |
5776 KB |
Output is correct |
15 |
Correct |
31 ms |
5824 KB |
Output is correct |
16 |
Correct |
29 ms |
5840 KB |
Output is correct |
17 |
Correct |
27 ms |
5696 KB |
Output is correct |
18 |
Correct |
268 ms |
53316 KB |
Output is correct |
19 |
Correct |
287 ms |
53464 KB |
Output is correct |
20 |
Correct |
280 ms |
53400 KB |
Output is correct |
21 |
Correct |
32 ms |
5832 KB |
Output is correct |
22 |
Correct |
26 ms |
5844 KB |
Output is correct |
23 |
Correct |
77 ms |
19904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
30 ms |
5676 KB |
Output is correct |
3 |
Correct |
30 ms |
6344 KB |
Output is correct |
4 |
Correct |
299 ms |
53292 KB |
Output is correct |
5 |
Correct |
30 ms |
5836 KB |
Output is correct |
6 |
Correct |
29 ms |
5836 KB |
Output is correct |
7 |
Correct |
29 ms |
5688 KB |
Output is correct |
8 |
Correct |
30 ms |
5728 KB |
Output is correct |
9 |
Correct |
29 ms |
5628 KB |
Output is correct |
10 |
Correct |
34 ms |
5664 KB |
Output is correct |
11 |
Correct |
31 ms |
5836 KB |
Output is correct |
12 |
Correct |
25 ms |
5828 KB |
Output is correct |
13 |
Correct |
31 ms |
5748 KB |
Output is correct |
14 |
Correct |
293 ms |
53424 KB |
Output is correct |
15 |
Correct |
34 ms |
5828 KB |
Output is correct |
16 |
Correct |
263 ms |
53300 KB |
Output is correct |
17 |
Correct |
262 ms |
54056 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
3 ms |
1116 KB |
Output is correct |
3 |
Correct |
3 ms |
1116 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 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 |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
1116 KB |
Output is correct |
17 |
Correct |
30 ms |
5664 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
452 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
344 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 |
195 ms |
41392 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
260 ms |
53280 KB |
Output is correct |
31 |
Correct |
274 ms |
53416 KB |
Output is correct |
32 |
Correct |
266 ms |
53676 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
272 ms |
53268 KB |
Output is correct |
35 |
Correct |
262 ms |
53196 KB |
Output is correct |
36 |
Correct |
282 ms |
53416 KB |
Output is correct |
37 |
Correct |
289 ms |
53240 KB |
Output is correct |
38 |
Correct |
0 ms |
344 KB |
Output is correct |
39 |
Correct |
28 ms |
5832 KB |
Output is correct |
40 |
Correct |
30 ms |
5832 KB |
Output is correct |
41 |
Correct |
25 ms |
5648 KB |
Output is correct |
42 |
Correct |
28 ms |
5844 KB |
Output is correct |
43 |
Correct |
26 ms |
5708 KB |
Output is correct |
44 |
Correct |
27 ms |
5832 KB |
Output is correct |
45 |
Correct |
27 ms |
5808 KB |
Output is correct |
46 |
Correct |
28 ms |
5836 KB |
Output is correct |
47 |
Correct |
28 ms |
5776 KB |
Output is correct |
48 |
Correct |
31 ms |
5824 KB |
Output is correct |
49 |
Correct |
29 ms |
5840 KB |
Output is correct |
50 |
Correct |
27 ms |
5696 KB |
Output is correct |
51 |
Correct |
268 ms |
53316 KB |
Output is correct |
52 |
Correct |
287 ms |
53464 KB |
Output is correct |
53 |
Correct |
280 ms |
53400 KB |
Output is correct |
54 |
Correct |
32 ms |
5832 KB |
Output is correct |
55 |
Correct |
26 ms |
5844 KB |
Output is correct |
56 |
Correct |
77 ms |
19904 KB |
Output is correct |
57 |
Correct |
0 ms |
344 KB |
Output is correct |
58 |
Correct |
30 ms |
5676 KB |
Output is correct |
59 |
Correct |
30 ms |
6344 KB |
Output is correct |
60 |
Correct |
299 ms |
53292 KB |
Output is correct |
61 |
Correct |
30 ms |
5836 KB |
Output is correct |
62 |
Correct |
29 ms |
5836 KB |
Output is correct |
63 |
Correct |
29 ms |
5688 KB |
Output is correct |
64 |
Correct |
30 ms |
5728 KB |
Output is correct |
65 |
Correct |
29 ms |
5628 KB |
Output is correct |
66 |
Correct |
34 ms |
5664 KB |
Output is correct |
67 |
Correct |
31 ms |
5836 KB |
Output is correct |
68 |
Correct |
25 ms |
5828 KB |
Output is correct |
69 |
Correct |
31 ms |
5748 KB |
Output is correct |
70 |
Correct |
293 ms |
53424 KB |
Output is correct |
71 |
Correct |
34 ms |
5828 KB |
Output is correct |
72 |
Correct |
263 ms |
53300 KB |
Output is correct |
73 |
Correct |
262 ms |
54056 KB |
Output is correct |
74 |
Correct |
0 ms |
344 KB |
Output is correct |
75 |
Correct |
0 ms |
348 KB |
Output is correct |
76 |
Correct |
0 ms |
348 KB |
Output is correct |
77 |
Correct |
0 ms |
348 KB |
Output is correct |
78 |
Correct |
0 ms |
348 KB |
Output is correct |
79 |
Correct |
3 ms |
1116 KB |
Output is correct |
80 |
Correct |
308 ms |
53300 KB |
Output is correct |
81 |
Correct |
301 ms |
53248 KB |
Output is correct |
82 |
Correct |
292 ms |
53420 KB |
Output is correct |
83 |
Correct |
298 ms |
53588 KB |
Output is correct |
84 |
Correct |
320 ms |
53528 KB |
Output is correct |
85 |
Correct |
315 ms |
53940 KB |
Output is correct |
86 |
Correct |
81 ms |
19904 KB |
Output is correct |
87 |
Correct |
1 ms |
348 KB |
Output is correct |