답안 #142675

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
142675 2019-08-10T12:20:32 Z Bodo171 이상한 기계 (APIO19_strange_device) C++14
5 / 100
1298 ms 62956 KB
#include <iostream>
#include <set>
#include <fstream>
using namespace std;
const long long lim=(long long)(1LL*1e18)+1;
long long n,i,j,l,r,A,B,L,R;
long long ans;
bool brk;
struct pct
{
    long long x,y;
}nl;
bool operator <(pct unu,pct doi)
{
    if(unu.x==doi.x) return unu.y<doi.y;
    return unu.x<doi.x;
}
bool operator !=(pct unu,pct doi)
{
    return (unu.x!=doi.x||unu.y!=doi.y);
}
set <pct> s;
set <pct>::iterator it,it1;
long long gcd(long long x,long long y)
{
    if((!x)||(!y)) return (x+y);
    return gcd(y,x%y);
}
void baga(long long st,long long dr)
{
    it=s.lower_bound({st,0});
    while(it!=s.end()&&(*it).x<=dr)
    {
        dr=max(dr,(*it).y);
        it1=it;it1++;s.erase(it);
        it=it1;
    }
    it=s.lower_bound({st,0});
    if(it!=s.begin())
    {
        it--;
        if((*it).y>=st)
        {
            st=min(st,(*it).y);
            s.erase(it);
        }
    }
    s.insert({st,dr});
}
int main()
{
    //freopen("data.in","r",stdin);
    ios_base::sync_with_stdio(false);
    cin>>n>>A>>B;
    long long t=gcd(A,B+1);
    A/=t;
    long long per;
    if(lim/A<=B) per=1LL*lim;
    else per=1LL*A*B;
    for(i=1;i<=n;i++)
    {
        cin>>l>>r;
        if(l/per==r/per)
        {
            baga(l%per,r%per);
        }
        else
        {
            if(l/per+1<r/per)
                baga(0,per-1);
            baga(l%per,per-1);
            baga(0,r%per);
        }
    }
    for(it=s.begin();it!=s.end();it++)
    {
        ans+=1LL*((*it).y-(*it).x+1);
    }
    cout<<ans;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 376 KB Output is correct
2 Incorrect 12 ms 1144 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 3 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 1298 ms 62956 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 1298 ms 62956 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 1298 ms 62956 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 124 ms 6696 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 376 KB Output is correct
2 Incorrect 12 ms 1144 KB Output isn't correct
3 Halted 0 ms 0 KB -