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;
long long n,a,b;
map<pair<long long,long long>,long long> mp;
void help()
{
for(long long t=0;t<=110;t++)
{
long long x=(t+t/b)%a,y=t%b;
if(mp[{x,y}])
{
cout<<t<<" "<<x<<" "<<y<<" "<<mp[{x,y}]<<endl;
}
mp[{x,y}]=t+1;
}
}
pair<long long,long long> p[2000001];
void solve()
{
int cnt=n;
long long h=1e18;
if(1e18/a>b)h=a*b;
for(long long i=1;i<=n;i++)
{
long long l,r;
cin>>l>>r;
p[i]={l%(a*b),r%(a*b)};
if(p[i].first>p[i].second)
{
cnt++;
p[cnt].first=0;
p[cnt].second=p[i].second;
p[i].second=a*b-1;
}
}
long long ans=0;
sort(p+1,p+cnt+1);
long long r=-1;
for(long long i=1;i<=cnt;i++)
{
if(p[i].second>r)
{
if(p[i].first>r)
ans+=p[i].second-p[i].first+1;
else ans+=p[i].second-r;
}
r=max(r,p[i].second);
}
cout<<ans<<endl;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin>>n>>a>>b;
//help();
solve();
return 0;
}
Compilation message (stderr)
strange_device.cpp: In function 'void solve()':
strange_device.cpp:24:15: warning: variable 'h' set but not used [-Wunused-but-set-variable]
24 | long long h=1e18;
| ^
# | 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... |