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 <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pll;
ll N,A,B;
ll L[1000006],R[1000006];
ll x,y;
vector<pll> S;
vector<pll> V;
ll ans,K;
int main(){
cin>>N>>A>>B;
ll M=(A*B);
for(int i=0;i<N;i++){
cin>>L[i]>>R[i];
x=L[i]%M;
y=R[i]%M;
if(y<x){
if(R[i]-L[i]>=M){
V.push_back({0,1});
V.push_back({M,-1});
}
else{
V.push_back({0,1});
V.push_back({y+1,-1});
V.push_back({x,1});
V.push_back({M,-1});
}
}
else{
V.push_back({x,1});
V.push_back({y+1,-1});
}
}
V.push_back({0,0});
sort(V.begin(),V.end());
for(pll p:V){
if(!S.empty() and p.first==S.back().first)
S.back().second+=p.second;
else
S.push_back(p);
}
pll q=*S.begin();
for(pll p:S){
if(K)
ans+=p.first-q.first;
K+=p.second;
q=p;
}
cout<<ans;
}
# | 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... |