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 <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <set>
#include <map>
#include <queue>
#include <cstring>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <functional>
//#include <unordered_map>
using namespace std;
template<typename T> void uin(T &a, T b) {if (b < a) a = b;}
template<typename T> void uax(T &a, T b) {if (b > a) a = b;}
#define int long long
#define double long double
#define left left228
#define right right228
#define mp make_pair
#define all(v) v.begin(), v.end()
const int INF = 1100LL * 1000LL * 1000LL * 1000LL * 1000LL * 1000LL;
int gcd(int a, int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int mult(int a, int b) {
if (a > INF / b) {
return INF;
}
return min( INF, a * b );
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, A, B;
cin >> n >> A >> B;
int MOD = mult(A, B);
MOD /= gcd(A, B + 1);
set< pair<int,int> > s;
map<int,int>bal;
int ans = 0;
bool all = 0;
for (int i = 0; i < n; ++i) {
int l, r;
cin >> l >> r;
if (r - l + 1 >= MOD) {
all = 1;
}
int lm = l % MOD;
int rm = r % MOD;
if (lm <= rm) {
++bal[lm];
--bal[rm + 1];
} else {
++bal[lm];
--bal[MOD];
++bal[0];
--bal[rm + 1];
}
}
if (all) {
cout << MOD << '\n';
return 0;
}
vector< pair<int, int> > v;
for (auto p : bal) {
v.emplace_back(p);
}
int balance = 0;
for (int i = 0; i < (int)v.size() - 1; ++i) {
balance += v[i].second;
if (balance > 0) {
ans += v[i + 1].first - v[i].first;
}
}
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... |