#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define X first
#define Y second
#define pb push_back
ll n,a,b,x,y,md,cnt=0,mx=-1,l,r;
set<pair<ll,ll> > s;
vector<pair<ll,ll> > v;
int main()
{
scanf("%lld%lld%lld",&n,&a,&b);
/*for(int i=1;i<=100;i++)
{
printf("%d %d %d\n",i,(i+i/b)%a,i%b);
}*/
//printf("%d\n",s.size());
md=b*a/__gcd(b+1,a);
for(int i=1;i<=n;i++)
{
scanf("%lld%lld",&x,&y);
x%=md;
y%=md;
if(x<=y)
{
v.pb({x,y});
}else
{
v.pb({x,md-1});
v.pb({0,y});
}
}
sort(v.begin(),v.end());
for(int i=0;i<v.size();i++)
{
l=v[i].X;
r=v[i].Y;
if(l>mx)
{
cnt+=(r-l+1);
mx=r;
}else
{
if(r>mx)
{
cnt+=r-mx;
mx=r;
}
}
}
printf("%lld\n",cnt);
}
Compilation message
strange_device.cpp: In function 'int main()':
strange_device.cpp:34:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | for(int i=0;i<v.size();i++)
| ~^~~~~~~~~
strange_device.cpp:12:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
12 | scanf("%lld%lld%lld",&n,&a,&b);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
strange_device.cpp:21:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
21 | scanf("%lld%lld",&x,&y);
| ~~~~~^~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
6 ms |
948 KB |
Output is correct |
3 |
Correct |
5 ms |
948 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
296 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
304 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
300 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
296 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
5 ms |
1032 KB |
Output is correct |
17 |
Correct |
50 ms |
5568 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
319 ms |
17048 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
444 ms |
16804 KB |
Output is correct |
3 |
Correct |
458 ms |
24484 KB |
Output is correct |
4 |
Correct |
419 ms |
23968 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
444 ms |
16804 KB |
Output is correct |
3 |
Correct |
458 ms |
24484 KB |
Output is correct |
4 |
Correct |
419 ms |
23968 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
421 ms |
23964 KB |
Output is correct |
7 |
Correct |
437 ms |
23548 KB |
Output is correct |
8 |
Correct |
435 ms |
24020 KB |
Output is correct |
9 |
Correct |
486 ms |
24064 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
444 ms |
16804 KB |
Output is correct |
3 |
Correct |
458 ms |
24484 KB |
Output is correct |
4 |
Correct |
419 ms |
23968 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
48 ms |
5736 KB |
Output is correct |
7 |
Correct |
52 ms |
5648 KB |
Output is correct |
8 |
Correct |
45 ms |
5648 KB |
Output is correct |
9 |
Correct |
43 ms |
5692 KB |
Output is correct |
10 |
Correct |
49 ms |
5592 KB |
Output is correct |
11 |
Correct |
46 ms |
5676 KB |
Output is correct |
12 |
Correct |
42 ms |
5700 KB |
Output is correct |
13 |
Correct |
45 ms |
5644 KB |
Output is correct |
14 |
Correct |
43 ms |
5616 KB |
Output is correct |
15 |
Correct |
48 ms |
5584 KB |
Output is correct |
16 |
Correct |
46 ms |
5624 KB |
Output is correct |
17 |
Correct |
48 ms |
5644 KB |
Output is correct |
18 |
Correct |
438 ms |
24524 KB |
Output is correct |
19 |
Correct |
423 ms |
24516 KB |
Output is correct |
20 |
Correct |
490 ms |
24460 KB |
Output is correct |
21 |
Correct |
48 ms |
5700 KB |
Output is correct |
22 |
Correct |
42 ms |
5664 KB |
Output is correct |
23 |
Correct |
146 ms |
14508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
48 ms |
5692 KB |
Output is correct |
3 |
Correct |
52 ms |
5592 KB |
Output is correct |
4 |
Correct |
516 ms |
24404 KB |
Output is correct |
5 |
Correct |
46 ms |
5692 KB |
Output is correct |
6 |
Correct |
49 ms |
5676 KB |
Output is correct |
7 |
Correct |
46 ms |
5664 KB |
Output is correct |
8 |
Correct |
49 ms |
5692 KB |
Output is correct |
9 |
Correct |
48 ms |
5728 KB |
Output is correct |
10 |
Correct |
49 ms |
5624 KB |
Output is correct |
11 |
Correct |
52 ms |
5564 KB |
Output is correct |
12 |
Correct |
44 ms |
5660 KB |
Output is correct |
13 |
Correct |
50 ms |
5688 KB |
Output is correct |
14 |
Correct |
475 ms |
24336 KB |
Output is correct |
15 |
Correct |
47 ms |
5608 KB |
Output is correct |
16 |
Correct |
424 ms |
23972 KB |
Output is correct |
17 |
Correct |
414 ms |
24488 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
6 ms |
948 KB |
Output is correct |
3 |
Correct |
5 ms |
948 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
296 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
304 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
300 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
296 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
5 ms |
1032 KB |
Output is correct |
17 |
Correct |
50 ms |
5568 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 |
212 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |