#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define N 2000010
#define ii pair<int,int>
#define fs first
#define sc second
#define ld double
#define int ll
const int MAX_VAL=2e18;
int S,cnt[N],n,A,B,dem=0,ans=0;
vector<int>s;
void sub_AB()
{
int res=0;
for(int i=1;i<=n;i++)
{
int l,r;
cin>>l>>r;
res+=(r-l+1);
}
cout<<res;
exit(0);
}
ii a[N];
int32_t main()
{
#ifdef SKY
freopen("A.inp","r",stdin);
freopen("A.out","w",stdout);
#endif // SKY
ios::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
cin>>n>>A>>B;
S=B*(A/__gcd(A,B+1));
for(int i=1;i<=n;i++)
{
int l,r;
cin>>l>>r;
if(r-l+1>=S)
{
cout<<S;
return 0;
}
int lef=l%S,righ=r%S;
if(lef<=righ)
{
a[++dem]={lef,righ};
}else
{
a[++dem]={lef,S-1};
a[++dem]={0,righ};
}
}
for(int i=1;i<=dem;i++)
{
s.pb(a[i].fs);
s.pb(a[i].sc+1);
}
sort(s.begin(),s.end());
s.erase(unique(s.begin(),s.end()),s.end());
for(int i=1;i<=dem;i++)
{
cnt[lower_bound(s.begin(),s.end(),a[i].fs)-s.begin()]++;
cnt[lower_bound(s.begin(),s.end(),a[i].sc+1)-s.begin()]--;
}
for(int i=0;i<s.size()-1;i++)
{
if(i>0)
cnt[i]+=cnt[i-1];
if(cnt[i]>0)
ans+=(s[i+1]-s[i]);
}
cout<<ans;
return 0;
}
Compilation message
strange_device.cpp: In function 'int32_t main()':
strange_device.cpp:76:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
76 | for(int i=0;i<s.size()-1;i++)
| ~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
5 ms |
856 KB |
Output is correct |
3 |
Correct |
6 ms |
796 KB |
Output is correct |
4 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 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 |
340 KB |
Output is correct |
16 |
Correct |
6 ms |
868 KB |
Output is correct |
17 |
Correct |
61 ms |
4324 KB |
Output is correct |
18 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
285 ms |
32468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
519 ms |
39556 KB |
Output is correct |
3 |
Correct |
548 ms |
39612 KB |
Output is correct |
4 |
Correct |
549 ms |
51704 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
519 ms |
39556 KB |
Output is correct |
3 |
Correct |
548 ms |
39612 KB |
Output is correct |
4 |
Correct |
549 ms |
51704 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
568 ms |
51592 KB |
Output is correct |
7 |
Correct |
570 ms |
51700 KB |
Output is correct |
8 |
Correct |
589 ms |
51608 KB |
Output is correct |
9 |
Correct |
649 ms |
51676 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
519 ms |
39556 KB |
Output is correct |
3 |
Correct |
548 ms |
39612 KB |
Output is correct |
4 |
Correct |
549 ms |
51704 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
66 ms |
8088 KB |
Output is correct |
7 |
Correct |
59 ms |
8004 KB |
Output is correct |
8 |
Correct |
55 ms |
7996 KB |
Output is correct |
9 |
Correct |
74 ms |
8084 KB |
Output is correct |
10 |
Correct |
56 ms |
8092 KB |
Output is correct |
11 |
Correct |
59 ms |
8040 KB |
Output is correct |
12 |
Correct |
58 ms |
7988 KB |
Output is correct |
13 |
Correct |
62 ms |
7984 KB |
Output is correct |
14 |
Correct |
54 ms |
8136 KB |
Output is correct |
15 |
Correct |
78 ms |
7964 KB |
Output is correct |
16 |
Correct |
68 ms |
8080 KB |
Output is correct |
17 |
Correct |
67 ms |
8064 KB |
Output is correct |
18 |
Correct |
598 ms |
51632 KB |
Output is correct |
19 |
Correct |
586 ms |
51700 KB |
Output is correct |
20 |
Correct |
642 ms |
51676 KB |
Output is correct |
21 |
Correct |
77 ms |
8020 KB |
Output is correct |
22 |
Correct |
51 ms |
8064 KB |
Output is correct |
23 |
Correct |
144 ms |
26548 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
61 ms |
4360 KB |
Output is correct |
3 |
Correct |
58 ms |
4360 KB |
Output is correct |
4 |
Correct |
711 ms |
39592 KB |
Output is correct |
5 |
Correct |
65 ms |
4332 KB |
Output is correct |
6 |
Correct |
59 ms |
4360 KB |
Output is correct |
7 |
Correct |
61 ms |
4364 KB |
Output is correct |
8 |
Correct |
65 ms |
4312 KB |
Output is correct |
9 |
Correct |
62 ms |
4360 KB |
Output is correct |
10 |
Correct |
66 ms |
4368 KB |
Output is correct |
11 |
Correct |
63 ms |
4280 KB |
Output is correct |
12 |
Correct |
58 ms |
4412 KB |
Output is correct |
13 |
Correct |
63 ms |
4360 KB |
Output is correct |
14 |
Correct |
650 ms |
39628 KB |
Output is correct |
15 |
Correct |
78 ms |
4360 KB |
Output is correct |
16 |
Correct |
576 ms |
51664 KB |
Output is correct |
17 |
Correct |
535 ms |
51660 KB |
Output is correct |
18 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
5 ms |
856 KB |
Output is correct |
3 |
Correct |
6 ms |
796 KB |
Output is correct |
4 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 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 |
340 KB |
Output is correct |
16 |
Correct |
6 ms |
868 KB |
Output is correct |
17 |
Correct |
61 ms |
4324 KB |
Output is correct |
18 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |