이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <deque>
#include <map>
#include <set>
#include <complex>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <chrono>
#include <ctime>
#define ft first
#define sc second
#define pb push_back
#define len(v) (int)v.size()
#define int ll
using namespace std;
typedef long long ll;
typedef long double ld;
mt19937 rnd(chrono::steady_clock().now().time_since_epoch().count());
int gcd(int a, int b) {
if(a == 0 || b == 0)
return a + b;
return gcd(b, a % b);
}
signed main() {
#ifdef PC
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, a, b, ans = 0;
cin >> n >> a >> b;
int k = ((b + 1) * a / gcd(b + 1, a)) / (b + 1) * b;
// cout << k << endl;
// for (int t = 0; t <= 10; t++) {
// cout << "T " << t << " " << (t + (t / b)) % a << " " << t % b << endl;
// }
vector<pair<int, int>> have;
for (int i = 0; i < n; i++) {
int l, r;
cin >> l >> r;
if(r - l >= k) {
have.pb({0, k - 1});
continue;
}
int p1 = l % k, p2 = r % k;
if(p2 >= p1) {
have.pb({p1, p2});
}
else {
have.pb({p1, k - 1});
have.pb({0, p2});
}
}
sort(have.begin(), have.end());
int l = have[0].ft, r = have[0].sc;
for (int i = 1; i < len(have); i++) {
if(have[i].ft <= r) {
r = max(r, have[i].sc);
continue;
}
else {
ans += (r - l + 1);
l = have[i].ft, r = have[i].sc;
}
}
ans += (r - l + 1);
cout << ans << '\n';
}
# | 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... |