#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,di;
set<pair<ll,ll> > s;
vector<pair<ll,ll> > v;
ll gcdprajao(ll a,ll b)
{
if(b==0)return a;
return gcdprajao(b,a%b);
}
int main()
{
scanf("%lld%lld%lld",&n,&a,&b);
di=a/gcdprajao(b+1,a);
if(di>(1e18+1)/b)
{
md=1e18+1;
}else
{
md=di*b;
}
//printf("%lld\n",md);
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:42: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]
42 | for(int i=0;i<v.size();i++)
| ~^~~~~~~~~
strange_device.cpp:17:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
17 | scanf("%lld%lld%lld",&n,&a,&b);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
strange_device.cpp:29:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
29 | scanf("%lld%lld",&x,&y);
| ~~~~~^~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
5 ms |
640 KB |
Output is correct |
3 |
Correct |
6 ms |
596 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 |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 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 |
1 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 |
6 ms |
596 KB |
Output is correct |
17 |
Correct |
45 ms |
2452 KB |
Output is correct |
18 |
Correct |
1 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 |
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 |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
303 ms |
16804 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
425 ms |
16884 KB |
Output is correct |
3 |
Correct |
403 ms |
16788 KB |
Output is correct |
4 |
Correct |
408 ms |
16800 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
425 ms |
16884 KB |
Output is correct |
3 |
Correct |
403 ms |
16788 KB |
Output is correct |
4 |
Correct |
408 ms |
16800 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
406 ms |
16736 KB |
Output is correct |
7 |
Correct |
415 ms |
16840 KB |
Output is correct |
8 |
Correct |
397 ms |
16752 KB |
Output is correct |
9 |
Correct |
421 ms |
16828 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
425 ms |
16884 KB |
Output is correct |
3 |
Correct |
403 ms |
16788 KB |
Output is correct |
4 |
Correct |
408 ms |
16800 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
52 ms |
2476 KB |
Output is correct |
7 |
Correct |
46 ms |
2376 KB |
Output is correct |
8 |
Correct |
39 ms |
2416 KB |
Output is correct |
9 |
Correct |
39 ms |
2424 KB |
Output is correct |
10 |
Correct |
40 ms |
2368 KB |
Output is correct |
11 |
Correct |
44 ms |
2460 KB |
Output is correct |
12 |
Correct |
39 ms |
2484 KB |
Output is correct |
13 |
Correct |
41 ms |
2432 KB |
Output is correct |
14 |
Correct |
49 ms |
2480 KB |
Output is correct |
15 |
Correct |
46 ms |
2368 KB |
Output is correct |
16 |
Correct |
41 ms |
2352 KB |
Output is correct |
17 |
Correct |
43 ms |
2468 KB |
Output is correct |
18 |
Correct |
417 ms |
17008 KB |
Output is correct |
19 |
Correct |
387 ms |
16808 KB |
Output is correct |
20 |
Correct |
470 ms |
16772 KB |
Output is correct |
21 |
Correct |
46 ms |
2444 KB |
Output is correct |
22 |
Correct |
45 ms |
2376 KB |
Output is correct |
23 |
Correct |
158 ms |
8552 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
43 ms |
2368 KB |
Output is correct |
3 |
Correct |
43 ms |
2400 KB |
Output is correct |
4 |
Correct |
522 ms |
16732 KB |
Output is correct |
5 |
Correct |
45 ms |
2424 KB |
Output is correct |
6 |
Correct |
50 ms |
2428 KB |
Output is correct |
7 |
Correct |
58 ms |
2456 KB |
Output is correct |
8 |
Correct |
46 ms |
2444 KB |
Output is correct |
9 |
Correct |
47 ms |
2408 KB |
Output is correct |
10 |
Correct |
43 ms |
2368 KB |
Output is correct |
11 |
Correct |
43 ms |
2376 KB |
Output is correct |
12 |
Correct |
37 ms |
2368 KB |
Output is correct |
13 |
Correct |
40 ms |
2368 KB |
Output is correct |
14 |
Correct |
531 ms |
16828 KB |
Output is correct |
15 |
Correct |
43 ms |
2376 KB |
Output is correct |
16 |
Correct |
430 ms |
16832 KB |
Output is correct |
17 |
Correct |
479 ms |
16892 KB |
Output is correct |
18 |
Correct |
1 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
5 ms |
640 KB |
Output is correct |
3 |
Correct |
6 ms |
596 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 |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 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 |
1 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 |
6 ms |
596 KB |
Output is correct |
17 |
Correct |
45 ms |
2452 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |