#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;
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, 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)
| ~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
10 ms |
660 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
2 ms |
212 KB |
Output is correct |
5 |
Correct |
689 ms |
17168 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
972 ms |
16820 KB |
Output is correct |
3 |
Correct |
960 ms |
16760 KB |
Output is correct |
4 |
Correct |
972 ms |
17056 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
972 ms |
16820 KB |
Output is correct |
3 |
Correct |
960 ms |
16760 KB |
Output is correct |
4 |
Correct |
972 ms |
17056 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
973 ms |
16948 KB |
Output is correct |
7 |
Correct |
1029 ms |
17168 KB |
Output is correct |
8 |
Incorrect |
1033 ms |
16988 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
972 ms |
16820 KB |
Output is correct |
3 |
Correct |
960 ms |
16760 KB |
Output is correct |
4 |
Correct |
972 ms |
17056 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Incorrect |
98 ms |
2624 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
98 ms |
2476 KB |
Output is correct |
3 |
Incorrect |
97 ms |
2400 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
10 ms |
660 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |