#include <bits/stdc++.h>
using namespace std;
int n;
long long a, b, mod;
long long l, r, last=0, sum = 0;
vector<pair<long long, bool>> vec;
int ctr = 0;
int main() {
cin.tie(0) -> sync_with_stdio(0);
cin >> n >> a >> b;
if(a >= 2e18/b) mod = 2e18;
else mod = a*b;
while(n--) {
cin >> l >> r;
if(r-l+1 >= mod) {
cout << mod;
return 0;
}
l %= mod; r %= mod;
if(l <= r) vec.emplace_back(l, 0), vec.emplace_back(r+1, 1);
else vec.emplace_back(l, 0), vec.emplace_back(mod, 1), vec.emplace_back(0, 0), vec.emplace_back(r+1, 1);
}
sort(vec.begin(), vec.end());
for(auto e:vec) {
sum += min(ctr, 1) * (e.first-last);
if(e.second) ctr--;
else ctr++;
last = e.first;
}
cout << sum;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
4 ms |
1240 KB |
Output is correct |
3 |
Correct |
5 ms |
1240 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 |
320 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
320 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
376 KB |
Output is correct |
5 |
Correct |
256 ms |
56900 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
390 ms |
68856 KB |
Output is correct |
3 |
Incorrect |
363 ms |
68864 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
390 ms |
68856 KB |
Output is correct |
3 |
Incorrect |
363 ms |
68864 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
390 ms |
68856 KB |
Output is correct |
3 |
Incorrect |
363 ms |
68864 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
42 ms |
7288 KB |
Output is correct |
3 |
Correct |
44 ms |
7204 KB |
Output is correct |
4 |
Correct |
562 ms |
68784 KB |
Output is correct |
5 |
Correct |
41 ms |
7232 KB |
Output is correct |
6 |
Correct |
49 ms |
7200 KB |
Output is correct |
7 |
Correct |
51 ms |
7252 KB |
Output is correct |
8 |
Correct |
45 ms |
7260 KB |
Output is correct |
9 |
Correct |
40 ms |
7248 KB |
Output is correct |
10 |
Correct |
46 ms |
7244 KB |
Output is correct |
11 |
Correct |
44 ms |
7236 KB |
Output is correct |
12 |
Correct |
38 ms |
7216 KB |
Output is correct |
13 |
Correct |
44 ms |
7236 KB |
Output is correct |
14 |
Correct |
503 ms |
68924 KB |
Output is correct |
15 |
Incorrect |
50 ms |
7340 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
4 ms |
1240 KB |
Output is correct |
3 |
Correct |
5 ms |
1240 KB |
Output is correct |
4 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |