Submission #561309

#TimeUsernameProblemLanguageResultExecution timeMemory
561309baokhue232005이상한 기계 (APIO19_strange_device)C++14
100 / 100
474 ms20672 KiB
/*
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
*/
// lethal option

#include<bits/stdc++.h>
using namespace std;

#define all(flg) flg.begin(), flg.end()
#define int long long
#define pb push_back
#define fi first
#define se second
#define endl "\n"
#define eb emplace_back
#define ii pair<int, int>
#define PI 3.141592653589793238462643383279502884
#define ll long long
#define for1(i, ff, gg) for(int i = ff; i <= gg; ++i)
#define for2(i, ff, gg) for(int i = ff; i >= gg; --i)
const ll mod = 1e9 + 7;
const int maxN = 1000005;
const ll oo = 2e18 + 7;
int n, a[maxN];
int x, y, z, k;
ii pr[maxN];

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> n >> x >> y;
    x = (x / __gcd(x, y + 1));
    z = y * x;
    if(x < y) swap(x, y);
    if(oo / x <= y) z = oo;
    assert(z >= 0);
    set<ii> st;
    for1(i, 1, n){
        cin >> x >> y;
        if(y - x + 1 >= z){
            cout << z << endl;
            exit(0);
        }
        pr[i].fi = x % z;
        pr[i].se = y % z;
    }
    for1(i, 1, n){
        if(pr[i].fi > pr[i].se){
            ++n;
            pr[n].se = pr[i].se;
            pr[n].fi = 0;
            pr[i].se = z - 1;
        }
    }
    int lmx = -oo;
    sort(pr + 1, pr + n + 1);
    int ans = 0;
    for1(i, 1, n){
        lmx = max(lmx, pr[i].fi - 1);
        ans += max(0ll, pr[i].se - lmx);
        lmx = max(lmx, pr[i].se);
    }
    cout << ans << endl;
}
#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...