#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pairll;
typedef pair<ll,pairll>pairlll;
typedef pair<pairll,pairll>pairllll;
typedef long double ld;
typedef pair<ll,string>pairls;
#define INF 1000000000000007
#define pb push_back
#define fr first
#define sc second
ll n,m,g;
ull a,b,k;
struct D{
ll x,y;
}d[1000007],t[4000007];
bool mcp(D d1, D d2){
return d1.x<d2.x;
}
int main()
{
cin>>n>>a>>b;
k=__gcd(a,b+1);
k=a/k;
k*=b;
for(int i=1;i<=n;i++){
cin>>d[i].x>>d[i].y;
d[i].y++;
if(d[i].y-d[i].x>=k){
m++;
t[m]={0,1};
m++;
t[m]={k,-1};
}else{
d[i].x%=k;
d[i].y%=k;
m++;
if(d[i].x<=d[i].y){
m++;
t[m]={d[i].x,1};
m++;
t[m]={d[i].y,-1};
}else{
m++;
t[m]={d[i].x,1};
m++;
t[m]={d[i].y,-1};
m++;
t[m]={0,1};
m++;
t[m]={k,-1};
}
}
}
m++;
t[m].x=k;
sort(t+1,t+1+m,mcp);
ll r=0;
ll h=0;
t[0].x=0;
for(int i=1;i<=m;i++){
if(h>0){
r+=(t[i].x-t[i-1].x);
}
h+=(t[i].y);
}
cout<<r<<endl;
return 0;
}
Compilation message
strange_device.cpp: In function 'int main()':
strange_device.cpp:38:25: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'ull' {aka 'long long unsigned int'} [-Wsign-compare]
38 | if(d[i].y-d[i].x>=k){
| ~~~~~~~~~~~~~^~~
strange_device.cpp:42:19: warning: narrowing conversion of 'k' from 'ull' {aka 'long long unsigned int'} to 'll' {aka 'long long int'} [-Wnarrowing]
42 | t[m]={k,-1};
| ^
strange_device.cpp:60:23: warning: narrowing conversion of 'k' from 'ull' {aka 'long long unsigned int'} to 'll' {aka 'long long int'} [-Wnarrowing]
60 | t[m]={k,-1};
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
17 ms |
892 KB |
Output is correct |
3 |
Correct |
17 ms |
852 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
17 ms |
896 KB |
Output is correct |
17 |
Correct |
169 ms |
6444 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
4 |
Correct |
2 ms |
332 KB |
Output is correct |
5 |
Correct |
1199 ms |
62992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1738 ms |
62840 KB |
Output is correct |
3 |
Correct |
1795 ms |
62848 KB |
Output is correct |
4 |
Correct |
1727 ms |
62968 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1738 ms |
62840 KB |
Output is correct |
3 |
Correct |
1795 ms |
62848 KB |
Output is correct |
4 |
Correct |
1727 ms |
62968 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1706 ms |
62968 KB |
Output is correct |
7 |
Correct |
1701 ms |
63060 KB |
Output is correct |
8 |
Correct |
1745 ms |
62904 KB |
Output is correct |
9 |
Correct |
1684 ms |
62956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1738 ms |
62840 KB |
Output is correct |
3 |
Correct |
1795 ms |
62848 KB |
Output is correct |
4 |
Correct |
1727 ms |
62968 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
172 ms |
6572 KB |
Output is correct |
7 |
Correct |
168 ms |
6560 KB |
Output is correct |
8 |
Correct |
165 ms |
6468 KB |
Output is correct |
9 |
Correct |
172 ms |
6560 KB |
Output is correct |
10 |
Correct |
180 ms |
6520 KB |
Output is correct |
11 |
Correct |
170 ms |
6584 KB |
Output is correct |
12 |
Correct |
178 ms |
6496 KB |
Output is correct |
13 |
Correct |
170 ms |
6436 KB |
Output is correct |
14 |
Correct |
173 ms |
6636 KB |
Output is correct |
15 |
Correct |
164 ms |
6492 KB |
Output is correct |
16 |
Correct |
167 ms |
6572 KB |
Output is correct |
17 |
Correct |
169 ms |
6508 KB |
Output is correct |
18 |
Correct |
1805 ms |
62904 KB |
Output is correct |
19 |
Correct |
1896 ms |
62904 KB |
Output is correct |
20 |
Correct |
1810 ms |
62904 KB |
Output is correct |
21 |
Correct |
186 ms |
6580 KB |
Output is correct |
22 |
Correct |
166 ms |
6556 KB |
Output is correct |
23 |
Correct |
567 ms |
21636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
171 ms |
6596 KB |
Output is correct |
3 |
Correct |
190 ms |
6532 KB |
Output is correct |
4 |
Correct |
1759 ms |
62832 KB |
Output is correct |
5 |
Correct |
161 ms |
6464 KB |
Output is correct |
6 |
Correct |
172 ms |
6604 KB |
Output is correct |
7 |
Correct |
173 ms |
6640 KB |
Output is correct |
8 |
Correct |
166 ms |
6556 KB |
Output is correct |
9 |
Correct |
164 ms |
6532 KB |
Output is correct |
10 |
Correct |
169 ms |
6484 KB |
Output is correct |
11 |
Correct |
168 ms |
6508 KB |
Output is correct |
12 |
Correct |
168 ms |
6552 KB |
Output is correct |
13 |
Correct |
176 ms |
6560 KB |
Output is correct |
14 |
Correct |
1716 ms |
63064 KB |
Output is correct |
15 |
Correct |
176 ms |
6512 KB |
Output is correct |
16 |
Correct |
1735 ms |
62916 KB |
Output is correct |
17 |
Correct |
1736 ms |
62832 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
17 ms |
892 KB |
Output is correct |
3 |
Correct |
17 ms |
852 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
17 ms |
896 KB |
Output is correct |
17 |
Correct |
169 ms |
6444 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
0 ms |
204 KB |
Output is correct |
22 |
Correct |
0 ms |
204 KB |
Output is correct |
23 |
Correct |
1 ms |
204 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
2 ms |
332 KB |
Output is correct |
26 |
Correct |
2 ms |
332 KB |
Output is correct |
27 |
Correct |
2 ms |
332 KB |
Output is correct |
28 |
Correct |
1199 ms |
62992 KB |
Output is correct |
29 |
Correct |
1 ms |
204 KB |
Output is correct |
30 |
Correct |
1738 ms |
62840 KB |
Output is correct |
31 |
Correct |
1795 ms |
62848 KB |
Output is correct |
32 |
Correct |
1727 ms |
62968 KB |
Output is correct |
33 |
Correct |
1 ms |
204 KB |
Output is correct |
34 |
Correct |
1706 ms |
62968 KB |
Output is correct |
35 |
Correct |
1701 ms |
63060 KB |
Output is correct |
36 |
Correct |
1745 ms |
62904 KB |
Output is correct |
37 |
Correct |
1684 ms |
62956 KB |
Output is correct |
38 |
Correct |
1 ms |
204 KB |
Output is correct |
39 |
Correct |
172 ms |
6572 KB |
Output is correct |
40 |
Correct |
168 ms |
6560 KB |
Output is correct |
41 |
Correct |
165 ms |
6468 KB |
Output is correct |
42 |
Correct |
172 ms |
6560 KB |
Output is correct |
43 |
Correct |
180 ms |
6520 KB |
Output is correct |
44 |
Correct |
170 ms |
6584 KB |
Output is correct |
45 |
Correct |
178 ms |
6496 KB |
Output is correct |
46 |
Correct |
170 ms |
6436 KB |
Output is correct |
47 |
Correct |
173 ms |
6636 KB |
Output is correct |
48 |
Correct |
164 ms |
6492 KB |
Output is correct |
49 |
Correct |
167 ms |
6572 KB |
Output is correct |
50 |
Correct |
169 ms |
6508 KB |
Output is correct |
51 |
Correct |
1805 ms |
62904 KB |
Output is correct |
52 |
Correct |
1896 ms |
62904 KB |
Output is correct |
53 |
Correct |
1810 ms |
62904 KB |
Output is correct |
54 |
Correct |
186 ms |
6580 KB |
Output is correct |
55 |
Correct |
166 ms |
6556 KB |
Output is correct |
56 |
Correct |
567 ms |
21636 KB |
Output is correct |
57 |
Correct |
1 ms |
204 KB |
Output is correct |
58 |
Correct |
171 ms |
6596 KB |
Output is correct |
59 |
Correct |
190 ms |
6532 KB |
Output is correct |
60 |
Correct |
1759 ms |
62832 KB |
Output is correct |
61 |
Correct |
161 ms |
6464 KB |
Output is correct |
62 |
Correct |
172 ms |
6604 KB |
Output is correct |
63 |
Correct |
173 ms |
6640 KB |
Output is correct |
64 |
Correct |
166 ms |
6556 KB |
Output is correct |
65 |
Correct |
164 ms |
6532 KB |
Output is correct |
66 |
Correct |
169 ms |
6484 KB |
Output is correct |
67 |
Correct |
168 ms |
6508 KB |
Output is correct |
68 |
Correct |
168 ms |
6552 KB |
Output is correct |
69 |
Correct |
176 ms |
6560 KB |
Output is correct |
70 |
Correct |
1716 ms |
63064 KB |
Output is correct |
71 |
Correct |
176 ms |
6512 KB |
Output is correct |
72 |
Correct |
1735 ms |
62916 KB |
Output is correct |
73 |
Correct |
1736 ms |
62832 KB |
Output is correct |
74 |
Correct |
1 ms |
204 KB |
Output is correct |
75 |
Correct |
0 ms |
204 KB |
Output is correct |
76 |
Correct |
1 ms |
204 KB |
Output is correct |
77 |
Correct |
1 ms |
204 KB |
Output is correct |
78 |
Correct |
1 ms |
204 KB |
Output is correct |
79 |
Correct |
17 ms |
844 KB |
Output is correct |
80 |
Correct |
1798 ms |
62904 KB |
Output is correct |
81 |
Correct |
1682 ms |
62848 KB |
Output is correct |
82 |
Correct |
1678 ms |
63008 KB |
Output is correct |
83 |
Correct |
1750 ms |
62988 KB |
Output is correct |
84 |
Correct |
1739 ms |
62900 KB |
Output is correct |
85 |
Correct |
1674 ms |
62904 KB |
Output is correct |
86 |
Correct |
535 ms |
21480 KB |
Output is correct |
87 |
Correct |
1 ms |
204 KB |
Output is correct |