이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define ret return 0
#define con continue
#define db double
#define gcd __gcd
#define freopen freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
using namespace std;
ll n,m,ans,cnt,x,y,z,u;
ll i,j,r,l,k;
ll a[1234567],b[1234567],d[1234567],e[1234567];
map <ll,ll> f;
set<pair<ll,ll>> s;
set<int>::iterator it;
vector <ll> c[1234567];
string p,q,w;
ll lcm(ll x,ll y){
ll z=gcd(x,y);
return x*y/z;
}
int main(){
ll A,B;
cin>>n>>A>>B;
z=A/__gcd(A,B+1);
if (z>1e18/B){
z=1000000000000000001;
}else{
z*=B;
}
while (n--){
cin>>l>>r;
if (r-l+1>=z){
cout<<z;
ret;
}
l%=z;
r%=z;
if (l<=r){
s.insert({l,r});
}else {
s.insert({0,r});
s.insert({l,z-1});
}
}
ll mm=-1;
while (s.size()!=0){
auto t=*s.begin();
s.erase(*s.begin());
x=t.first;
y=t.second;
mm=max(mm,x-1);
ans+=max(y-mm,0ll);
mm=max(y,mm);
}
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... |