#include <bits/stdc++.h>
#define LL long long
LL INF =1e18+5LL;
using namespace std;
int main()
{
LL n,a,b;
cin>>n>>a>>b;
LL t = (a/__gcd(b+1,a));
vector<pair<LL,LL>>v;
__int128_t x=(__int128_t)b*t;
if(x>INF)t=INF;
else t=(LL)x;
// printf("t=%lld\n",t);
bool jawab=false;
for(LL a=1;a<=n;a++)
{
LL l,r;
cin>>l>>r;
LL temp=l,temp2=r;
if(jawab)continue;
if(r-l+1>=t)
{
printf("%lld\n",t);
jawab=1;
return 0;
}
l%=t ,r%=t;
if(l==r)
{
if(temp==temp2)
{
v.push_back(make_pair(l,0));
v.push_back(make_pair(r,1));
}
else
{
v.push_back(make_pair(0,0));
v.push_back(make_pair(t-1,1));
}
}
else if(l>r)
{
// printf("->%lld,%lld\n-> 0 %lld\n",l,t-1,r);
// v.push_back(make_pair(l,t-1));
v.push_back(make_pair(l,0));
v.push_back(make_pair(t-1,1));
// v.push_back(make_pair(0,r));
v.push_back(make_pair(0,0));
v.push_back(make_pair(r,1));
}
else
{
v.push_back(make_pair(l,0));
v.push_back(make_pair(r,1));
}
}
sort(v.begin(),v.end());
LL kanan=0,tot=0,kiri=0,cnt=0;
for(pair<LL,LL>x:v)
{
if(x.second==0)
{
cnt++;
if(cnt==1)kiri=x.first;
}
else
{
cnt--;
if(cnt==0)tot+=(x.first-kiri+1);
}
}
cout<<tot<<endl;
}
Compilation message
strange_device.cpp: In function 'int main()':
strange_device.cpp:63:6: warning: unused variable 'kanan' [-Wunused-variable]
63 | LL kanan=0,tot=0,kiri=0,cnt=0;
| ^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
10 ms |
844 KB |
Output is correct |
3 |
Correct |
13 ms |
932 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 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 |
11 ms |
912 KB |
Output is correct |
17 |
Correct |
111 ms |
4404 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
232 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 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 |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
360 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
803 ms |
33216 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1203 ms |
33184 KB |
Output is correct |
3 |
Correct |
1150 ms |
33160 KB |
Output is correct |
4 |
Correct |
1138 ms |
33360 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1203 ms |
33184 KB |
Output is correct |
3 |
Correct |
1150 ms |
33160 KB |
Output is correct |
4 |
Correct |
1138 ms |
33360 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1150 ms |
33236 KB |
Output is correct |
7 |
Correct |
1136 ms |
33256 KB |
Output is correct |
8 |
Correct |
1125 ms |
33204 KB |
Output is correct |
9 |
Correct |
1173 ms |
33172 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1203 ms |
33184 KB |
Output is correct |
3 |
Correct |
1150 ms |
33160 KB |
Output is correct |
4 |
Correct |
1138 ms |
33360 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
128 ms |
4456 KB |
Output is correct |
7 |
Correct |
111 ms |
4524 KB |
Output is correct |
8 |
Correct |
101 ms |
4516 KB |
Output is correct |
9 |
Correct |
104 ms |
4488 KB |
Output is correct |
10 |
Correct |
132 ms |
4496 KB |
Output is correct |
11 |
Correct |
105 ms |
4488 KB |
Output is correct |
12 |
Correct |
101 ms |
4472 KB |
Output is correct |
13 |
Correct |
111 ms |
4512 KB |
Output is correct |
14 |
Correct |
101 ms |
4408 KB |
Output is correct |
15 |
Correct |
111 ms |
4408 KB |
Output is correct |
16 |
Correct |
107 ms |
4520 KB |
Output is correct |
17 |
Correct |
103 ms |
4516 KB |
Output is correct |
18 |
Correct |
1107 ms |
33152 KB |
Output is correct |
19 |
Correct |
1087 ms |
33288 KB |
Output is correct |
20 |
Correct |
1171 ms |
33188 KB |
Output is correct |
21 |
Correct |
127 ms |
4468 KB |
Output is correct |
22 |
Correct |
100 ms |
4504 KB |
Output is correct |
23 |
Correct |
337 ms |
16768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
116 ms |
4488 KB |
Output is correct |
3 |
Correct |
130 ms |
4520 KB |
Output is correct |
4 |
Correct |
1224 ms |
33224 KB |
Output is correct |
5 |
Correct |
114 ms |
4484 KB |
Output is correct |
6 |
Correct |
109 ms |
4588 KB |
Output is correct |
7 |
Correct |
110 ms |
4408 KB |
Output is correct |
8 |
Correct |
114 ms |
4512 KB |
Output is correct |
9 |
Correct |
105 ms |
4412 KB |
Output is correct |
10 |
Correct |
109 ms |
4496 KB |
Output is correct |
11 |
Correct |
110 ms |
4504 KB |
Output is correct |
12 |
Correct |
104 ms |
4496 KB |
Output is correct |
13 |
Correct |
112 ms |
4404 KB |
Output is correct |
14 |
Correct |
1197 ms |
33200 KB |
Output is correct |
15 |
Correct |
111 ms |
4412 KB |
Output is correct |
16 |
Correct |
1066 ms |
33152 KB |
Output is correct |
17 |
Correct |
1156 ms |
33192 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
10 ms |
844 KB |
Output is correct |
3 |
Correct |
13 ms |
932 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 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 |
11 ms |
912 KB |
Output is correct |
17 |
Correct |
111 ms |
4404 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
256 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
232 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
360 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
803 ms |
33216 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
1203 ms |
33184 KB |
Output is correct |
31 |
Correct |
1150 ms |
33160 KB |
Output is correct |
32 |
Correct |
1138 ms |
33360 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
1150 ms |
33236 KB |
Output is correct |
35 |
Correct |
1136 ms |
33256 KB |
Output is correct |
36 |
Correct |
1125 ms |
33204 KB |
Output is correct |
37 |
Correct |
1173 ms |
33172 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
128 ms |
4456 KB |
Output is correct |
40 |
Correct |
111 ms |
4524 KB |
Output is correct |
41 |
Correct |
101 ms |
4516 KB |
Output is correct |
42 |
Correct |
104 ms |
4488 KB |
Output is correct |
43 |
Correct |
132 ms |
4496 KB |
Output is correct |
44 |
Correct |
105 ms |
4488 KB |
Output is correct |
45 |
Correct |
101 ms |
4472 KB |
Output is correct |
46 |
Correct |
111 ms |
4512 KB |
Output is correct |
47 |
Correct |
101 ms |
4408 KB |
Output is correct |
48 |
Correct |
111 ms |
4408 KB |
Output is correct |
49 |
Correct |
107 ms |
4520 KB |
Output is correct |
50 |
Correct |
103 ms |
4516 KB |
Output is correct |
51 |
Correct |
1107 ms |
33152 KB |
Output is correct |
52 |
Correct |
1087 ms |
33288 KB |
Output is correct |
53 |
Correct |
1171 ms |
33188 KB |
Output is correct |
54 |
Correct |
127 ms |
4468 KB |
Output is correct |
55 |
Correct |
100 ms |
4504 KB |
Output is correct |
56 |
Correct |
337 ms |
16768 KB |
Output is correct |
57 |
Correct |
1 ms |
212 KB |
Output is correct |
58 |
Correct |
116 ms |
4488 KB |
Output is correct |
59 |
Correct |
130 ms |
4520 KB |
Output is correct |
60 |
Correct |
1224 ms |
33224 KB |
Output is correct |
61 |
Correct |
114 ms |
4484 KB |
Output is correct |
62 |
Correct |
109 ms |
4588 KB |
Output is correct |
63 |
Correct |
110 ms |
4408 KB |
Output is correct |
64 |
Correct |
114 ms |
4512 KB |
Output is correct |
65 |
Correct |
105 ms |
4412 KB |
Output is correct |
66 |
Correct |
109 ms |
4496 KB |
Output is correct |
67 |
Correct |
110 ms |
4504 KB |
Output is correct |
68 |
Correct |
104 ms |
4496 KB |
Output is correct |
69 |
Correct |
112 ms |
4404 KB |
Output is correct |
70 |
Correct |
1197 ms |
33200 KB |
Output is correct |
71 |
Correct |
111 ms |
4412 KB |
Output is correct |
72 |
Correct |
1066 ms |
33152 KB |
Output is correct |
73 |
Correct |
1156 ms |
33192 KB |
Output is correct |
74 |
Correct |
0 ms |
212 KB |
Output is correct |
75 |
Correct |
1 ms |
212 KB |
Output is correct |
76 |
Correct |
1 ms |
212 KB |
Output is correct |
77 |
Correct |
1 ms |
296 KB |
Output is correct |
78 |
Correct |
1 ms |
212 KB |
Output is correct |
79 |
Correct |
13 ms |
1204 KB |
Output is correct |
80 |
Correct |
1224 ms |
39372 KB |
Output is correct |
81 |
Correct |
1246 ms |
38396 KB |
Output is correct |
82 |
Correct |
1200 ms |
37924 KB |
Output is correct |
83 |
Correct |
1213 ms |
37876 KB |
Output is correct |
84 |
Correct |
1248 ms |
39408 KB |
Output is correct |
85 |
Correct |
1189 ms |
39440 KB |
Output is correct |
86 |
Correct |
333 ms |
22504 KB |
Output is correct |
87 |
Correct |
1 ms |
296 KB |
Output is correct |