#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(l-r+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 |
1 ms |
216 KB |
Output is correct |
2 |
Correct |
11 ms |
1176 KB |
Output is correct |
3 |
Correct |
12 ms |
1100 KB |
Output is correct |
4 |
Correct |
1 ms |
300 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
300 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
304 KB |
Output is correct |
12 |
Correct |
1 ms |
300 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
13 ms |
1188 KB |
Output is correct |
17 |
Correct |
134 ms |
4792 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 |
Incorrect |
1 ms |
300 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
308 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
777 ms |
33276 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1185 ms |
33352 KB |
Output is correct |
3 |
Correct |
1113 ms |
33752 KB |
Output is correct |
4 |
Correct |
1108 ms |
33832 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1185 ms |
33352 KB |
Output is correct |
3 |
Correct |
1113 ms |
33752 KB |
Output is correct |
4 |
Correct |
1108 ms |
33832 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1134 ms |
33784 KB |
Output is correct |
7 |
Correct |
1121 ms |
33800 KB |
Output is correct |
8 |
Correct |
1099 ms |
33728 KB |
Output is correct |
9 |
Correct |
1184 ms |
33856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1185 ms |
33352 KB |
Output is correct |
3 |
Correct |
1113 ms |
33752 KB |
Output is correct |
4 |
Correct |
1108 ms |
33832 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
119 ms |
4888 KB |
Output is correct |
7 |
Correct |
131 ms |
4916 KB |
Output is correct |
8 |
Correct |
109 ms |
5012 KB |
Output is correct |
9 |
Correct |
115 ms |
5032 KB |
Output is correct |
10 |
Correct |
107 ms |
4932 KB |
Output is correct |
11 |
Correct |
113 ms |
4964 KB |
Output is correct |
12 |
Correct |
135 ms |
4944 KB |
Output is correct |
13 |
Correct |
112 ms |
4956 KB |
Output is correct |
14 |
Correct |
116 ms |
5000 KB |
Output is correct |
15 |
Correct |
117 ms |
4984 KB |
Output is correct |
16 |
Correct |
115 ms |
5056 KB |
Output is correct |
17 |
Correct |
108 ms |
5000 KB |
Output is correct |
18 |
Correct |
1153 ms |
33976 KB |
Output is correct |
19 |
Correct |
1088 ms |
33752 KB |
Output is correct |
20 |
Correct |
1195 ms |
33908 KB |
Output is correct |
21 |
Correct |
117 ms |
4948 KB |
Output is correct |
22 |
Correct |
106 ms |
5156 KB |
Output is correct |
23 |
Correct |
376 ms |
17572 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
135 ms |
4948 KB |
Output is correct |
3 |
Correct |
124 ms |
4980 KB |
Output is correct |
4 |
Correct |
1382 ms |
33624 KB |
Output is correct |
5 |
Correct |
172 ms |
4888 KB |
Output is correct |
6 |
Correct |
135 ms |
4952 KB |
Output is correct |
7 |
Correct |
125 ms |
4992 KB |
Output is correct |
8 |
Correct |
129 ms |
4884 KB |
Output is correct |
9 |
Correct |
142 ms |
4996 KB |
Output is correct |
10 |
Correct |
137 ms |
5016 KB |
Output is correct |
11 |
Correct |
126 ms |
5016 KB |
Output is correct |
12 |
Correct |
120 ms |
5096 KB |
Output is correct |
13 |
Correct |
148 ms |
4984 KB |
Output is correct |
14 |
Correct |
1329 ms |
33636 KB |
Output is correct |
15 |
Correct |
120 ms |
4896 KB |
Output is correct |
16 |
Correct |
1142 ms |
33480 KB |
Output is correct |
17 |
Correct |
1211 ms |
33964 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
216 KB |
Output is correct |
2 |
Correct |
11 ms |
1176 KB |
Output is correct |
3 |
Correct |
12 ms |
1100 KB |
Output is correct |
4 |
Correct |
1 ms |
300 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
300 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
304 KB |
Output is correct |
12 |
Correct |
1 ms |
300 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
13 ms |
1188 KB |
Output is correct |
17 |
Correct |
134 ms |
4792 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Incorrect |
1 ms |
300 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |