#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
long long long_gcd(long long a, long long b)
{
// cout << "gcd " << a << ' ' << b << '\n';
if(a == b) return a;
if(a < b) swap(a, b);
if(b == 0) return a;
return long_gcd(a%b, b);
}
long long long_abs(long long x)
{
if(x >= 0) return x;
return -x;
}
long long long_sign(long long x)
{
if(x > 0) return 1;
return -1;
}
int main()
{
int n;
long long A, B;
cin >> n >> A >> B;
long long period = A * B / long_gcd(A, B+1);
// cout << period << '\n';
long long l, r;
vector<long long> endpoints;
for(int i = 1; i <= n; i++)
{
cin >> l >> r;
if(l % period <= r % period)
{
endpoints.push_back(l % period + 1);
endpoints.push_back(-(r % period) - 1 - 1);
}
else
{
endpoints.push_back(l % period + 1);
endpoints.push_back(-period - 1);
endpoints.push_back(0 + 1);
endpoints.push_back(-(r % period) - 1 - 1);
}
}
// for(long long e: endpoints) cout << e << ' ';
// cout << '\n';
sort(endpoints.begin(), endpoints.end(), [] (long long p, long long q)
{
return long_abs(p) < long_abs(q);
});
// for(long long e: endpoints) cout << e << ' ';
// cout << '\n';
long long res = 0;
long long count = 0;
count += long_sign(endpoints[0]);
for(int i = 1; i < endpoints.size(); i++)
{
// cout << count << ' ' << long_abs(endpoints[i]) - long_abs(endpoints[i-1]) << '\n';
if(count > 0) res += long_abs(endpoints[i]) - long_abs(endpoints[i-1]);
count += long_sign(endpoints[i]);
}
cout << res << '\n';
}
Compilation message
strange_device.cpp: In function 'int main()':
strange_device.cpp:79:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
79 | for(int i = 1; i < endpoints.size(); i++)
| ~~^~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
17 ms |
1004 KB |
Output is correct |
3 |
Correct |
17 ms |
1004 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
16 ms |
1004 KB |
Output is correct |
17 |
Correct |
180 ms |
5088 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
2 ms |
364 KB |
Output is correct |
3 |
Correct |
2 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
364 KB |
Output is correct |
5 |
Correct |
1107 ms |
17432 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1634 ms |
17900 KB |
Output is correct |
3 |
Correct |
1692 ms |
17812 KB |
Output is correct |
4 |
Correct |
1622 ms |
17804 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1634 ms |
17900 KB |
Output is correct |
3 |
Correct |
1692 ms |
17812 KB |
Output is correct |
4 |
Correct |
1622 ms |
17804 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1658 ms |
17864 KB |
Output is correct |
7 |
Correct |
1644 ms |
17888 KB |
Output is correct |
8 |
Correct |
1646 ms |
17864 KB |
Output is correct |
9 |
Correct |
1774 ms |
18048 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1634 ms |
17900 KB |
Output is correct |
3 |
Correct |
1692 ms |
17812 KB |
Output is correct |
4 |
Correct |
1622 ms |
17804 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
162 ms |
5088 KB |
Output is correct |
7 |
Correct |
166 ms |
5088 KB |
Output is correct |
8 |
Correct |
158 ms |
5088 KB |
Output is correct |
9 |
Correct |
164 ms |
5088 KB |
Output is correct |
10 |
Correct |
155 ms |
5088 KB |
Output is correct |
11 |
Correct |
164 ms |
5088 KB |
Output is correct |
12 |
Correct |
161 ms |
5088 KB |
Output is correct |
13 |
Correct |
173 ms |
5108 KB |
Output is correct |
14 |
Correct |
159 ms |
5088 KB |
Output is correct |
15 |
Correct |
175 ms |
5088 KB |
Output is correct |
16 |
Correct |
175 ms |
5088 KB |
Output is correct |
17 |
Correct |
166 ms |
5088 KB |
Output is correct |
18 |
Correct |
1652 ms |
17992 KB |
Output is correct |
19 |
Correct |
1624 ms |
18032 KB |
Output is correct |
20 |
Correct |
1808 ms |
17860 KB |
Output is correct |
21 |
Correct |
177 ms |
5216 KB |
Output is correct |
22 |
Correct |
154 ms |
5088 KB |
Output is correct |
23 |
Correct |
503 ms |
11108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
170 ms |
5092 KB |
Output is correct |
3 |
Correct |
172 ms |
5088 KB |
Output is correct |
4 |
Correct |
1816 ms |
18144 KB |
Output is correct |
5 |
Correct |
171 ms |
5088 KB |
Output is correct |
6 |
Correct |
174 ms |
5088 KB |
Output is correct |
7 |
Correct |
172 ms |
5088 KB |
Output is correct |
8 |
Correct |
176 ms |
5088 KB |
Output is correct |
9 |
Correct |
167 ms |
5088 KB |
Output is correct |
10 |
Correct |
177 ms |
5088 KB |
Output is correct |
11 |
Correct |
175 ms |
5088 KB |
Output is correct |
12 |
Correct |
161 ms |
5236 KB |
Output is correct |
13 |
Correct |
176 ms |
5088 KB |
Output is correct |
14 |
Correct |
1790 ms |
18328 KB |
Output is correct |
15 |
Correct |
181 ms |
5088 KB |
Output is correct |
16 |
Correct |
1602 ms |
18020 KB |
Output is correct |
17 |
Correct |
1632 ms |
18244 KB |
Output is correct |
18 |
Correct |
1 ms |
492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
17 ms |
1004 KB |
Output is correct |
3 |
Correct |
17 ms |
1004 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
16 ms |
1004 KB |
Output is correct |
17 |
Correct |
180 ms |
5088 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
0 ms |
364 KB |
Output is correct |
20 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |