#include<bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define f(i, n) for (int i = 0; i < (n); i++)
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define ll long long
#define ld long double
#define int long long
#define pii pair<int, int>
int ob(vector<pii> a) {
vector<pii> v;
for (auto s : a) {
v.eb(s.x, 0);
v.eb(s.y + 1, 1);
}
sort(all(v));
int res = 0, cnt = 0;
f(i, sz(v) - 1) {
if (v[i].y == 0) cnt++; else cnt--;
if (cnt) res += v[i + 1].x - v[i].x;
}
return res;
}
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, a, b;
cin >> n >> a >> b;
int p = a / __gcd(a, b + 1);
vector<int> l(n), r(n);
f(i, n) cin >> l[i] >> r[i];
int ans = 0;
f(z, b) {
vector<pii> v;
for (int i = 0; i < n; i++) {
if (r[i] < z) continue;
int ql = max(0LL, (l[i] - z + b - 1) / b), qr = (r[i] - z) / b;
if (ql <= qr) {
ql %= p;
qr %= p;
if (ql <= qr) {
v.eb(ql, qr);
} else {
v.eb(0, qr);
v.eb(ql, p - 1);
}
}
}
ans += ob(v);
}
cout << ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
893 ms |
1016 KB |
Output is correct |
3 |
Correct |
2684 ms |
920 KB |
Output is correct |
4 |
Correct |
6 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
6 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
7 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
4 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
17 ms |
384 KB |
Output is correct |
16 |
Correct |
92 ms |
1016 KB |
Output is correct |
17 |
Execution timed out |
5059 ms |
3072 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Execution timed out |
5065 ms |
384 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
16 ms |
512 KB |
Output is correct |
3 |
Correct |
417 ms |
400 KB |
Output is correct |
4 |
Correct |
107 ms |
504 KB |
Output is correct |
5 |
Execution timed out |
5050 ms |
119036 KB |
Time limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
698 ms |
80324 KB |
Output is correct |
3 |
Correct |
729 ms |
86668 KB |
Output is correct |
4 |
Correct |
706 ms |
86980 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
698 ms |
80324 KB |
Output is correct |
3 |
Correct |
729 ms |
86668 KB |
Output is correct |
4 |
Correct |
706 ms |
86980 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
989 ms |
118496 KB |
Output is correct |
7 |
Correct |
766 ms |
60884 KB |
Output is correct |
8 |
Correct |
1234 ms |
118432 KB |
Output is correct |
9 |
Correct |
1593 ms |
118488 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
698 ms |
80324 KB |
Output is correct |
3 |
Correct |
729 ms |
86668 KB |
Output is correct |
4 |
Correct |
706 ms |
86980 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
297 ms |
16288 KB |
Output is correct |
7 |
Correct |
216 ms |
16312 KB |
Output is correct |
8 |
Correct |
193 ms |
16316 KB |
Output is correct |
9 |
Correct |
199 ms |
16296 KB |
Output is correct |
10 |
Correct |
1615 ms |
15080 KB |
Output is correct |
11 |
Correct |
2489 ms |
16484 KB |
Output is correct |
12 |
Correct |
2212 ms |
16536 KB |
Output is correct |
13 |
Correct |
2965 ms |
16668 KB |
Output is correct |
14 |
Execution timed out |
5044 ms |
5624 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Execution timed out |
5054 ms |
3320 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
893 ms |
1016 KB |
Output is correct |
3 |
Correct |
2684 ms |
920 KB |
Output is correct |
4 |
Correct |
6 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
6 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
7 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
4 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
17 ms |
384 KB |
Output is correct |
16 |
Correct |
92 ms |
1016 KB |
Output is correct |
17 |
Execution timed out |
5059 ms |
3072 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |