이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// Zende bad Shoma nasime faghat !
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " : " << x << '\n'
using namespace std;
typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;
const ll Mod = 1000000007LL;
const int N = 2e5 + 10;
const ll Inf = 2242545357980376863LL;
const ll Log = 30;
int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll n, A, B;
cin >> n >> A >> B;
ll z = A / __gcd(A, B + 1);
ll L = z * B;
vector<pll> V;
ll l, r;
for(int i = 0; i < n; i++){
cin >> l >> r;
if(r - l + 1 >= L) return cout << L << '\n', 0;
if(l % L <= r % L) V.pb({l % L, r % L});
else {
V.pb({l % L, L - 1});
V.pb({0, r % L});
}
}
sort(all(V));
ll ans = L;
ll la = -1;
for(auto x : V){
ans -= max(0ll, x.F - la - 1);
la = max(la, x.S);
}
ans -= max(0ll, L - la - 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... |