#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define all(v) v.begin(), v.end()
#define pb push_back
#define ss second
#define ff first
#define vt vector
#define ih __int128
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int, int> pii;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int mod = 1e9+7;
const ll inf = 1e18 + 1;
const int maxn = 1e6 + 1;
set<pair<ih, ih>> s;
ll ans;
void upd(ll l, ll r){
if(s.empty())return;
vt<pair<ih, ih>> del;
auto i = s.lower_bound({l, inf});
if(i != s.begin())i--;
if((*i).ss < l)i++;
while(i != s.end() && (*i).ff <= r){
if((*i).ff < l){
s.insert({(*i).ff, l - 1});
ans -= l - (*i).ff;
}
if((*i).ss > r){
s.insert({r + 1, (*i).ss});
ans -= (*i).ss - r;
}
del.pb(*i);
ans += (*i).ss - (*i).ff + 1;
i++;
}
for(auto i : del)s.erase(i);
}
void solve() {
int n;
ih a, b;
ll A, B;
cin >> n >> A >> B;
a = A, b = B;
ih md = a * b / __gcd(a, b + 1);
s.insert({0, md - 1});
for(int i = 0; i < n; i++){
ll l, r;
cin >> l >> r;
if(r - l + 1 >= md){
ans = md;
break;
}
l %= md, r %= md;
if(l <= r)upd(l, r);
else upd(0, r), upd(l, md - 1);
}
cout << ans;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int times = 1;
//cin >> times;
for(int i = 1; i <= times; i++) {
solve();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
4 ms |
348 KB |
Output is correct |
3 |
Correct |
4 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
600 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
5 ms |
488 KB |
Output is correct |
17 |
Correct |
35 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
179 ms |
432 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
544 KB |
Output is correct |
2 |
Correct |
342 ms |
464 KB |
Output is correct |
3 |
Correct |
339 ms |
456 KB |
Output is correct |
4 |
Correct |
339 ms |
500 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
544 KB |
Output is correct |
2 |
Correct |
342 ms |
464 KB |
Output is correct |
3 |
Correct |
339 ms |
456 KB |
Output is correct |
4 |
Correct |
339 ms |
500 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
341 ms |
592 KB |
Output is correct |
7 |
Correct |
342 ms |
344 KB |
Output is correct |
8 |
Correct |
342 ms |
596 KB |
Output is correct |
9 |
Correct |
343 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
544 KB |
Output is correct |
2 |
Correct |
342 ms |
464 KB |
Output is correct |
3 |
Correct |
339 ms |
456 KB |
Output is correct |
4 |
Correct |
339 ms |
500 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
35 ms |
492 KB |
Output is correct |
7 |
Correct |
35 ms |
348 KB |
Output is correct |
8 |
Correct |
35 ms |
348 KB |
Output is correct |
9 |
Correct |
35 ms |
348 KB |
Output is correct |
10 |
Correct |
35 ms |
348 KB |
Output is correct |
11 |
Correct |
34 ms |
348 KB |
Output is correct |
12 |
Correct |
34 ms |
348 KB |
Output is correct |
13 |
Correct |
35 ms |
344 KB |
Output is correct |
14 |
Correct |
34 ms |
348 KB |
Output is correct |
15 |
Correct |
34 ms |
452 KB |
Output is correct |
16 |
Correct |
34 ms |
544 KB |
Output is correct |
17 |
Correct |
34 ms |
348 KB |
Output is correct |
18 |
Correct |
343 ms |
348 KB |
Output is correct |
19 |
Correct |
340 ms |
348 KB |
Output is correct |
20 |
Correct |
344 ms |
348 KB |
Output is correct |
21 |
Correct |
39 ms |
452 KB |
Output is correct |
22 |
Correct |
34 ms |
344 KB |
Output is correct |
23 |
Correct |
77 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
34 ms |
480 KB |
Output is correct |
3 |
Correct |
34 ms |
348 KB |
Output is correct |
4 |
Correct |
366 ms |
456 KB |
Output is correct |
5 |
Correct |
34 ms |
348 KB |
Output is correct |
6 |
Correct |
34 ms |
348 KB |
Output is correct |
7 |
Correct |
34 ms |
348 KB |
Output is correct |
8 |
Correct |
35 ms |
480 KB |
Output is correct |
9 |
Correct |
35 ms |
348 KB |
Output is correct |
10 |
Correct |
35 ms |
348 KB |
Output is correct |
11 |
Correct |
35 ms |
344 KB |
Output is correct |
12 |
Correct |
34 ms |
348 KB |
Output is correct |
13 |
Correct |
36 ms |
348 KB |
Output is correct |
14 |
Correct |
342 ms |
344 KB |
Output is correct |
15 |
Correct |
33 ms |
448 KB |
Output is correct |
16 |
Correct |
342 ms |
600 KB |
Output is correct |
17 |
Correct |
347 ms |
600 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
4 ms |
348 KB |
Output is correct |
3 |
Correct |
4 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
600 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
5 ms |
488 KB |
Output is correct |
17 |
Correct |
35 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
344 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
179 ms |
432 KB |
Output is correct |
29 |
Correct |
0 ms |
544 KB |
Output is correct |
30 |
Correct |
342 ms |
464 KB |
Output is correct |
31 |
Correct |
339 ms |
456 KB |
Output is correct |
32 |
Correct |
339 ms |
500 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
341 ms |
592 KB |
Output is correct |
35 |
Correct |
342 ms |
344 KB |
Output is correct |
36 |
Correct |
342 ms |
596 KB |
Output is correct |
37 |
Correct |
343 ms |
344 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
35 ms |
492 KB |
Output is correct |
40 |
Correct |
35 ms |
348 KB |
Output is correct |
41 |
Correct |
35 ms |
348 KB |
Output is correct |
42 |
Correct |
35 ms |
348 KB |
Output is correct |
43 |
Correct |
35 ms |
348 KB |
Output is correct |
44 |
Correct |
34 ms |
348 KB |
Output is correct |
45 |
Correct |
34 ms |
348 KB |
Output is correct |
46 |
Correct |
35 ms |
344 KB |
Output is correct |
47 |
Correct |
34 ms |
348 KB |
Output is correct |
48 |
Correct |
34 ms |
452 KB |
Output is correct |
49 |
Correct |
34 ms |
544 KB |
Output is correct |
50 |
Correct |
34 ms |
348 KB |
Output is correct |
51 |
Correct |
343 ms |
348 KB |
Output is correct |
52 |
Correct |
340 ms |
348 KB |
Output is correct |
53 |
Correct |
344 ms |
348 KB |
Output is correct |
54 |
Correct |
39 ms |
452 KB |
Output is correct |
55 |
Correct |
34 ms |
344 KB |
Output is correct |
56 |
Correct |
77 ms |
348 KB |
Output is correct |
57 |
Correct |
0 ms |
348 KB |
Output is correct |
58 |
Correct |
34 ms |
480 KB |
Output is correct |
59 |
Correct |
34 ms |
348 KB |
Output is correct |
60 |
Correct |
366 ms |
456 KB |
Output is correct |
61 |
Correct |
34 ms |
348 KB |
Output is correct |
62 |
Correct |
34 ms |
348 KB |
Output is correct |
63 |
Correct |
34 ms |
348 KB |
Output is correct |
64 |
Correct |
35 ms |
480 KB |
Output is correct |
65 |
Correct |
35 ms |
348 KB |
Output is correct |
66 |
Correct |
35 ms |
348 KB |
Output is correct |
67 |
Correct |
35 ms |
344 KB |
Output is correct |
68 |
Correct |
34 ms |
348 KB |
Output is correct |
69 |
Correct |
36 ms |
348 KB |
Output is correct |
70 |
Correct |
342 ms |
344 KB |
Output is correct |
71 |
Correct |
33 ms |
448 KB |
Output is correct |
72 |
Correct |
342 ms |
600 KB |
Output is correct |
73 |
Correct |
347 ms |
600 KB |
Output is correct |
74 |
Correct |
0 ms |
344 KB |
Output is correct |
75 |
Correct |
0 ms |
348 KB |
Output is correct |
76 |
Correct |
0 ms |
456 KB |
Output is correct |
77 |
Correct |
0 ms |
348 KB |
Output is correct |
78 |
Correct |
0 ms |
348 KB |
Output is correct |
79 |
Correct |
4 ms |
600 KB |
Output is correct |
80 |
Correct |
385 ms |
19140 KB |
Output is correct |
81 |
Correct |
354 ms |
19124 KB |
Output is correct |
82 |
Correct |
356 ms |
18920 KB |
Output is correct |
83 |
Correct |
347 ms |
19132 KB |
Output is correct |
84 |
Correct |
353 ms |
18892 KB |
Output is correct |
85 |
Correct |
365 ms |
19288 KB |
Output is correct |
86 |
Correct |
80 ms |
6840 KB |
Output is correct |
87 |
Correct |
0 ms |
544 KB |
Output is correct |