# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
122791 | abacaba | Strange Device (APIO19_strange_device) | C++14 | 892 ms | 39916 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 15;
int n;
long long t, a, b, l, r, ans;
vector <pair <long long, int> > temp;
stack <long long> st;
int main() {
scanf("%d%lld%lld", &n, &a, &b);
if((b + 1) % a == 0)
t = b;
else {
t = a / __gcd(a, b + 1);
t *= b;
}
while(n--) {
scanf("%lld%lld", &l, &r);
if(r - l + 1 >= t)
return cout << t, 0;
l %= t, r %= t;
if(l > r) {
temp.push_back({l, -1});
temp.push_back({t, 1});
temp.push_back({0, -1});
temp.push_back({r + 1, 1});
}
else {
temp.push_back({l, -1});
temp.push_back({r + 1, 1});
}
}
sort(temp.begin(), temp.end());
for(auto i : temp) {
if(i.second == 1) {
if(st.size() == 1)
ans += i.first - st.top();
st.pop();
}
else
st.push(i.first);
}
printf("%lld", ans);
return 0;
}
Compilation message (stderr)
# | 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... |