This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,popcnt,sse4,abm")
#include <bits/stdc++.h>
using namespace std;
#ifdef WAIMAI
#define debug(HEHE...) cout << "[" << #HEHE << "] : ", dout(HEHE)
void dout() {cout << '\n';}
template<typename T, typename...U>
void dout(T t, U...u) {cout << t << (sizeof...(u) ? ", " : ""), dout(u...);}
#else
#define debug(...) 7122
#endif
#define ll long long
#define Waimai ios::sync_with_stdio(false), cin.tie(0)
#define FOR(x,a,b) for (int x = a, I = b; x <= I; x++)
#define pb emplace_back
#define F first
#define S second
const int INF = 2e18;
int n;
ll a, b, len, ans;
vector<pair<ll, ll>> v;
void solve() {
cin >> n >> a >> b;
len = a / gcd(a, b + 1);
if ((__int128) len * b >= INF) len = INF;
else len *= b;
while (n--) {
ll l, r;
cin >> l >> r;
if (r - l + 1 >= len) {
cout << len << '\n';
return;
}
if (l % len <= r % len) v.pb(l % len, r % len);
else v.pb(l % len, len - 1), v.pb(0, r % len);
}
sort(v.begin(), v.end());
ll R = -1;
for (auto [l, r] : v) {
if (l > R) R = l;
if (r >= R) {
ans += r - R + 1;
R = r + 1;
}
}
cout << ans << '\n';
}
int main() {
Waimai;
solve();
}
Compilation message (stderr)
strange_device.cpp:22:17: warning: overflow in conversion from 'double' to 'int' changes value from '2.0e+18' to '2147483647' [-Woverflow]
22 | const int INF = 2e18;
| ^~~~
# | 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... |