//0 1 1 0 1
//0 1 0 0 1
//1 0 0 1 1
//0 1 1 0 1
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx2")
using namespace std;
#define F first
#define S second
#define pb push_back
#define sze size()
#define all(x) x.begin() , x.end()
#define wall__ cout << "--------------------------------------\n";
#define kids int mid = (tl + tr) >> 1, cl = v << 1, cr = v << 1 | 1
#define file_io freopen("input.cpp", "r", stdin); freopen("output.cpp", "w", stdout);
typedef long long ll;
typedef long double dl;
typedef pair < int , int > pii;
typedef pair < int , ll > pil;
typedef pair < ll , int > pli;
typedef pair < ll , ll > pll;
typedef pair < int , pii > piii;
typedef pair < ll, pll > plll;
const ll N = 2e5 + 10;
const ll mod = 1e9 + 7;
const ll inf = 5e18;
const ll rinf = -2e18;
const ll INF = 1e9 + 10;
const ll rINF = -1e9 - 10;
const ll lg = 32;
set < plll > s;
plll find (ll id) {
auto it = s.lower_bound({id + 1ll, {0, 0}});
it = prev(it);
return *it;
}
void add (ll l, ll r) {
plll x = find(l);
if (x.F < l) {
s.erase(x);
s.insert({x.F, {l - 1ll, x.S.S}});
s.insert({l, x.S});
}
x = find(r);
if (x.S.F > r) {
s.erase(x);
s.insert({x.F, {r, x.S.S}});
s.insert({r + 1ll, x.S});
}
x = *s.lower_bound({l, {0, 0}});
while (x.F <= r) {
s.erase(x);
if (x.S.F == r) break;
x = *s.lower_bound({l, {0, 0}});
}
s.insert({l, {r, 1}});
}
void solve () {
int n;
ll A, B;
cin >> n >> A >> B;
dl a = A, b = (B + 1ll);
dl x = __gcd(A, B + 1ll);
dl lcm = (a * b) / x;
dl y = lcm / b;
dl bb = B;
dl z = y * bb;
ll t;
if (z > 1e18) t = 1e8;
else t = z;
s.insert({0, {t - 1ll, 0}});
s.insert({inf, {inf, inf}});
s.insert({-1, {-1, -1}});
bool ch = 0;
ll en = t - 1ll;
for (int i = 1; i <= n; i++) {
ll l, r; cin >> l >> r;
ll len = (r - l + 1ll);
if (len >= t) {
ch = 1;
add(0, en);
}
if (ch) continue;
l = l % t;
r = r % t;
if (l <= r) add(l, r);
else {
add(l, en);
add(0, r);
}
}
ll ans = 0;
for (auto it = s.begin(); it != s.end(); ++it) {
plll x = *it;
if (x.S.S == 1) ans += (x.S.F - x.F + 1ll);
}
cout << ans << '\n';
}
int main() {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int t = 1;
// cin >> t;
while (t--) {solve();}
return 0;
}
/*
*/
//inhonorofsbi;
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
12 ms |
932 KB |
Output is correct |
3 |
Correct |
11 ms |
852 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
228 KB |
Output is correct |
16 |
Correct |
10 ms |
896 KB |
Output is correct |
17 |
Correct |
141 ms |
6528 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
320 ms |
296 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1505 ms |
62844 KB |
Output is correct |
3 |
Correct |
1558 ms |
62956 KB |
Output is correct |
4 |
Correct |
1790 ms |
74040 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1505 ms |
62844 KB |
Output is correct |
3 |
Correct |
1558 ms |
62956 KB |
Output is correct |
4 |
Correct |
1790 ms |
74040 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1529 ms |
73576 KB |
Output is correct |
7 |
Correct |
1585 ms |
73368 KB |
Output is correct |
8 |
Correct |
1543 ms |
73416 KB |
Output is correct |
9 |
Correct |
1724 ms |
73260 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1505 ms |
62844 KB |
Output is correct |
3 |
Correct |
1558 ms |
62956 KB |
Output is correct |
4 |
Correct |
1790 ms |
74040 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
108 ms |
10184 KB |
Output is correct |
7 |
Correct |
105 ms |
10212 KB |
Output is correct |
8 |
Correct |
118 ms |
10192 KB |
Output is correct |
9 |
Correct |
145 ms |
10268 KB |
Output is correct |
10 |
Correct |
120 ms |
10280 KB |
Output is correct |
11 |
Correct |
118 ms |
10220 KB |
Output is correct |
12 |
Correct |
121 ms |
10264 KB |
Output is correct |
13 |
Correct |
143 ms |
10228 KB |
Output is correct |
14 |
Correct |
110 ms |
10164 KB |
Output is correct |
15 |
Correct |
148 ms |
10284 KB |
Output is correct |
16 |
Correct |
148 ms |
10220 KB |
Output is correct |
17 |
Correct |
134 ms |
10184 KB |
Output is correct |
18 |
Correct |
1427 ms |
73144 KB |
Output is correct |
19 |
Correct |
1678 ms |
73444 KB |
Output is correct |
20 |
Correct |
1810 ms |
73756 KB |
Output is correct |
21 |
Correct |
124 ms |
10164 KB |
Output is correct |
22 |
Correct |
144 ms |
10164 KB |
Output is correct |
23 |
Correct |
157 ms |
9304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
152 ms |
6612 KB |
Output is correct |
3 |
Correct |
155 ms |
6452 KB |
Output is correct |
4 |
Correct |
1726 ms |
63832 KB |
Output is correct |
5 |
Correct |
162 ms |
10232 KB |
Output is correct |
6 |
Correct |
162 ms |
10188 KB |
Output is correct |
7 |
Correct |
162 ms |
10240 KB |
Output is correct |
8 |
Correct |
154 ms |
10188 KB |
Output is correct |
9 |
Correct |
140 ms |
10204 KB |
Output is correct |
10 |
Correct |
118 ms |
10276 KB |
Output is correct |
11 |
Correct |
134 ms |
10260 KB |
Output is correct |
12 |
Correct |
127 ms |
10272 KB |
Output is correct |
13 |
Correct |
155 ms |
10192 KB |
Output is correct |
14 |
Correct |
1820 ms |
64148 KB |
Output is correct |
15 |
Correct |
110 ms |
10252 KB |
Output is correct |
16 |
Correct |
1407 ms |
73372 KB |
Output is correct |
17 |
Correct |
1422 ms |
73292 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
12 ms |
932 KB |
Output is correct |
3 |
Correct |
11 ms |
852 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
228 KB |
Output is correct |
16 |
Correct |
10 ms |
896 KB |
Output is correct |
17 |
Correct |
141 ms |
6528 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
0 ms |
212 KB |
Output is correct |
25 |
Correct |
2 ms |
340 KB |
Output is correct |
26 |
Correct |
2 ms |
340 KB |
Output is correct |
27 |
Correct |
2 ms |
340 KB |
Output is correct |
28 |
Correct |
320 ms |
296 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
1505 ms |
62844 KB |
Output is correct |
31 |
Correct |
1558 ms |
62956 KB |
Output is correct |
32 |
Correct |
1790 ms |
74040 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
1529 ms |
73576 KB |
Output is correct |
35 |
Correct |
1585 ms |
73368 KB |
Output is correct |
36 |
Correct |
1543 ms |
73416 KB |
Output is correct |
37 |
Correct |
1724 ms |
73260 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
108 ms |
10184 KB |
Output is correct |
40 |
Correct |
105 ms |
10212 KB |
Output is correct |
41 |
Correct |
118 ms |
10192 KB |
Output is correct |
42 |
Correct |
145 ms |
10268 KB |
Output is correct |
43 |
Correct |
120 ms |
10280 KB |
Output is correct |
44 |
Correct |
118 ms |
10220 KB |
Output is correct |
45 |
Correct |
121 ms |
10264 KB |
Output is correct |
46 |
Correct |
143 ms |
10228 KB |
Output is correct |
47 |
Correct |
110 ms |
10164 KB |
Output is correct |
48 |
Correct |
148 ms |
10284 KB |
Output is correct |
49 |
Correct |
148 ms |
10220 KB |
Output is correct |
50 |
Correct |
134 ms |
10184 KB |
Output is correct |
51 |
Correct |
1427 ms |
73144 KB |
Output is correct |
52 |
Correct |
1678 ms |
73444 KB |
Output is correct |
53 |
Correct |
1810 ms |
73756 KB |
Output is correct |
54 |
Correct |
124 ms |
10164 KB |
Output is correct |
55 |
Correct |
144 ms |
10164 KB |
Output is correct |
56 |
Correct |
157 ms |
9304 KB |
Output is correct |
57 |
Correct |
1 ms |
212 KB |
Output is correct |
58 |
Correct |
152 ms |
6612 KB |
Output is correct |
59 |
Correct |
155 ms |
6452 KB |
Output is correct |
60 |
Correct |
1726 ms |
63832 KB |
Output is correct |
61 |
Correct |
162 ms |
10232 KB |
Output is correct |
62 |
Correct |
162 ms |
10188 KB |
Output is correct |
63 |
Correct |
162 ms |
10240 KB |
Output is correct |
64 |
Correct |
154 ms |
10188 KB |
Output is correct |
65 |
Correct |
140 ms |
10204 KB |
Output is correct |
66 |
Correct |
118 ms |
10276 KB |
Output is correct |
67 |
Correct |
134 ms |
10260 KB |
Output is correct |
68 |
Correct |
127 ms |
10272 KB |
Output is correct |
69 |
Correct |
155 ms |
10192 KB |
Output is correct |
70 |
Correct |
1820 ms |
64148 KB |
Output is correct |
71 |
Correct |
110 ms |
10252 KB |
Output is correct |
72 |
Correct |
1407 ms |
73372 KB |
Output is correct |
73 |
Correct |
1422 ms |
73292 KB |
Output is correct |
74 |
Correct |
0 ms |
212 KB |
Output is correct |
75 |
Correct |
1 ms |
324 KB |
Output is correct |
76 |
Correct |
1 ms |
212 KB |
Output is correct |
77 |
Correct |
1 ms |
212 KB |
Output is correct |
78 |
Correct |
1 ms |
212 KB |
Output is correct |
79 |
Correct |
11 ms |
1236 KB |
Output is correct |
80 |
Correct |
1773 ms |
75656 KB |
Output is correct |
81 |
Correct |
1630 ms |
75800 KB |
Output is correct |
82 |
Correct |
1821 ms |
75556 KB |
Output is correct |
83 |
Correct |
1811 ms |
75772 KB |
Output is correct |
84 |
Correct |
1913 ms |
75508 KB |
Output is correct |
85 |
Correct |
1709 ms |
75620 KB |
Output is correct |
86 |
Correct |
140 ms |
12828 KB |
Output is correct |
87 |
Correct |
1 ms |
212 KB |
Output is correct |