이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define AquA cin.tie(0);ios_base::sync_with_stdio(0);
#define fs first
#define sc second
#define p_q priority_queue
using namespace std;
long long inf=2e18;
long long mul(long long x,long long y){
long long sum=inf;
if(sum/x>=y-2){
sum=min(sum,x*y);
}
return sum;
}
int main(){
AquA;
long long n,a,b;
cin >> n >> a >> b;
long long u=__gcd(a,(b+1));
a/=u;
long long sum=mul(a,b);
vector<pair<long long,long long> > x;
for(int i=0;i<n;i++){
long long l,r;
cin >> l >> r;
if(r/sum>l/sum+1){
cout << sum << "\n";
return 0;
}
if(r/sum==l/sum){
x.push_back({l%sum,r%sum});
}
else{
x.push_back({l%sum,sum-1});
x.push_back({0%sum,r%sum});
}
}
sort(x.begin(),x.end());
long long ans=0;
long long nw=0;
for(auto h:x){
nw=max(nw,h.fs);
if(h.sc>=nw){
ans+=(h.sc-nw+1);
}
nw=max(nw,h.sc+1);
}
cout << ans << "\n";
return 0;
}
# | 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... |