이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define all(x) x.begin(), x.end()
#define int long long
#define pi pair<int, int >
#define pq priority_queue
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define eb emplace_back
#define mset multiset
#define F first
#define S second
using namespace std;
int n, A, B, range;
vector<pair<int, int>> v;
int fastpow(int a, int b, int n) {
if (!b) return 1;
if (b % 2 == 0) {int r = fastpow(a, b / 2, n); return (r * r) % n;}
else {int r = fastpow(a, b - 1, n); return (r * a) % n;}
}
int fastmul(int a, int b, int n) {
if (b == 0) return 0;
if (b % 2 == 0) {int r = fastmul(a, b / 2, n); return (r + r) % n;}
else {int r = fastmul(a, b - 1, n); return (r + a) % n;}
}
int gcd(int a, int b) {return (!a ? b : gcd(b % a, a));}
void build() {
int L = gcd(B+1, A);
range = fastmul(A / L, B, 1e18);
}
void calc(int l, int r) {
if (r - l > range) {v.pb({1, range}); return ;}
int s = l / range;
l %= range ;
r -= s * range;
if (r > range) r -= range;
v.pb({l, 1});
v.pb({r, 2});
}
int count() {
sort(all(v));
int ans = 0, se = 0, si = 0;
for (auto i: v) {
if (i.S & 1) {
if (i.F > 0 && i.F <= se) ans += i.F - si + 1;
}
else {
se = i.F;
ans += i.F - si + 1;
}
si = i.F;
}
return ans;
}
void solve ()
{
cin >> n >> A >> B;
build();
for (int i = 1; i <= n; i++) {
int l, r; cin >> l >> r;
calc(l, r);
}
cout << count();
}
signed main(){IOS solve(); return 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... |