#include <bits/stdc++.h>
#define fastInput ios::sync_with_stdio(false); cin.tie(nullptr);
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pii;
typedef vector<pii> vp;
typedef vector<bool> vb;
typedef vector<vb> vvb;
ll A, B;
inline pii getTime(ll t) {
ll x = (t + (t / B)) % A;
ll y = t % B;
return { x,y };
}
inline void pushTime(pii p, ll mod, vp &points) {
if (p.first % mod <= p.second % mod) {
points.push_back({ p.first % mod, 1 });
points.push_back({ p.second % mod, -1 });
}
else {
points.push_back({ p.first % mod, 1 });
points.push_back({ mod, -1 });
points.push_back({ 0, 1 });
points.push_back({ p.second % mod, -1 });
}
}
ll gcd(ll a, ll b) {
if (b == 0) {
return a;
}
else {
return gcd(b, a % b);
}
}
int main() {
fastInput;
int n;
cin >> n >> A >> B;
ll mod = A * B / gcd(A, B + 1);
if (mod < 0)mod = 1e18 + 7;
vp times(n);
vp points;
ll l, r;
for (int i = 0; i < n; i++) {
cin >> l >> r;
times[i] = { l,r + 1 };
pushTime(times[i], mod, points);
}
sort(points.begin(), points.end());
ll count = 0;
int open = 0;
int last = -1;
for (int i = 0; i < points.size(); i++) {
open += points[i].second;
if (open == 0) {
if (last != -1) {
ll amount = points[i].first - last;
count += amount;
last = -1;
}
}
else {
if (last == -1) {
last = points[i].first;
}
}
}
cout << count;
return 0;
}
Compilation message
strange_device.cpp: In function 'int main()':
strange_device.cpp:67:20: 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]
67 | for (int i = 0; i < points.size(); i++) {
| ~~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |