// Zende bad Shoma nasime faghat !
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " : " << x << '\n'
using namespace std;
typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;
const ll Mod = 1000000007LL;
const int N = 2e5 + 10;
const ll Inf = 2242545357980376863LL;
const ll Log = 30;
int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll n, A, B;
cin >> n >> A >> B;
ll z = A / __gcd(A, B + 1);
ll L = z * B;
vector<pll> V;
ll l, r;
for(int i = 0; i < n; i++){
cin >> l >> r;
if(r - l + 1 >= L) return cout << L << '\n', 0;
if(l % L <= r % L) V.pb({l % L, r % L});
else {
V.pb({l % L, L - 1});
V.pb({0, r % L});
}
}
sort(all(V));
ll ans = L;
ll la = -1;
for(auto x : V){
ans -= max(0ll, x.F - la - 1);
la = max(la, x.S);
}
ans -= max(0ll, L - la - 1);
cout << ans << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
1152 KB |
Output is correct |
3 |
Correct |
6 ms |
1152 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
6 ms |
1152 KB |
Output is correct |
17 |
Correct |
57 ms |
5724 KB |
Output is correct |
18 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
361 ms |
41408 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
505 ms |
53316 KB |
Output is correct |
3 |
Correct |
541 ms |
53384 KB |
Output is correct |
4 |
Correct |
539 ms |
53440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
505 ms |
53316 KB |
Output is correct |
3 |
Correct |
541 ms |
53384 KB |
Output is correct |
4 |
Correct |
539 ms |
53440 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
517 ms |
53312 KB |
Output is correct |
7 |
Correct |
510 ms |
53312 KB |
Output is correct |
8 |
Correct |
508 ms |
53312 KB |
Output is correct |
9 |
Correct |
551 ms |
53436 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
505 ms |
53316 KB |
Output is correct |
3 |
Correct |
541 ms |
53384 KB |
Output is correct |
4 |
Correct |
539 ms |
53440 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
53 ms |
5740 KB |
Output is correct |
7 |
Correct |
55 ms |
5740 KB |
Output is correct |
8 |
Correct |
52 ms |
5736 KB |
Output is correct |
9 |
Correct |
52 ms |
5736 KB |
Output is correct |
10 |
Correct |
51 ms |
5740 KB |
Output is correct |
11 |
Correct |
53 ms |
5868 KB |
Output is correct |
12 |
Correct |
50 ms |
5864 KB |
Output is correct |
13 |
Correct |
53 ms |
5736 KB |
Output is correct |
14 |
Correct |
50 ms |
5740 KB |
Output is correct |
15 |
Correct |
55 ms |
5736 KB |
Output is correct |
16 |
Correct |
55 ms |
5740 KB |
Output is correct |
17 |
Correct |
53 ms |
5792 KB |
Output is correct |
18 |
Correct |
548 ms |
53312 KB |
Output is correct |
19 |
Correct |
507 ms |
53560 KB |
Output is correct |
20 |
Correct |
601 ms |
53444 KB |
Output is correct |
21 |
Correct |
57 ms |
5740 KB |
Output is correct |
22 |
Correct |
50 ms |
5736 KB |
Output is correct |
23 |
Correct |
171 ms |
18528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
57 ms |
5744 KB |
Output is correct |
3 |
Correct |
57 ms |
5740 KB |
Output is correct |
4 |
Correct |
576 ms |
53312 KB |
Output is correct |
5 |
Correct |
56 ms |
5736 KB |
Output is correct |
6 |
Correct |
55 ms |
5784 KB |
Output is correct |
7 |
Correct |
53 ms |
5736 KB |
Output is correct |
8 |
Correct |
60 ms |
5740 KB |
Output is correct |
9 |
Correct |
55 ms |
5692 KB |
Output is correct |
10 |
Correct |
56 ms |
5740 KB |
Output is correct |
11 |
Correct |
55 ms |
5740 KB |
Output is correct |
12 |
Correct |
52 ms |
5740 KB |
Output is correct |
13 |
Correct |
55 ms |
5740 KB |
Output is correct |
14 |
Correct |
589 ms |
53568 KB |
Output is correct |
15 |
Correct |
53 ms |
5736 KB |
Output is correct |
16 |
Correct |
539 ms |
53312 KB |
Output is correct |
17 |
Correct |
520 ms |
53312 KB |
Output is correct |
18 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
1152 KB |
Output is correct |
3 |
Correct |
6 ms |
1152 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
6 ms |
1152 KB |
Output is correct |
17 |
Correct |
57 ms |
5724 KB |
Output is correct |
18 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |