Submission #137000

#TimeUsernameProblemLanguageResultExecution timeMemory
137000nikolapesic2802Strange Device (APIO19_strange_device)C++14
100 / 100
888 ms34964 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define ll long long
#define pb push_back
#define sz(x) (int)(x).size()
#define mp make_pair
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define D(x) cerr << #x << " is " << (x) << "\n";
#define ld long double

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; ///find_by_order(),order_of_key()
template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) { os << '{' << a.f << ", " << a.s << '}'; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& a){os << '{';for(int i=0;i<sz(a);i++){if(i>0&&i<sz(a))os << ", ";os << a[i];}os<<'}';return os;}
template<class T> ostream& operator<<(ostream& os, const set<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T> ostream& operator<<(ostream& os, const multiset<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T1,class T2> ostream& operator<<(ostream& os, const map<T1,T2>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}

int n;
ll a,b;
ll nzd(ll aa,ll bb)
{
    if(bb==0)
        return aa;
    return nzd(bb,aa%bb);
}
int main()
{
    scanf("%i %lld %lld",&n,&a,&b);
    ll z=a/nzd(a,b+1);
    ll first=LLONG_MAX;
    if(LLONG_MAX/z>b)
        first=z*b;
    vector<pair<ll,int> > events;
    for(int i=0;i<n;i++)
    {
        ll l,r;
        scanf("%lld %lld",&l,&r);
        if(r-l+1>=first)
        {
            printf("%lld\n",first);
            return 0;
        }
        l%=first;
        r%=first;
        events.pb({l,1});
        events.pb({r+1,-1});
        if(l>r)
            events.pb({first,-1}),events.pb({0,1});
    }
    int cnt=0;
    ll last=0,ans=0;
    sort(all(events));
    for(auto p:events)
    {
        if(cnt)
            ans+=p.f-last;
        cnt+=p.s;
        last=p.f;
    }
    printf("%lld\n",ans);
}

Compilation message (stderr)

strange_device.cpp: In function 'int main()':
strange_device.cpp:39:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%i %lld %lld",&n,&a,&b);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
strange_device.cpp:48:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld %lld",&l,&r);
         ~~~~~^~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...