#include <bits/stdc++.h>
#define SZ(v) ((int)(v).size())
using namespace std;
using ll = long long;
template<typename... Args>
void read(Args&... args)
{
((cin >> args), ...);
}
template<typename T>
void read(vector<T> &vec)
{
for (auto &v : vec) read(v);
}
void write() {}
template<typename H, typename... T>
void write(const H &h, const T&... t)
{
cout << h;
if (sizeof...(t)) {cout << ' '; write(t...);}
}
template<typename T>
void write(const vector<T> &vec)
{
if (SZ(vec) == 0) return;
write(vec[0]);
for (int i(1); i < SZ(vec); ++i)
{cout << ' '; write(vec[i]);}
}
template<typename... Args>
void writeln(Args... args)
{
write(args...); cout << '\n';
}
int main(void)
{
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int n;
ll A, B;
read(n, A, B);
__int128 mod = (__int128(A) * B) / gcd(A, B+1);
vector<pair<ll, ll>> intervals;
for (int i(0); i < n; ++i)
{
ll l, r;
read(l, r);
l %= mod, r %= mod;
if (l > r)
{
intervals.emplace_back(l, mod-1);
intervals.emplace_back(0, r);
}
else
intervals.emplace_back(l, r);
}
sort(intervals.begin(), intervals.end());
ll lst(-1);
ll sol(0);
for (auto [l, r] : intervals)
{
sol += max(0LL, r - max(l, lst+1) + 1);
lst = max(lst, r);
}
writeln(sol);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
5 ms |
1132 KB |
Output is correct |
3 |
Correct |
7 ms |
1132 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
5 ms |
1132 KB |
Output is correct |
17 |
Correct |
66 ms |
4200 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
341 ms |
16976 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
461 ms |
19816 KB |
Output is correct |
3 |
Correct |
453 ms |
17044 KB |
Output is correct |
4 |
Correct |
455 ms |
16976 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
461 ms |
19816 KB |
Output is correct |
3 |
Correct |
453 ms |
17044 KB |
Output is correct |
4 |
Correct |
455 ms |
16976 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
457 ms |
16976 KB |
Output is correct |
7 |
Correct |
456 ms |
17008 KB |
Output is correct |
8 |
Correct |
472 ms |
16976 KB |
Output is correct |
9 |
Correct |
499 ms |
17260 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
461 ms |
19816 KB |
Output is correct |
3 |
Correct |
453 ms |
17044 KB |
Output is correct |
4 |
Correct |
455 ms |
16976 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
45 ms |
3564 KB |
Output is correct |
7 |
Correct |
54 ms |
3432 KB |
Output is correct |
8 |
Correct |
46 ms |
3304 KB |
Output is correct |
9 |
Correct |
47 ms |
3176 KB |
Output is correct |
10 |
Correct |
44 ms |
3176 KB |
Output is correct |
11 |
Correct |
46 ms |
3176 KB |
Output is correct |
12 |
Correct |
45 ms |
3232 KB |
Output is correct |
13 |
Correct |
49 ms |
3304 KB |
Output is correct |
14 |
Correct |
44 ms |
3048 KB |
Output is correct |
15 |
Correct |
49 ms |
3048 KB |
Output is correct |
16 |
Correct |
49 ms |
3048 KB |
Output is correct |
17 |
Correct |
46 ms |
2792 KB |
Output is correct |
18 |
Correct |
452 ms |
16992 KB |
Output is correct |
19 |
Correct |
447 ms |
16976 KB |
Output is correct |
20 |
Correct |
578 ms |
17000 KB |
Output is correct |
21 |
Correct |
49 ms |
2792 KB |
Output is correct |
22 |
Correct |
44 ms |
2792 KB |
Output is correct |
23 |
Correct |
141 ms |
8796 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
48 ms |
2536 KB |
Output is correct |
3 |
Correct |
49 ms |
2792 KB |
Output is correct |
4 |
Correct |
536 ms |
16976 KB |
Output is correct |
5 |
Correct |
49 ms |
2792 KB |
Output is correct |
6 |
Correct |
49 ms |
2792 KB |
Output is correct |
7 |
Correct |
48 ms |
2792 KB |
Output is correct |
8 |
Correct |
50 ms |
2792 KB |
Output is correct |
9 |
Correct |
52 ms |
2792 KB |
Output is correct |
10 |
Correct |
50 ms |
2792 KB |
Output is correct |
11 |
Correct |
48 ms |
2792 KB |
Output is correct |
12 |
Correct |
47 ms |
2920 KB |
Output is correct |
13 |
Correct |
48 ms |
2792 KB |
Output is correct |
14 |
Correct |
494 ms |
16976 KB |
Output is correct |
15 |
Correct |
47 ms |
2792 KB |
Output is correct |
16 |
Correct |
453 ms |
16992 KB |
Output is correct |
17 |
Correct |
451 ms |
16976 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
5 ms |
1132 KB |
Output is correct |
3 |
Correct |
7 ms |
1132 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
5 ms |
1132 KB |
Output is correct |
17 |
Correct |
66 ms |
4200 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
492 KB |
Output is correct |
20 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |