#include <bits/stdc++.h>
#define LL long long
using namespace std;
int main()
{
LL n,a,b;
scanf("%lld %lld %lld",&n,&a,&b);
__int128_t t=b*a/__gcd(b+1,a);
vector<pair<LL,LL>>v;
// printf("t=%lld\n",t);
for(LL a=1;a<=n;a++)
{
LL l,r;
scanf("%lld %lld",&l,&r);
LL temp=l,temp2=r;
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:48:6: warning: unused variable 'kanan' [-Wunused-variable]
48 | LL kanan=0,tot=0,kiri=0,cnt=0;
| ^~~~~
strange_device.cpp:7:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
7 | scanf("%lld %lld %lld",&n,&a,&b);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
strange_device.cpp:14:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
14 | scanf("%lld %lld",&l,&r);
| ~~~~~^~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
5 ms |
848 KB |
Output is correct |
3 |
Correct |
5 ms |
1156 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
256 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 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 |
296 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
300 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
5 ms |
1088 KB |
Output is correct |
17 |
Correct |
55 ms |
5756 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 |
Incorrect |
0 ms |
236 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
278 ms |
33180 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
415 ms |
33188 KB |
Output is correct |
3 |
Correct |
418 ms |
33984 KB |
Output is correct |
4 |
Correct |
396 ms |
34008 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
415 ms |
33188 KB |
Output is correct |
3 |
Correct |
418 ms |
33984 KB |
Output is correct |
4 |
Correct |
396 ms |
34008 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
428 ms |
34080 KB |
Output is correct |
7 |
Correct |
409 ms |
34052 KB |
Output is correct |
8 |
Correct |
408 ms |
34032 KB |
Output is correct |
9 |
Correct |
491 ms |
33972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
415 ms |
33188 KB |
Output is correct |
3 |
Correct |
418 ms |
33984 KB |
Output is correct |
4 |
Correct |
396 ms |
34008 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
40 ms |
5080 KB |
Output is correct |
7 |
Correct |
40 ms |
5260 KB |
Output is correct |
8 |
Correct |
39 ms |
5292 KB |
Output is correct |
9 |
Correct |
39 ms |
5256 KB |
Output is correct |
10 |
Correct |
38 ms |
5304 KB |
Output is correct |
11 |
Correct |
41 ms |
5228 KB |
Output is correct |
12 |
Correct |
39 ms |
5300 KB |
Output is correct |
13 |
Correct |
43 ms |
5292 KB |
Output is correct |
14 |
Correct |
39 ms |
5280 KB |
Output is correct |
15 |
Correct |
46 ms |
5272 KB |
Output is correct |
16 |
Correct |
49 ms |
5300 KB |
Output is correct |
17 |
Correct |
40 ms |
5304 KB |
Output is correct |
18 |
Correct |
426 ms |
34084 KB |
Output is correct |
19 |
Correct |
393 ms |
34056 KB |
Output is correct |
20 |
Correct |
512 ms |
34104 KB |
Output is correct |
21 |
Correct |
49 ms |
5264 KB |
Output is correct |
22 |
Correct |
36 ms |
5176 KB |
Output is correct |
23 |
Correct |
113 ms |
17528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
42 ms |
4540 KB |
Output is correct |
3 |
Correct |
49 ms |
5332 KB |
Output is correct |
4 |
Correct |
563 ms |
34008 KB |
Output is correct |
5 |
Correct |
44 ms |
5084 KB |
Output is correct |
6 |
Correct |
44 ms |
5276 KB |
Output is correct |
7 |
Correct |
43 ms |
5188 KB |
Output is correct |
8 |
Correct |
49 ms |
5144 KB |
Output is correct |
9 |
Correct |
44 ms |
5200 KB |
Output is correct |
10 |
Correct |
53 ms |
5232 KB |
Output is correct |
11 |
Correct |
45 ms |
5304 KB |
Output is correct |
12 |
Correct |
39 ms |
5164 KB |
Output is correct |
13 |
Correct |
45 ms |
5060 KB |
Output is correct |
14 |
Correct |
471 ms |
33900 KB |
Output is correct |
15 |
Correct |
47 ms |
5152 KB |
Output is correct |
16 |
Correct |
396 ms |
33988 KB |
Output is correct |
17 |
Correct |
417 ms |
34012 KB |
Output is correct |
18 |
Correct |
1 ms |
300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
5 ms |
848 KB |
Output is correct |
3 |
Correct |
5 ms |
1156 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
256 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 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 |
296 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
300 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
5 ms |
1088 KB |
Output is correct |
17 |
Correct |
55 ms |
5756 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Incorrect |
0 ms |
236 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |