이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
void speed()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
const ll maxn = 1e6 + 10;
ll n;
ll l[maxn], r[maxn];
ll A, B;
struct poll
{
ll x, t;
poll(ll _x = 0, ll _t = 0)
{
x = _x;
t = _t;
}
bool operator < (const poll &p) const
{
if (x == p.x)
return t < p.t;
return x < p.x;
}
};
vector < poll > vec;
void add_segment(ll l, ll r)
{
vec.push_back(poll(l, 1));
vec.push_back(poll(r + 1, -1));
}
void solve()
{
cin >> n >> A >> B;
for (ll i = 1; i <= n; i ++)
{
cin >> l[i] >> r[i];
}
ll g = __gcd(A, B + 1);
/// period is A * B / g
if ((double)(1e18) / (double)(A) < (double)(B) / (double)(g))
{
ll ans = 0;
for (ll i = 1; i <= n; i ++)
{
ans = ans + (r[i] - l[i] + 1);
}
cout << ans << endl;
return;
}
long long period = A * B / g;
for (ll i = 1; i <= n; i ++)
{
if (r[i] - l[i] + 1 >= period)
{
cout << period << endl;
return;
}
ll x = l[i] % period, y = r[i] % period;
if (x <= y)
{
add_segment(x, y);
}
else
{
add_segment(0, y);
add_segment(x, period - 1);
}
}
sort(vec.begin(), vec.end());
ll ans = 0, cnt = 1;
for (ll i = 1; i < vec.size(); i ++)
{
///cout << i << " :: " << cnt << " " << vec[i].x << endl;
if (cnt > 0)
ans = ans + vec[i].x - vec[i - 1].x;
cnt += vec[i].t;
}
cout << ans << endl;
}
int main()
{
solve();
return 0;
}
/**
1 10000 3312452154131231
1 1
*/
컴파일 시 표준 에러 (stderr) 메시지
strange_device.cpp: In function 'void solve()':
strange_device.cpp:92:22: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<poll>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
92 | for (ll i = 1; i < vec.size(); i ++)
| ~~^~~~~~~~~~~~
# | 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... |