제출 #484579

#제출 시각아이디문제언어결과실행 시간메모리
484579CyberSleeper이상한 기계 (APIO19_strange_device)C++14
100 / 100
508 ms53256 KiB
#include <bits/stdc++.h>
#define fastio      ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define debug(x)    cout << "Line " << __LINE__ << ", " << #x << " is " << x << endl
#define fi          first
#define se          second
#define mp          make_pair
#define pb          push_back
#define ll          long long
#define pll         pair<ll, ll>
#define ull         unsigned long long
#define ld          long double
#define pii         pair<ll, ll>
#define nl          '\n'
#define tb          '\t'
#define sp          ' '
using namespace std;

const ll MX=1000001, MOD=998244353, BLOCK=330, INF=1e9+7, INFF=2e18;
const ld ERR=1e-7, pi=3.14159265358979323846;

ll N, A, B, cyc, last=0, GCD;
vector<pll> L;

int main(){
    fastio;
    cin >> N >> A >> B;
    A/=__gcd(A, B+1ll);
    cyc=(INFF+A-1)/A;
    if(B>=cyc)
        cyc=INFF;
    else
        cyc=A*B;
    for(ll i=0, x, y; i<N; i++){
        cin >> x >> y;
        if(y-x+1>=cyc){
            L.pb({0, cyc-1});
        }else{
            x%=cyc;
            y%=cyc;
            if(x<=y)
                L.pb({x, y});
            else{
                L.pb({0, y});
                L.pb({x, cyc-1});
            }
        }
    }
    N=L.size();
    sort(L.begin(), L.end());
    ll ans=0;
    for(auto i:L){
        ll x=i.fi, y=i.se;
        if(y<last)
            continue;
        x=max(last, x);
        ans+=y-x+1;
        last=max(last, y+1);
    }
    cout << ans << nl;
}
#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...