#include <bits/stdc++.h>
#define LL long long
using namespace std;
int main()
{
LL n,a,b;
scanf("%lld %lld %lld",&n,&a,&b);
LL 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());
}
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 |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1278 ms |
1216 KB |
Output is correct |
3 |
Correct |
2862 ms |
1268 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
300 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 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 |
3457 ms |
1296 KB |
Output is correct |
17 |
Execution timed out |
5063 ms |
1676 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 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 |
17 ms |
364 KB |
Output is correct |
3 |
Correct |
15 ms |
396 KB |
Output is correct |
4 |
Correct |
24 ms |
308 KB |
Output is correct |
5 |
Execution timed out |
5061 ms |
1512 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Execution timed out |
5102 ms |
1492 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Execution timed out |
5102 ms |
1492 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Execution timed out |
5102 ms |
1492 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Execution timed out |
5061 ms |
1528 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1278 ms |
1216 KB |
Output is correct |
3 |
Correct |
2862 ms |
1268 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
300 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 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 |
3457 ms |
1296 KB |
Output is correct |
17 |
Execution timed out |
5063 ms |
1676 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |