제출 #980815

#제출 시각아이디문제언어결과실행 시간메모리
980815Tuanlinh123이상한 기계 (APIO19_strange_device)C++17
100 / 100
565 ms80564 KiB
#include<bits/stdc++.h> #define ll long long #define pll pair<ll, ll> #define pb push_back #define mp make_pair #define fi first #define se second #define ld long double #define sz(a) ((ll)(a).size()) using namespace std; const ll inf=2e18; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll n, A, B; cin >> n >> A >> B, A=A/__gcd(A, B+1); vector <pll> range; if (A>inf/B) { range.resize(n); for (pll &i:range) cin >> i.fi >> i.se; } else { ll M=A*B; for (ll i=0; i<n; i++) { ll l, r; cin >> l >> r; ll bl=l/M, br=r/M; if (bl==br) range.pb({l%M, r%M}); else if (bl+1==br) range.pb({l%M, M-1}), range.pb({0, r%M}); else range.pb({0, M-1}); } } vector <ll> cx; for (pll i:range) cx.pb(i.fi), cx.pb(i.se+1); sort(cx.begin(), cx.end()), cx.resize(unique(cx.begin(), cx.end())-cx.begin()); vector <ll> sum(sz(cx), 0); for (pll i:range) { sum[lower_bound(cx.begin(), cx.end(), i.fi)-cx.begin()]++; sum[lower_bound(cx.begin(), cx.end(), i.se+1)-cx.begin()]--; } ll ans=0; for (ll i=0, crr=0; i<sz(cx); crr+=sum[i], ans+=(!!crr)*(cx[i+1]-cx[i]), i++) {} cout << ans; }
#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...