//#pragma GCC optimize ("Ofast")
//#pragma GCC target("avx2")
//#pragma GCC optimize("unroll-loops")
//#include <x86intrin.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
#define PI 3.141592653589793L
#define FAST ios::sync_with_stdio(false); cin.tie(NULL);
// Use for file I/O;
#define FIN string _fname = "input"; \
string _is = _fname + ".in", _os = _fname + ".out"; \
freopen(_is.c_str(), "r", stdin); \
freopen(_os.c_str(), "w", stdout);
#define FIN2 freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define RINIT mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define gsize(x) (int)((x).size())
using namespace std;
//using namespace __gnu_pbds;
//typedef gp_hash_table<int, int, hash<int>> ht;
const char nl = '\n';
typedef long long ll;
typedef long double ld;
// typedef unsigned int uint;
typedef unsigned long long ull;
const ll inf = 1e9 + 10;
const ll inf2 = 1e18 + 99LL;
const ld inf3 = 1e17;
const ll mod = 1e9+7, mod2 = 998244353;
const ld eps = 1e-9;
const bool local = false;
//RINIT;
const int logn = 21, maxn = 1000000, maxm = 100000, maxn2 = 3;
int main() {
FAST;
int n;
cin >> n;
ll ta, tb;
cin >> ta >> tb;
//auto g = gcd(ta, tb);
//ta /= g; tb /= g;
//cout << ta << ' ' << tb << ' ' << tn << nl;
__int128 a = ta, b = tb;
//a /= g;
//b /= g;
__int128 tn = a * b;
vector<pair<ll, ll>> segs;
while (n--) {
ll l, r;
cin >> l >> r;
if (r - l + 1 >= tn) {
segs.emplace_back(0, 1);
segs.emplace_back(tn, -1);
} else {
l %= tn;
r %= tn;
if (l <= r) {
segs.emplace_back(l, 1);
segs.emplace_back(r + 1, -1);
} else {
segs.emplace_back(0, 1);
segs.emplace_back(r + 1, -1);
segs.emplace_back(l, 1);
segs.emplace_back(tn, -1);
}
}
}
sort(all(segs));
ll ans = 0, ti = 0, px = -1, ct = 0;
while (ti < gsize(segs)) {
ll tx = segs[ti].first;
if (ct) ans += tx - px;
px = tx;
while (ti < gsize(segs) && segs[ti].first == tx) {
ct += segs[ti].second;
ti++;
}
}
cout << ans << nl;
}
// © Benq
/* stuff you should look for
* int overflow, array bounds
* special cases (n=1?)
* do smth instead of nothing and stay organized
* WRITE STUFF DOWN
* DON'T GET STUCK ON ONE APPROACH
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
6 ms |
976 KB |
Output is correct |
3 |
Correct |
6 ms |
848 KB |
Output is correct |
4 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
312 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
413 ms |
33276 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
618 ms |
33232 KB |
Output is correct |
3 |
Incorrect |
557 ms |
36004 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
618 ms |
33232 KB |
Output is correct |
3 |
Incorrect |
557 ms |
36004 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
618 ms |
33232 KB |
Output is correct |
3 |
Incorrect |
557 ms |
36004 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
68 ms |
7196 KB |
Output is correct |
3 |
Correct |
69 ms |
7196 KB |
Output is correct |
4 |
Correct |
764 ms |
37288 KB |
Output is correct |
5 |
Correct |
67 ms |
7176 KB |
Output is correct |
6 |
Correct |
70 ms |
7256 KB |
Output is correct |
7 |
Correct |
67 ms |
7180 KB |
Output is correct |
8 |
Correct |
69 ms |
7224 KB |
Output is correct |
9 |
Correct |
66 ms |
7188 KB |
Output is correct |
10 |
Correct |
70 ms |
7212 KB |
Output is correct |
11 |
Correct |
66 ms |
7220 KB |
Output is correct |
12 |
Correct |
59 ms |
7220 KB |
Output is correct |
13 |
Correct |
70 ms |
7200 KB |
Output is correct |
14 |
Correct |
723 ms |
37316 KB |
Output is correct |
15 |
Incorrect |
71 ms |
7228 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
6 ms |
976 KB |
Output is correct |
3 |
Correct |
6 ms |
848 KB |
Output is correct |
4 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |