#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
using ll = long long;
using ld = long double;
ll const inf = 1000000000000000000;
ll period(ll a, ll b){
ll p = __gcd(a, b + 1);
if(b / p <= inf / a)
return b / p * a;
return inf + 1;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
ll a, b;
cin >> n >> a >> b;
ll pi = period(a, b);
if(inf < pi){
ll result = 0;
for(int i = 1;i <= n; i++){
ll x, y;
cin >> x >> y;
result += y - x + 1;
}
cout << result;
} else {
vector<pair<ll,int>> event;
for(int i = 1;i <= n; i++){
ll x, y;
cin >> x >> y;
if(y - x < pi){
if(x % pi <= y % pi){
event.push_back({x % pi, 1});
event.push_back({y % pi + 1, -1});
} else {
event.push_back({x % pi, 1});
event.push_back({pi, -1});
event.push_back({0, 1});
event.push_back({y % pi + 1, -1});
}
} else {
cout << pi;
return 0;
}
}
sort(event.begin(), event.end());
ll result = 0, last = 0, sum = 0;
for(int i = 0; i < event.size(); i++){
if(0 < sum)
result += event[i].first - last;
last = event[i].first;
sum += event[i].second;
}
cout << result;
}
return 0;
}
Compilation message
strange_device.cpp: In function 'int main()':
strange_device.cpp:62:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < event.size(); i++){
~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
12 ms |
1400 KB |
Output is correct |
3 |
Correct |
15 ms |
1400 KB |
Output is correct |
4 |
Incorrect |
5 ms |
376 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
504 KB |
Output is correct |
3 |
Correct |
6 ms |
632 KB |
Output is correct |
4 |
Correct |
5 ms |
504 KB |
Output is correct |
5 |
Correct |
465 ms |
35356 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
675 ms |
47168 KB |
Output is correct |
3 |
Incorrect |
5 ms |
376 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
675 ms |
47168 KB |
Output is correct |
3 |
Incorrect |
5 ms |
376 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
675 ms |
47168 KB |
Output is correct |
3 |
Incorrect |
5 ms |
376 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
376 KB |
Output is correct |
2 |
Correct |
90 ms |
7392 KB |
Output is correct |
3 |
Correct |
82 ms |
7272 KB |
Output is correct |
4 |
Correct |
840 ms |
37056 KB |
Output is correct |
5 |
Correct |
79 ms |
7392 KB |
Output is correct |
6 |
Correct |
78 ms |
7276 KB |
Output is correct |
7 |
Correct |
76 ms |
7272 KB |
Output is correct |
8 |
Correct |
80 ms |
7276 KB |
Output is correct |
9 |
Correct |
84 ms |
7420 KB |
Output is correct |
10 |
Correct |
80 ms |
7392 KB |
Output is correct |
11 |
Correct |
80 ms |
7276 KB |
Output is correct |
12 |
Correct |
68 ms |
7272 KB |
Output is correct |
13 |
Correct |
82 ms |
7272 KB |
Output is correct |
14 |
Correct |
795 ms |
37020 KB |
Output is correct |
15 |
Incorrect |
81 ms |
7272 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
12 ms |
1400 KB |
Output is correct |
3 |
Correct |
15 ms |
1400 KB |
Output is correct |
4 |
Incorrect |
5 ms |
376 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |