# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
221628 | MKopchev | Strange Device (APIO19_strange_device) | C++14 | 1050 ms | 102072 KiB |
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;
const int nmax=1e6+42;
const long long inf=1e18;
int n;
long long A,B;
pair<long long,long long> inp[nmax];
vector< pair<long long,long long> > segments;
vector< pair<long long,int> > active;
bool cmp(pair<long long,int> s,pair<long long,int> t)
{
if(s.first!=t.first)return s.first<t.first;
return s.second>t.second;
}
int main()
{
scanf("%i%lld%lld",&n,&A,&B);
A=A/__gcd(A,B+1);
for(int i=1;i<=n;i++)
{
scanf("%lld%lld",&inp[i].first,&inp[i].second);
if(A>inf/B)segments.push_back(inp[i]);
else
{
if(inp[i].second-inp[i].first+1>=A*B)
{
printf("%lld\n",A*B);
return 0;
}
inp[i].first=inp[i].first%(A*B);
inp[i].second=inp[i].second%(A*B);
if(inp[i].first<=inp[i].second)segments.push_back(inp[i]);
else
{
segments.push_back({inp[i].first,A*B-1});
segments.push_back({0,inp[i].second});
}
}
}
for(auto k:segments)
{
active.push_back({k.first,1});
active.push_back({k.second+1,-1});
//cout<<k.first<<" "<<k.second<<endl;
}
sort(active.begin(),active.end(),cmp);
int sum=1;
long long output=0;
for(int i=1;i<active.size();i++)
{
if(sum)output+=active[i].first-active[i-1].first;
sum=sum+active[i].second;
//cout<<i<<" -> "<<sum<<" "<<output<<" "<<active[i].first<<" "<<active[i].second<<endl;
}
printf("%lld\n",output);
return 0;
}
Compilation message (stderr)
# | 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... |