Submission #543518

# Submission time Handle Problem Language Result Execution time Memory
543518 2022-03-30T20:00:52 Z OttoTheDino Strange Device (APIO19_strange_device) C++17
0 / 100
36 ms 280 KB
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long n, a, b, ans=0;
    cin>>n>>a>>b;
    if (log(a)+log(b)>log(__gcd(a,b+1))+log(2e18)){
        for (int i =0; i<n; ++i){
            long long li,ri;cin>>li>>ri;
            ans += ri-li+1;
        }
        cout<<ans<<endl;
        return 0;
    }
    long long s = a/__gcd(a,b+1)*b;
    set<pair<long long, long long>> st;
    for (int i = 0; i<n;++i){
        int li, ri; cin >> li >> ri;
        if (ri-li>=s) st.insert({0,s-1});
        else if (ri%s<li%s){
            st.insert({0,ri%s});
            st.insert({li%s,s-1});
        }
        else st.insert({li%s,ri%s});
    }
    ans =s;
    long long x = -1;
    for (auto el : st) {
        ans -= max (el.first-x-1, 0LL);
        x = max (x, el.second);
    }
    ans -= s-1-x;
    cout << ans << endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 36 ms 280 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 36 ms 280 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 36 ms 280 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 4 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -