이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define f1 first
#define s2 second
#define fastio ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define debug(x...) cerr << "[" << #x << "]: " << x << "\n";
using ll = long long;
using ld = long double;
using ii = pair<int, int>;
using pl = pair<ll, ll>;
ld const PI = 4*atan((ld)1);
int main()
{
fastio;
ll n, a, b;
cin >> n >> a >> b;
vector<pl> v(n);
for (pl &x : v)
cin >> x.f1 >> x.s2;
ll gcd = __gcd(a, b+1);
if (v.back().s2 / b < a / gcd)
{
ll res = 0;
for (pl x : v)
res += (x.s2 - x.f1 + 1);
cout << res << '\n';
return 0;
}
ll mod = (a/gcd) * b;
vector<pl> range; //first: duration, second: state
for (pl x : v)
{
if (x.s2 - x.f1 + 1 >= mod)
{
cout << mod << '\n';
return 0;
}
ll l = x.f1 % mod;
ll r = x.s2 % mod;
if (l <= r)
{
range.pb({l, 1});
range.pb({r+1, -1});
}
else
{
range.pb({l, 1});
range.pb({mod, -1});
range.pb({0, 1});
range.pb({r+1, -1});
}
}
sort(range.begin(), range.end());
//for (auto x : range)
//{
// cout << "-> " << x.f1 << " " << x.s2 << '\n';
//}
ll ctr = 0;
ll res = 0;
for (int i = 0; i+1 < range.size(); ++i)
{
ctr += range[i].s2;
if (ctr > 0) res += (range[i+1].f1 - range[i].f1);
}
cout << res << '\n';
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
strange_device.cpp: In function 'int main()':
strange_device.cpp:75:22: 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]
75 | for (int i = 0; i+1 < range.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... |