#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
using namespace std;
template <typename T>
using bstring = basic_string<T>;
template <typename T>
using matrix = vector<vector<T>>;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll INFL = (1LL<<62)-1;
const int INF = (1<<30)-1;
const double EPS = 1e-7;
const int MOD = 998244353;
const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
const ll MAXN = 1e18+10;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
ll n, a, b;
cin >> n >> a >> b;
a/=gcd(b+1,a);
bool beeg = (MAXN+b-1)/b < a;
vector<pll> v(n);
ll resp = 0;
vector<pll> interval;
for(auto& [l, r] : v){
cin >> l >> r;
if(beeg){
resp+=r-l+1;
} else {
if(r-l+1 >= a*b){
cout << a*b << '\n';
return 0;
}
ll tl = l%(a*b), tr = r%(a*b);
if(tl <= tr){
interval.push_back({tl,tr});
} else {
interval.push_back({tl,a*b-1});
interval.push_back({0,tr});
}
}
}
if(beeg){
cout << resp << '\n';
return 0;
}
sort(all(interval));
ll counted = -1;
for(auto [l,r] : interval){
if(counted < l){
resp+=r-l+1;
counted = r;
} else {
resp+=max(0ll,r-counted);
counted = max(counted,r);
}
}
cout << resp << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
5 ms |
1236 KB |
Output is correct |
3 |
Correct |
5 ms |
1236 KB |
Output is correct |
4 |
Correct |
0 ms |
316 KB |
Output is correct |
5 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
316 KB |
Output is correct |
13 |
Correct |
1 ms |
320 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
316 KB |
Output is correct |
16 |
Correct |
5 ms |
1224 KB |
Output is correct |
17 |
Correct |
51 ms |
7192 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
320 KB |
Output is correct |
4 |
Correct |
1 ms |
316 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
380 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Correct |
407 ms |
57044 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
454 ms |
32604 KB |
Output is correct |
3 |
Correct |
443 ms |
32552 KB |
Output is correct |
4 |
Correct |
385 ms |
32552 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
454 ms |
32604 KB |
Output is correct |
3 |
Correct |
443 ms |
32552 KB |
Output is correct |
4 |
Correct |
385 ms |
32552 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
422 ms |
32516 KB |
Output is correct |
7 |
Correct |
419 ms |
32796 KB |
Output is correct |
8 |
Correct |
387 ms |
32616 KB |
Output is correct |
9 |
Correct |
448 ms |
32544 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
454 ms |
32604 KB |
Output is correct |
3 |
Correct |
443 ms |
32552 KB |
Output is correct |
4 |
Correct |
385 ms |
32552 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
43 ms |
5052 KB |
Output is correct |
7 |
Correct |
54 ms |
5020 KB |
Output is correct |
8 |
Correct |
44 ms |
4372 KB |
Output is correct |
9 |
Correct |
44 ms |
4372 KB |
Output is correct |
10 |
Correct |
40 ms |
4448 KB |
Output is correct |
11 |
Correct |
41 ms |
4452 KB |
Output is correct |
12 |
Correct |
39 ms |
4412 KB |
Output is correct |
13 |
Correct |
47 ms |
4424 KB |
Output is correct |
14 |
Correct |
38 ms |
4424 KB |
Output is correct |
15 |
Correct |
41 ms |
4328 KB |
Output is correct |
16 |
Correct |
44 ms |
7388 KB |
Output is correct |
17 |
Correct |
42 ms |
7200 KB |
Output is correct |
18 |
Correct |
441 ms |
68948 KB |
Output is correct |
19 |
Correct |
424 ms |
68960 KB |
Output is correct |
20 |
Correct |
469 ms |
68840 KB |
Output is correct |
21 |
Correct |
45 ms |
7216 KB |
Output is correct |
22 |
Correct |
55 ms |
7244 KB |
Output is correct |
23 |
Correct |
144 ms |
23772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
43 ms |
4344 KB |
Output is correct |
3 |
Correct |
46 ms |
4376 KB |
Output is correct |
4 |
Correct |
460 ms |
32600 KB |
Output is correct |
5 |
Correct |
39 ms |
3996 KB |
Output is correct |
6 |
Correct |
42 ms |
4048 KB |
Output is correct |
7 |
Correct |
40 ms |
4040 KB |
Output is correct |
8 |
Correct |
40 ms |
3996 KB |
Output is correct |
9 |
Correct |
45 ms |
3972 KB |
Output is correct |
10 |
Correct |
42 ms |
4068 KB |
Output is correct |
11 |
Correct |
41 ms |
4092 KB |
Output is correct |
12 |
Correct |
36 ms |
4060 KB |
Output is correct |
13 |
Correct |
40 ms |
4080 KB |
Output is correct |
14 |
Correct |
446 ms |
32516 KB |
Output is correct |
15 |
Correct |
47 ms |
7256 KB |
Output is correct |
16 |
Correct |
425 ms |
68872 KB |
Output is correct |
17 |
Correct |
420 ms |
68832 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
5 ms |
1236 KB |
Output is correct |
3 |
Correct |
5 ms |
1236 KB |
Output is correct |
4 |
Correct |
0 ms |
316 KB |
Output is correct |
5 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
316 KB |
Output is correct |
13 |
Correct |
1 ms |
320 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
316 KB |
Output is correct |
16 |
Correct |
5 ms |
1224 KB |
Output is correct |
17 |
Correct |
51 ms |
7192 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
320 KB |
Output is correct |
22 |
Correct |
1 ms |
316 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
328 KB |
Output is correct |
26 |
Correct |
1 ms |
380 KB |
Output is correct |
27 |
Correct |
1 ms |
328 KB |
Output is correct |
28 |
Correct |
407 ms |
57044 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
454 ms |
32604 KB |
Output is correct |
31 |
Correct |
443 ms |
32552 KB |
Output is correct |
32 |
Correct |
385 ms |
32552 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
422 ms |
32516 KB |
Output is correct |
35 |
Correct |
419 ms |
32796 KB |
Output is correct |
36 |
Correct |
387 ms |
32616 KB |
Output is correct |
37 |
Correct |
448 ms |
32544 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
43 ms |
5052 KB |
Output is correct |
40 |
Correct |
54 ms |
5020 KB |
Output is correct |
41 |
Correct |
44 ms |
4372 KB |
Output is correct |
42 |
Correct |
44 ms |
4372 KB |
Output is correct |
43 |
Correct |
40 ms |
4448 KB |
Output is correct |
44 |
Correct |
41 ms |
4452 KB |
Output is correct |
45 |
Correct |
39 ms |
4412 KB |
Output is correct |
46 |
Correct |
47 ms |
4424 KB |
Output is correct |
47 |
Correct |
38 ms |
4424 KB |
Output is correct |
48 |
Correct |
41 ms |
4328 KB |
Output is correct |
49 |
Correct |
44 ms |
7388 KB |
Output is correct |
50 |
Correct |
42 ms |
7200 KB |
Output is correct |
51 |
Correct |
441 ms |
68948 KB |
Output is correct |
52 |
Correct |
424 ms |
68960 KB |
Output is correct |
53 |
Correct |
469 ms |
68840 KB |
Output is correct |
54 |
Correct |
45 ms |
7216 KB |
Output is correct |
55 |
Correct |
55 ms |
7244 KB |
Output is correct |
56 |
Correct |
144 ms |
23772 KB |
Output is correct |
57 |
Correct |
1 ms |
212 KB |
Output is correct |
58 |
Correct |
43 ms |
4344 KB |
Output is correct |
59 |
Correct |
46 ms |
4376 KB |
Output is correct |
60 |
Correct |
460 ms |
32600 KB |
Output is correct |
61 |
Correct |
39 ms |
3996 KB |
Output is correct |
62 |
Correct |
42 ms |
4048 KB |
Output is correct |
63 |
Correct |
40 ms |
4040 KB |
Output is correct |
64 |
Correct |
40 ms |
3996 KB |
Output is correct |
65 |
Correct |
45 ms |
3972 KB |
Output is correct |
66 |
Correct |
42 ms |
4068 KB |
Output is correct |
67 |
Correct |
41 ms |
4092 KB |
Output is correct |
68 |
Correct |
36 ms |
4060 KB |
Output is correct |
69 |
Correct |
40 ms |
4080 KB |
Output is correct |
70 |
Correct |
446 ms |
32516 KB |
Output is correct |
71 |
Correct |
47 ms |
7256 KB |
Output is correct |
72 |
Correct |
425 ms |
68872 KB |
Output is correct |
73 |
Correct |
420 ms |
68832 KB |
Output is correct |
74 |
Correct |
1 ms |
212 KB |
Output is correct |
75 |
Correct |
1 ms |
212 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 |
5 ms |
1228 KB |
Output is correct |
80 |
Correct |
536 ms |
68952 KB |
Output is correct |
81 |
Correct |
495 ms |
68856 KB |
Output is correct |
82 |
Correct |
441 ms |
68924 KB |
Output is correct |
83 |
Correct |
451 ms |
68936 KB |
Output is correct |
84 |
Correct |
446 ms |
68960 KB |
Output is correct |
85 |
Correct |
478 ms |
68820 KB |
Output is correct |
86 |
Correct |
136 ms |
23780 KB |
Output is correct |
87 |
Correct |
1 ms |
212 KB |
Output is correct |