This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int ll
#define endl '\n' //comment for interactive
#define fast_io ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb push_back
#define re resize
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define loop(i, n) for(int i = 0; i < n; i++)
#define loop1(i, n) for(int i = 1; i <= n; i++)
#define print(x) cout << #x << ": " << x << endl << flush
typedef long long ll;
typedef vector<int> vi;
typedef array<int, 2> ii;
typedef array<int, 3> ti;
typedef vector<ii> vii;
typedef vector<ti> vti;
typedef priority_queue<int> pq;
template<class T> bool ckmin(T&a, T b) { bool B = a > b; a = min(a, b); return B; }
template<class T> bool ckmax(T&a, T b) { bool B = a < b; a = max(a, b); return B; }
const int inf = 1e17;
//const int maxn = ;
void solve() {
int n, a, b;
cin >> n >> a >> b;
int p = 1.1e18;
if((float) b * a / __gcd(a, b+1) < p)
p = b * a / __gcd(a, b+1);
vii intvl;
loop(i, n) {
int l, r; cin >> l >> r;
if(r - l + 1 >= p) intvl.pb({0, p-1});
else {
int x = l/p;
l -= x*p;
r -= x*p;
if(r >= p) {
intvl.pb({l, p-1});
intvl.pb({0, r-p});
} else {
intvl.pb({l, r});
}
}
}
vii pts;
for(auto [a, b] : intvl) {
pts.pb({a, 1});
pts.pb({b, 2});
}
sort(all(pts));
int st = -1;
int cnt = 0;
int res = 0;
for(auto [x, t] : pts) {
if(t == 1) {
if(cnt) cnt++;
else {
st = x;
cnt++;
}
} else {
cnt--;
if(cnt) {}
else
res += x - st + 1;
}
}
cout << res << endl;
}
signed main() {
fast_io;
int t = 1; //cin >> t;
while(t--)
solve();
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... |