이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
// author: aykhn
using namespace std;
typedef long long ll;
#define TC int t; cin >> t; while (t--) _();
#define OPT ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(v) v.begin(), v.end()
#define pii pair<int, int>
#define mpr make_pair
#define eb emplace_back
#define new int32_t
#define pb push_back
#define ts to_string
#define fi first
#define se second
#define int ll
#define ins insert
#define inf 0x3F3F3F3F
#define infll 0x3F3F3F3F3F3F3F3FLL
#define bpc __builtin_popcount
int n, a, b;
/*int x(int i)
{
return (i + i/b) % a;
}
int y(int i)
{
return i % b;
}*/
new main()
{
cin >> n >> a >> b;
int x = a/__gcd(a, b + 1) * b;
set<pii> s;
for (int i = 0; i < n; i++)
{
int a, b;
cin >> a >> b;
if (b - a + 1 >= x)
{
s.ins(mpr(0, x - 1));
}
else
{
int l = a % x;
int r = b % x;
if (l <= r)
{
s.ins(mpr(l, r));
}
else
{
s.ins(mpr(l, x - 1));
s.ins(mpr(0, r));
}
}
}
stack<pii> nw;
nw.push(*s.begin());
s.erase(s.begin());
while (!s.empty())
{
pii t = nw.top();
pii a = *s.begin();
if (t.se < a.fi) nw.push(a);
else
{
nw.pop();
nw.push(mpr(min(t.fi, a.fi), max(t.se, a.se)));
}
s.erase(s.begin());
}
int res = 0;
while (!nw.empty())
{
res += nw.top().se - nw.top().fi + 1;
nw.pop();
}
cout << res << endl;
return 0;
}
// 4, 5 -> 10;
// 3, 6 -> 18;
# | 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... |