# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
781773 | devariaota | 이상한 기계 (APIO19_strange_device) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
const ll MAX = 1e18;
vector<pll> vec;
// {Left, Right}
ll n, a, b, length, ans = 0, cnt = 0;
set<pll> st;
void solve() {
while(n--)
{
for (ll i = l; i <= r; ++i)
{
pll hasil = {(i + (i/b)) % a, i % b};
st.insert(hasil);
}
}
cout << st.size() << "\n";
}
void opr(ll l, ll r) {
ll pushl = min(l, r);
ll pushr = max(l, r);
if (pushl == 0) {
// pushl = length;
}
if (pushr == 0) {
// pushr = length;
}
vec.push_back({pushl, pushr});
}
void answer() {
sort(vec.begin(), vec.end());
ll idx = -1;
for (int i = 0; i < vec.size(); ++i)
{
// cout << vec[i].first << " " << vec[i].second << "\n";
pll now = vec[i];
if (now.second < now.first)
{
continue ;
}
if (idx >= now.first)
{
if (now.second <= idx)
{
continue ;
} else {
idx++;
ans += now.second - idx + 1;
idx = now.second;
}
} else {
idx = now.first;
ans += now.second - idx + 1;
idx = now.second;
}
}
cout << ans << "\n";
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> n >> a >> b;
unsigned long long lebek;
if (a == 1) {
lebek = b;
} else {
if (a % 2)
{
lebek = a * b;
} else {
lebek = (a/2) * b;
}
}
length = lebek;
length = min(length, MAX);
for (int i = 0; i < n; ++i)
{
ll nowl, nowr;
cin >> nowl >> nowr;
cnt += nowr-nowl+1;
if (nowr-nowl+1 >= length)
{
cout << length << "\n";
return 0;
}
if (nowl/length != nowr/length) {
opr(nowl % length + 1, length);
opr(1, nowr % length + 1);
} else {
opr(nowl % length + 1, nowr % length + 1);
}
}
if (cnt <= 1e6)
{
solve();
return 0;
}
answer();
return 0;
}