이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
const long long N = ((long long) 1e18) + 5;
long long gcd(long long x, long long y) {
if (x < y) swap(x, y);
while (y) {
x %= y;
swap(x, y);
}
return x;
}
vector< pair<long long, long long> > v;
long long ans;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
long long n, a, b;
cin >> n >> a >> b;
long long aa = a / gcd(a, b + 1);
long long len;
if (aa > (N / b))
len = N;
else len = a * b;
for (int i = 0; i < n; i++) {
long long bg, en;
cin >> bg >> en;
if (en - bg >= len) {
cout << len << '\n';
exit(0);
}
bg %= len;
en %= len;
if (bg > en) {
v.push_back(make_pair(bg, len - 1));
v.push_back(make_pair(0, en));
} else {
v.push_back(make_pair(bg, en));
}
}
long long bg = 0, en = -1;
for (pair<long long, long long> x : v) {
long long bgg = x.first;
long long enn = x.second;
if (bgg > en) {
ans += en - bg + 1;
bg = bgg;
en = enn;
continue;
}
if (bgg <= en) {
en = max(en, enn);
}
}
ans += en - bg + 1;
cout << ans << '\n';
}
# | 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... |