This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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, p.second % mod });
}
else {
points.push_back({ p.first % mod, mod - 1 });
points.push_back({ 0, p.second % mod });
}
}
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 / gcd(A, B + 1)) * B;
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};
pushTime(times[i], mod, points);
}
sort(points.begin(), points.end());
ll count = 0;
int open = 0;
ll last = points[0].second;
ll start = points[0].first;
for (int i = 1; i < points.size(); i++) {
if (points[i].first > last) {
ll amount = last - start + 1;
start = points[i].first;
count += amount;
}
last = max(last, points[i].second);
}
ll amount = last - start + 1;
count += amount;
cout << count;
return 0;
}
Compilation message (stderr)
strange_device.cpp: In function 'int main()':
strange_device.cpp:65: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]
65 | for (int i = 1; i < points.size(); i++) {
| ~~^~~~~~~~~~~~~~~
strange_device.cpp:62:6: warning: unused variable 'open' [-Wunused-variable]
62 | int open = 0;
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |