#include <iostream>
#include <vector>
#include <algorithm>
#include <array>
#define ll long long
using namespace std;
ll n, a, b, x, y, l, r, f;
vector<array<ll, 2>> A;
int main() {
cin >> n >> a >> b;
for (int i=0; i<n; ++i) {
cin >> x >> y;
l = y-x;
x %= (a*b);
if (x+l >= a*b) {
l -= a*b-x;
l = min(l, a*b-1);
A.push_back({x, a*b-1});
A.push_back({0, l});
}
else A.push_back({x, x+l});
}
sort(A.begin(), A.end());
l = r = -1e9;
++l;
for (auto [u, v] : A) {
if (r+1 < u) {
//cout << l << " " << r << endl;
f += r-l+1;
l = u, r = v;
}
else r = max(r, v);
}
//cout << l << " " << r << endl;
f += (r-l)+1;
cout << f << '\n';
}
Compilation message
strange_device.cpp: In function 'int main()':
strange_device.cpp:28:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
28 | for (auto [u, v] : A) {
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
13 ms |
980 KB |
Output is correct |
3 |
Correct |
14 ms |
980 KB |
Output is correct |
4 |
Incorrect |
1 ms |
296 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
300 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
300 KB |
Output is correct |
5 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
304 KB |
Output is correct |
4 |
Correct |
2 ms |
344 KB |
Output is correct |
5 |
Correct |
1077 ms |
41456 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1408 ms |
53216 KB |
Output is correct |
3 |
Incorrect |
1392 ms |
53160 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1408 ms |
53216 KB |
Output is correct |
3 |
Incorrect |
1392 ms |
53160 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1408 ms |
53216 KB |
Output is correct |
3 |
Incorrect |
1392 ms |
53160 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
304 KB |
Output is correct |
2 |
Correct |
163 ms |
5580 KB |
Output is correct |
3 |
Correct |
143 ms |
5688 KB |
Output is correct |
4 |
Correct |
1446 ms |
53316 KB |
Output is correct |
5 |
Correct |
162 ms |
5600 KB |
Output is correct |
6 |
Correct |
153 ms |
5700 KB |
Output is correct |
7 |
Correct |
139 ms |
5664 KB |
Output is correct |
8 |
Correct |
138 ms |
5644 KB |
Output is correct |
9 |
Correct |
146 ms |
5576 KB |
Output is correct |
10 |
Correct |
143 ms |
5684 KB |
Output is correct |
11 |
Correct |
137 ms |
5604 KB |
Output is correct |
12 |
Correct |
133 ms |
5584 KB |
Output is correct |
13 |
Correct |
139 ms |
5748 KB |
Output is correct |
14 |
Correct |
1428 ms |
53332 KB |
Output is correct |
15 |
Incorrect |
142 ms |
5700 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
13 ms |
980 KB |
Output is correct |
3 |
Correct |
14 ms |
980 KB |
Output is correct |
4 |
Incorrect |
1 ms |
296 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |