#include<bits/stdc++.h>
using namespace std;
#define int long long
const int inf=1e18+69;
vector<pair<int, int> >seg;
int32_t main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, a, b;
cin>>n>>a>>b;
int gcd=__gcd(a, b+1);
int t;
if(a/gcd>inf/b) t=inf; //a*b/gcd>inf
else t=(a/gcd)*b;
for(int i=0; i<n; i++){
int l, r; cin>>l>>r;
if(r-l+1>=t) seg.push_back({0, t-1});
else{
l%=t; r%=t;
if(l<=r) seg.push_back({l, r});
else{
seg.push_back({l, t-1});
seg.push_back({0, r});
}
}
}
sort(seg.begin(), seg.end());
int ans=0;
for(int i=0; i<(int)seg.size(); i++){
int l=seg[i].first, r=seg[i].second;
int nxt=i;
while(nxt+1<seg.size()&&seg[nxt+1].first<=r){
r=max(r, seg[nxt+1].second); nxt++;
}
ans+=r-l+1; i=nxt;
}
cout<<ans<<endl; return 0;
}
Compilation message
strange_device.cpp: In function 'int32_t main()':
strange_device.cpp:32:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(nxt+1<seg.size()&&seg[nxt+1].first<=r){
~~~~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
6 ms |
1152 KB |
Output is correct |
3 |
Correct |
6 ms |
1152 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
6 ms |
1152 KB |
Output is correct |
17 |
Correct |
56 ms |
5740 KB |
Output is correct |
18 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
371 ms |
17496 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
500 ms |
26836 KB |
Output is correct |
3 |
Correct |
502 ms |
26964 KB |
Output is correct |
4 |
Correct |
531 ms |
26836 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
500 ms |
26836 KB |
Output is correct |
3 |
Correct |
502 ms |
26964 KB |
Output is correct |
4 |
Correct |
531 ms |
26836 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
508 ms |
26932 KB |
Output is correct |
7 |
Correct |
524 ms |
26984 KB |
Output is correct |
8 |
Correct |
506 ms |
26836 KB |
Output is correct |
9 |
Correct |
546 ms |
26836 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
500 ms |
26836 KB |
Output is correct |
3 |
Correct |
502 ms |
26964 KB |
Output is correct |
4 |
Correct |
531 ms |
26836 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
50 ms |
5796 KB |
Output is correct |
7 |
Correct |
55 ms |
5736 KB |
Output is correct |
8 |
Correct |
55 ms |
5876 KB |
Output is correct |
9 |
Correct |
51 ms |
5740 KB |
Output is correct |
10 |
Correct |
56 ms |
5740 KB |
Output is correct |
11 |
Correct |
57 ms |
5736 KB |
Output is correct |
12 |
Correct |
54 ms |
5864 KB |
Output is correct |
13 |
Correct |
55 ms |
5736 KB |
Output is correct |
14 |
Correct |
49 ms |
5740 KB |
Output is correct |
15 |
Correct |
55 ms |
5736 KB |
Output is correct |
16 |
Correct |
53 ms |
5740 KB |
Output is correct |
17 |
Correct |
55 ms |
5776 KB |
Output is correct |
18 |
Correct |
507 ms |
18132 KB |
Output is correct |
19 |
Correct |
522 ms |
18132 KB |
Output is correct |
20 |
Correct |
600 ms |
18004 KB |
Output is correct |
21 |
Correct |
56 ms |
5740 KB |
Output is correct |
22 |
Correct |
51 ms |
5740 KB |
Output is correct |
23 |
Correct |
159 ms |
18528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
54 ms |
5740 KB |
Output is correct |
3 |
Correct |
61 ms |
5736 KB |
Output is correct |
4 |
Correct |
613 ms |
26740 KB |
Output is correct |
5 |
Correct |
58 ms |
5736 KB |
Output is correct |
6 |
Correct |
78 ms |
5736 KB |
Output is correct |
7 |
Correct |
58 ms |
5736 KB |
Output is correct |
8 |
Correct |
57 ms |
5736 KB |
Output is correct |
9 |
Correct |
55 ms |
5740 KB |
Output is correct |
10 |
Correct |
54 ms |
5736 KB |
Output is correct |
11 |
Correct |
68 ms |
5740 KB |
Output is correct |
12 |
Correct |
51 ms |
5740 KB |
Output is correct |
13 |
Correct |
56 ms |
5736 KB |
Output is correct |
14 |
Correct |
575 ms |
26836 KB |
Output is correct |
15 |
Correct |
67 ms |
5784 KB |
Output is correct |
16 |
Correct |
516 ms |
18008 KB |
Output is correct |
17 |
Correct |
502 ms |
18004 KB |
Output is correct |
18 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
6 ms |
1152 KB |
Output is correct |
3 |
Correct |
6 ms |
1152 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
6 ms |
1152 KB |
Output is correct |
17 |
Correct |
56 ms |
5740 KB |
Output is correct |
18 |
Correct |
0 ms |
384 KB |
Output is correct |
19 |
Correct |
0 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
0 ms |
384 KB |
Output is correct |
22 |
Correct |
0 ms |
384 KB |
Output is correct |
23 |
Correct |
0 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
384 KB |
Output is correct |
25 |
Correct |
1 ms |
384 KB |
Output is correct |
26 |
Correct |
1 ms |
384 KB |
Output is correct |
27 |
Correct |
1 ms |
384 KB |
Output is correct |
28 |
Correct |
371 ms |
17496 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
30 |
Correct |
500 ms |
26836 KB |
Output is correct |
31 |
Correct |
502 ms |
26964 KB |
Output is correct |
32 |
Correct |
531 ms |
26836 KB |
Output is correct |
33 |
Correct |
0 ms |
384 KB |
Output is correct |
34 |
Correct |
508 ms |
26932 KB |
Output is correct |
35 |
Correct |
524 ms |
26984 KB |
Output is correct |
36 |
Correct |
506 ms |
26836 KB |
Output is correct |
37 |
Correct |
546 ms |
26836 KB |
Output is correct |
38 |
Correct |
0 ms |
384 KB |
Output is correct |
39 |
Correct |
50 ms |
5796 KB |
Output is correct |
40 |
Correct |
55 ms |
5736 KB |
Output is correct |
41 |
Correct |
55 ms |
5876 KB |
Output is correct |
42 |
Correct |
51 ms |
5740 KB |
Output is correct |
43 |
Correct |
56 ms |
5740 KB |
Output is correct |
44 |
Correct |
57 ms |
5736 KB |
Output is correct |
45 |
Correct |
54 ms |
5864 KB |
Output is correct |
46 |
Correct |
55 ms |
5736 KB |
Output is correct |
47 |
Correct |
49 ms |
5740 KB |
Output is correct |
48 |
Correct |
55 ms |
5736 KB |
Output is correct |
49 |
Correct |
53 ms |
5740 KB |
Output is correct |
50 |
Correct |
55 ms |
5776 KB |
Output is correct |
51 |
Correct |
507 ms |
18132 KB |
Output is correct |
52 |
Correct |
522 ms |
18132 KB |
Output is correct |
53 |
Correct |
600 ms |
18004 KB |
Output is correct |
54 |
Correct |
56 ms |
5740 KB |
Output is correct |
55 |
Correct |
51 ms |
5740 KB |
Output is correct |
56 |
Correct |
159 ms |
18528 KB |
Output is correct |
57 |
Correct |
0 ms |
384 KB |
Output is correct |
58 |
Correct |
54 ms |
5740 KB |
Output is correct |
59 |
Correct |
61 ms |
5736 KB |
Output is correct |
60 |
Correct |
613 ms |
26740 KB |
Output is correct |
61 |
Correct |
58 ms |
5736 KB |
Output is correct |
62 |
Correct |
78 ms |
5736 KB |
Output is correct |
63 |
Correct |
58 ms |
5736 KB |
Output is correct |
64 |
Correct |
57 ms |
5736 KB |
Output is correct |
65 |
Correct |
55 ms |
5740 KB |
Output is correct |
66 |
Correct |
54 ms |
5736 KB |
Output is correct |
67 |
Correct |
68 ms |
5740 KB |
Output is correct |
68 |
Correct |
51 ms |
5740 KB |
Output is correct |
69 |
Correct |
56 ms |
5736 KB |
Output is correct |
70 |
Correct |
575 ms |
26836 KB |
Output is correct |
71 |
Correct |
67 ms |
5784 KB |
Output is correct |
72 |
Correct |
516 ms |
18008 KB |
Output is correct |
73 |
Correct |
502 ms |
18004 KB |
Output is correct |
74 |
Correct |
0 ms |
384 KB |
Output is correct |
75 |
Correct |
0 ms |
384 KB |
Output is correct |
76 |
Correct |
0 ms |
384 KB |
Output is correct |
77 |
Correct |
1 ms |
384 KB |
Output is correct |
78 |
Correct |
1 ms |
384 KB |
Output is correct |
79 |
Correct |
6 ms |
1152 KB |
Output is correct |
80 |
Correct |
589 ms |
18132 KB |
Output is correct |
81 |
Correct |
570 ms |
18008 KB |
Output is correct |
82 |
Correct |
528 ms |
18004 KB |
Output is correct |
83 |
Correct |
559 ms |
18176 KB |
Output is correct |
84 |
Correct |
537 ms |
18004 KB |
Output is correct |
85 |
Correct |
525 ms |
18004 KB |
Output is correct |
86 |
Correct |
170 ms |
18528 KB |
Output is correct |
87 |
Correct |
1 ms |
384 KB |
Output is correct |