답안 #957430

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
957430 2024-04-03T17:01:00 Z steveonalex 이상한 기계 (APIO19_strange_device) C++17
0 / 100
1 ms 348 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define MASK(i) (1LL << (i))
#define GETBIT(mask, i) (((mask) >> (i)) & 1)
#define ALL(v) (v).begin(), (v).end()

ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}

ll LASTBIT(ll mask){return (mask) & (-mask);}
int pop_cnt(ll mask){return __builtin_popcountll(mask);}
int ctz(ll mask){return __builtin_ctzll(mask);}
int logOf(ll mask){return 63 - __builtin_clzll(mask);}

mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
// mt19937_64 rng(69);
ll rngesus(ll l, ll r){return l + (ull) rng() % (r - l + 1);}

template <class T1, class T2>
    bool maximize(T1 &a, T2 b){
        if (a < b) {a = b; return true;}
        return false;
    }

template <class T1, class T2>
    bool minimize(T1 &a, T2 b){
        if (a > b) {a = b; return true;}
        return false;
    }

template <class T>
    void printArr(T& container, string separator = " ", string finish = "\n", ostream &out = cout){
        for(auto item: container) out << item << separator;
        out << finish;
    }

template <class T>
    void remove_dup(vector<T> &a){
        sort(ALL(a));
        a.resize(unique(ALL(a)) - a.begin());
    }


int main(void){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int n; ll a, b; cin >> n >> a >> b;

    vector<pair<ll, ll>> r(n);
    for(int i= 0; i<n; ++i) cin >> r[i].first >> r[i].second;

    __int128 wut = a; wut *= b;
    __int128 wow = __gcd((__int128)(b+1), wut);
    __int128 cycle = wut / wow;

    vector<pair<ll,ll>> ligma;
    for(auto i: r){
        if (i.second - i.first + 1 >= cycle){
            ligma.push_back({0, cycle});
        }
        else{
            i.first %= cycle; i.second %= cycle;
            if (i.second < i.first ){
                ligma.push_back({i.first, cycle - 1});
                ligma.push_back({0, i.second});
            }
            else{
                ligma.push_back({i.first, i.second});
            }
        }
    }

    sort(ALL(ligma));

    vector<pair<ll, ll>> real;
    for(auto i: ligma){
        if (real.size() && real.back().second >= i.first){
            maximize(real.back().second, i.second);
        }
        else real.push_back(i);
    }

    ll ans = 0;
    for(auto i: real) ans += i.second - i.first + 1;

    cout << ans << "\n";

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -