This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
if(MAX_VAL/B<=A/__gcd(A,B+1))
sub_AB();
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 (stderr)
strange_device.cpp: In function 'int32_t main()':
strange_device.cpp:78: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]
78 | for(int i=0;i<s.size()-1;i++)
| ~^~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |