Submission #938934

# Submission time Handle Problem Language Result Execution time Memory
938934 2024-03-05T22:07:54 Z Andreibatman Strange Device (APIO19_strange_device) C++14
0 / 100
3 ms 604 KB
#include <bits/stdc++.h>
using namespace std;
unsigned long long n,a,b,ans,i,t,k,pozst,lg,schema,ok,st,dr;
struct ceva
{
    unsigned long long l,r;
}v[5000010];
bool cmp(ceva a,ceva b)
{
    return a.r<b.r || (a.r==b.r && a.l<b.l);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>a>>b;
    if(ULLONG_MAX/a<=b)
        k=1e18;
    else
        k=a*b;
    k=k-a;
    for(i=1;i<=n;i++)
    {
        cin>>v[i].l>>v[i].r;
        pozst=v[i].l%k;
        lg=v[i].r-v[i].l+1;
        if(lg>=k)
        {
            ok=1;
            v[i]={1,k};
            continue;
        }
        if(pozst==0)
        {
            v[n+(++schema)]={k,k};
            pozst=1;
            v[i].l=1;
            v[i].r=v[i].l+lg-2;
            lg--;
        }
        if(pozst+lg-1>k)
        {
            v[n+(++schema)]={pozst,k};
            v[i]={1,lg-2};
        }
        else
            v[i]={pozst,pozst+lg-1};
    }
    /*if(ok==1)
    {
        cout<<k;
        return 0;
    }*/
    n=n+schema;
    sort(v+1,v+n+1,cmp);
    //for(i=1;i<=n;i++)
    //    cout<<v[i].l<<" "<<v[i].r<<'\n';
    st=0;
    dr=0;
    for(i=1;i<=n;i++)
    {
        st=max(st,v[i].l);
        st=max(st,v[i-1].r+1);
        if(dr==v[i].r)
            continue;
        dr=v[i].r;
        st=max(st,v[i].l);
        st=max(st,v[i-1].r+1);
        ans=ans+dr-st+1;
    }
    cout<<ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 600 KB Execution killed with signal 8
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 604 KB Execution killed with signal 8
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 348 KB Execution killed with signal 8
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 604 KB Execution killed with signal 8
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 604 KB Execution killed with signal 8
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 604 KB Execution killed with signal 8
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 600 KB Execution killed with signal 8
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 600 KB Execution killed with signal 8
2 Halted 0 ms 0 KB -