Submission #729959

# Submission time Handle Problem Language Result Execution time Memory
729959 2023-04-24T23:44:14 Z MtSaka Strange Device (APIO19_strange_device) C++17
0 / 100
1 ms 320 KB
#include<bits/stdc++.h>
#define overload(a,b,c,d,...) d
#define rep1(a) for(ll _=0;_<(ll)a;++_)
#define rep2(i,a) for(ll i=0;i<(ll)a;++i)
#define rep3(i,a,b) for(ll i=a;i<(ll)b;++i)
#define rep(...) overload(__VA_ARGS__,rep3,rep2,rep1)(__VA_ARGS__)
#define rrep1(i,a) for(ll i=(ll)a-1;i>=0;--i)
#define rrep2(i,a,b) for(ll i=(ll)b-1;i>=(ll)a;--i)
#define rrep(...) overload(__VA_ARGS__,rrep2,rrep1)(__VA_ARGS__)
#define all(a) a.begin(),a.end()
#define lb(v,x) lower_bound(all(v),x);
#define ub(v,x) upper_bound(all(v),x);
using namespace std;
using ll=long long;
using ull=unsigned long long;
using ld=long double;
template<typename T,typename U>
inline bool chmin(T&a,const U&b){return (a>b?a=b,true:false);}
template<typename T,typename U>
inline bool chmax(T&a,const U&b){return (a<b?a=b,true:false);}
struct segmnet_set{
    private:
    set<pair<ll,ll>>st;
    public:
    segmnet_set(){}
    void add(ll l,ll r){
        if(st.empty()){
            st.insert({l,r});
            return;
        }
        auto it=st.lower_bound({l,-1});
        if(it!=st.begin()){
            if(prev(it)->second>=l){
                l=prev(it)->first;
                chmax(r,prev(it)->second);
                st.erase(prev(it));
            }
        }
        while(it!=st.end()&&it->first<=r){
            chmax(r,it->second);
            it++;
            st.erase(prev(it));
        }
        st.insert({l,r});
    }
    ll calc()const{
        ll ans=0;
        for(const auto&[l,r]:st)ans+=r-l;
        return ans;
    }
};
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;cin>>n;
    ll a,b;cin>>a>>b;
    ll g=gcd(a,b+1);
    if((100000000000000000+b-1)/b<a/g){
        ll ans=0;
        rep(i,n){
            ll l,r;cin>>l>>r;ans+=r-l+1;
        }
        cout<<ans<<endl;return 0;
    }
    segmnet_set st;
    ll md=a/g*b;
    rep(i,n){
        ll l,r;cin>>l>>r;
        r++;
        l%=md,r%=md;
        if(l>r){
            st.add(l,md),st.add(0,r);
        }
        else{
            st.add(l,r);
        }
    }
    cout<<st.calc()<<endl;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 320 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 320 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 320 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -