이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#include<ext/rope>
using namespace std;
using namespace __gnu_cxx;
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false);cin.tie(0)
#define fopen freopen("input.txt", "r", stdin)
#define eb emplace_back
#define em emplace
#define prec(a) cout<<fixed;cout.precision(a);
#define all(a) (a).begin(), (a).end()
typedef long long ll;typedef long double ld;typedef unsigned long long ul;typedef unsigned int ui;typedef pair<int,int> pii;typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tiii;
const ll INF = 2e18;
const int inf = 2e9;
template<class T>
void pr(T t) {cerr << t << " ";}
template<class T, class ...Args>
void pr(T a, Args ...args) {cerr << a << " ";pr(args...);}
template<class ...Args>
void prl(Args ...args) {pr(args...);cerr << endl;}
int n;
ll A, B, m, ans;
double tmp;
bool flag;
vector<pll> h;
int main(){
fastio;
cin>>n>>A>>B;
tmp = (double)A*B;
ll g = __gcd(A,B+1);
if((double)A/g>(double)1e18/B) m = 2e18;
else m = A*B/g;
for(int i=1;i<=n;i++){
ll a, b;
cin>>a>>b;
if(b-a+1>=m){
flag=true;
continue;
}
a%=m;b%=m;
if(a<=b) h.eb(a,b);
else{
h.eb(a,m-1);h.eb(0,b);
}
}
if(flag){
cout<<m;return 0;
}
sort(all(h));
ll ma=-1;
for(auto i:h){
ans = ans + max(i.fi-ma-1, 0LL);
ma = max(ma, i.se);
}
ans = ans + m-1-ma;
cout<<m-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... |