이 제출은 이전 버전의 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 int maxn = 1e6 + 10;
int n;
ll l[maxn], r[maxn];
ll A, B;
struct point
{
ll x, t;
point(ll _x = 0, ll _t = 0)
{
x = _x;
t = _t;
}
bool operator < (const point &p) const
{
if (x == p.x)
return t > p.t;
return x < p.x;
}
};
vector < point > vec;
void add_segment(int l, int r)
{
vec.push_back(point(l, 1));
vec.push_back(point(r, -1));
}
void solve()
{
cin >> n >> A >> B;
for (int i = 1; i <= n; i ++)
{
cin >> l[i] >> r[i];
}
ll period = 1e18 + 10;
ll g = __gcd(A, B + 1);
if ((double)(A) * (double)(B) / (double)(g) < (double)period)
period = A * B / g;
for (int 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);
}
}
sort(vec.begin(), vec.end());
ll ans = 0, cnt = 0;
ll st = -1;
for (int i = 0; i < vec.size(); i ++)
{
///cout << vec[i].x << " " << vec[i].t << endl;
if (vec[i].t == 1)
{
if (cnt)
cnt ++;
else
{
st = vec[i].x;
cnt = 1;
}
}
else
{
if (cnt > 1)
cnt --;
else
{
ans = ans + vec[i].x - st + 1;
cnt = 0;
}
}
}
cout << ans << endl;
}
int main()
{
solve();
return 0;
}
/**
1 10000 3312452154131231
1 1
*/
컴파일 시 표준 에러 (stderr) 메시지
strange_device.cpp: In function 'void solve()':
strange_device.cpp:84:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<point>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
84 | for (int i = 0; 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... |