#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);
ll mod = (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);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
6 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 |
57 ms |
5820 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
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 |
382 ms |
41316 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
486 ms |
19024 KB |
Output is correct |
3 |
Correct |
484 ms |
53552 KB |
Output is correct |
4 |
Correct |
481 ms |
53400 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
486 ms |
19024 KB |
Output is correct |
3 |
Correct |
484 ms |
53552 KB |
Output is correct |
4 |
Correct |
481 ms |
53400 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
493 ms |
53500 KB |
Output is correct |
7 |
Correct |
512 ms |
53304 KB |
Output is correct |
8 |
Correct |
477 ms |
53308 KB |
Output is correct |
9 |
Correct |
560 ms |
53388 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
486 ms |
19024 KB |
Output is correct |
3 |
Correct |
484 ms |
53552 KB |
Output is correct |
4 |
Correct |
481 ms |
53400 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
48 ms |
5732 KB |
Output is correct |
7 |
Correct |
49 ms |
5732 KB |
Output is correct |
8 |
Correct |
55 ms |
5860 KB |
Output is correct |
9 |
Correct |
46 ms |
5732 KB |
Output is correct |
10 |
Correct |
55 ms |
5732 KB |
Output is correct |
11 |
Correct |
49 ms |
5732 KB |
Output is correct |
12 |
Correct |
57 ms |
5860 KB |
Output is correct |
13 |
Correct |
67 ms |
5732 KB |
Output is correct |
14 |
Correct |
48 ms |
5732 KB |
Output is correct |
15 |
Correct |
51 ms |
5736 KB |
Output is correct |
16 |
Correct |
69 ms |
5724 KB |
Output is correct |
17 |
Correct |
48 ms |
5772 KB |
Output is correct |
18 |
Correct |
489 ms |
53308 KB |
Output is correct |
19 |
Correct |
468 ms |
53340 KB |
Output is correct |
20 |
Correct |
515 ms |
53420 KB |
Output is correct |
21 |
Correct |
52 ms |
5756 KB |
Output is correct |
22 |
Correct |
45 ms |
5732 KB |
Output is correct |
23 |
Correct |
154 ms |
18524 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
51 ms |
5116 KB |
Output is correct |
3 |
Correct |
48 ms |
5732 KB |
Output is correct |
4 |
Correct |
567 ms |
53316 KB |
Output is correct |
5 |
Correct |
49 ms |
5764 KB |
Output is correct |
6 |
Correct |
61 ms |
5732 KB |
Output is correct |
7 |
Correct |
54 ms |
5732 KB |
Output is correct |
8 |
Correct |
50 ms |
5720 KB |
Output is correct |
9 |
Correct |
48 ms |
5860 KB |
Output is correct |
10 |
Correct |
53 ms |
5756 KB |
Output is correct |
11 |
Correct |
49 ms |
5808 KB |
Output is correct |
12 |
Correct |
43 ms |
5792 KB |
Output is correct |
13 |
Correct |
56 ms |
5732 KB |
Output is correct |
14 |
Correct |
534 ms |
53364 KB |
Output is correct |
15 |
Correct |
53 ms |
5732 KB |
Output is correct |
16 |
Correct |
471 ms |
53284 KB |
Output is correct |
17 |
Correct |
458 ms |
53320 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
6 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 |
57 ms |
5820 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |