#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 = l;
ll pushr = 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 (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;
if (a == 1) {
length = b;
} else {
if (a % 2)
{
length = a * b;
} else {
length = (a/2) * b;
}
}
if (length <= 0 || length > LLONG_MAX)
{
length = 1e18;
}
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, length-1);
opr(0, nowr % length);
} else {
opr(nowl % length, nowr % length);
}
}
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 |
668 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 |
1 ms |
212 KB |
Output is correct |
4 |
Incorrect |
1 ms |
224 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
2 ms |
212 KB |
Output is correct |
5 |
Correct |
740 ms |
16992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1004 ms |
16872 KB |
Output is correct |
3 |
Correct |
1056 ms |
16820 KB |
Output is correct |
4 |
Correct |
1081 ms |
16988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1004 ms |
16872 KB |
Output is correct |
3 |
Correct |
1056 ms |
16820 KB |
Output is correct |
4 |
Correct |
1081 ms |
16988 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1066 ms |
16876 KB |
Output is correct |
7 |
Correct |
1096 ms |
16968 KB |
Output is correct |
8 |
Incorrect |
1037 ms |
16932 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1004 ms |
16872 KB |
Output is correct |
3 |
Correct |
1056 ms |
16820 KB |
Output is correct |
4 |
Correct |
1081 ms |
16988 KB |
Output is correct |
5 |
Correct |
1 ms |
300 KB |
Output is correct |
6 |
Incorrect |
119 ms |
2888 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 |
100 ms |
2420 KB |
Output is correct |
3 |
Incorrect |
105 ms |
2700 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 |
668 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |