#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0);
typedef long long ll;
#define f first
#define s second
#define LOGN 21
const ll MOD = 1e9 + 7;
const ll MAXN = 3e4 + 100;
#define int long long
set<pair<int,int>> st;
void add_seg(int l, int r) {
st.insert({l, r});
}
signed main() {
fast
ll n, A, B, mx = -1;
cin >> n >> A >> B;
if (B < A)
swap(A, B);
if ((((long long)1e9) * ((long long)1e9) + A - 1LL) / A <= B) {
int ans = 0;
for (int i = 0; i < n; i++) {
int l, r;
cin >> l >> r;
add_seg(l, r);
}
for (auto u : st) {
ans += max(0LL, (u.s - max(mx + 1, u.f)) + 1);
mx = max(mx, u.s);
}
cout << ans << "\n";
return 0;
}
A *= B;
bool control = true;
for (int i = 0; i < n; i++) {
int l, r;
cin >> l >> r;
if (r - l + 1 >= A) {
cout << A << "\n";
control = false;
}
int x = l % A;
int y = r % A;
if (y < x) {
add_seg(x, A-1);
add_seg(0, y);
} else
add_seg(x, y);
}
if (!control)
return 0;
ll ans = 0;
for (auto u : st) {
ans += max(0LL, u.s - max(mx + 1, u.f) + 1);
mx = max(mx, u.s);
}
cout << ans << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
4 ms |
1372 KB |
Output is correct |
3 |
Correct |
3 ms |
1372 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 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 |
0 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 |
124 ms |
432 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
342 ms |
63052 KB |
Output is correct |
3 |
Incorrect |
400 ms |
74576 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
342 ms |
63052 KB |
Output is correct |
3 |
Incorrect |
400 ms |
74576 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
342 ms |
63052 KB |
Output is correct |
3 |
Incorrect |
400 ms |
74576 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
39 ms |
9016 KB |
Output is correct |
3 |
Correct |
36 ms |
8576 KB |
Output is correct |
4 |
Correct |
396 ms |
74692 KB |
Output is correct |
5 |
Correct |
37 ms |
8272 KB |
Output is correct |
6 |
Correct |
35 ms |
8240 KB |
Output is correct |
7 |
Correct |
37 ms |
8396 KB |
Output is correct |
8 |
Correct |
35 ms |
8276 KB |
Output is correct |
9 |
Correct |
37 ms |
8272 KB |
Output is correct |
10 |
Correct |
32 ms |
8488 KB |
Output is correct |
11 |
Correct |
32 ms |
8276 KB |
Output is correct |
12 |
Correct |
32 ms |
8268 KB |
Output is correct |
13 |
Correct |
34 ms |
8368 KB |
Output is correct |
14 |
Correct |
410 ms |
74428 KB |
Output is correct |
15 |
Incorrect |
34 ms |
8364 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
4 ms |
1372 KB |
Output is correct |
3 |
Correct |
3 ms |
1372 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |