# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
210207 | tatyam | Strange Device (APIO19_strange_device) | C++17 | 775 ms | 33756 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;
using ull = unsigned long long;
#define rep(n) for(int i=0;i<n;++i)
#define all(i) begin(i),end(i)
#define Sort(a) sort(all(a))
#define Rev(a) reverse(all(a))
using u128 = __uint128_t;
signed main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
ull n, a, b;
cin >> n >> a >> b;
u128 mod = a / gcd(a, b + 1) * u128(b);
vector<pair<ull, int>> query;
rep(n){
ull l, r;
cin >> l >> r;
if(r - l + 1 >= mod){
cout << ull(mod) << endl;
return 0;
}
l %= mod; r %= mod;
r++;
query.emplace_back(l, 1);
query.emplace_back(r, -1);
if(l > r){
query.emplace_back(mod, -1);
query.emplace_back(0, 1);
}
}
Sort(query);
Rev(query);
ull at = 0, cnt = 0, ans = 0;
while(query.size()){
ull next = query.back().first;
if(cnt) ans += next - at;
at = next;
while(query.size() && query.back().first == at){
cnt += query.back().second;
query.pop_back();
}
}
cout << ans << endl;
}
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... |