#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
vector<pll> vec;
// {Left, Right}
ll n, a, b, length, ans = 0;
void opr(ll l, ll r) {
ll pushl = min(l, r);
ll pushr = max(l, r);
if (pushl == 0) {
// pushl = length;
}
if (pushr == 0) {
// pushr = length;
}
vec.push_back({pushl, pushr});
}
void answer() {
sort(vec.begin(), vec.end());
ll idx = -1;
for (int i = 0; i < vec.size(); ++i)
{
// cout << vec[i].first << " " << vec[i].second << "\n";
pll now = vec[i];
if (now.second < now.first)
{
continue ;
}
if (idx >= now.first)
{
if (now.second <= idx)
{
continue ;
} else {
idx++;
ans += now.second - idx + 1;
idx = now.second;
}
} else {
idx = now.first;
ans += now.second - idx + 1;
idx = now.second;
}
}
cout << ans << "\n";
}
int main(){
cin >> n >> a >> b;
unsigned long long lebek;
if (a == 1) {
lebek = b;
} else {
if (a % 2)
{
lebek = a * b;
} else {
lebek = (a/2) * b;
}
}
length = lebek;
for (int i = 0; i < n; ++i)
{
ll nowl, nowr;
cin >> nowl >> nowr;
if (nowr-nowl+1 >= length)
{
cout << length << "\n";
return 0;
}
if (nowl/length != nowr/length) {
opr(nowl % length + 1, length);
opr(1, nowr % length + 1);
} else {
opr(nowl % length + 1, nowr % length + 1);
}
}
answer();
return 0;
}
Compilation message
strange_device.cpp: In function 'void answer()':
strange_device.cpp:29:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
29 | for (int i = 0; i < vec.size(); ++i)
| ~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
10 ms |
596 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 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 |
212 KB |
Output is correct |
5 |
Correct |
673 ms |
16840 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
959 ms |
16912 KB |
Output is correct |
3 |
Correct |
965 ms |
16844 KB |
Output is correct |
4 |
Correct |
945 ms |
16952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
959 ms |
16912 KB |
Output is correct |
3 |
Correct |
965 ms |
16844 KB |
Output is correct |
4 |
Correct |
945 ms |
16952 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
963 ms |
16800 KB |
Output is correct |
7 |
Correct |
967 ms |
16804 KB |
Output is correct |
8 |
Incorrect |
970 ms |
16784 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
959 ms |
16912 KB |
Output is correct |
3 |
Correct |
965 ms |
16844 KB |
Output is correct |
4 |
Correct |
945 ms |
16952 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Incorrect |
93 ms |
2440 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
101 ms |
2484 KB |
Output is correct |
3 |
Incorrect |
96 ms |
2412 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
10 ms |
596 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |