Submission #677177

#TimeUsernameProblemLanguageResultExecution timeMemory
677177Melika0ghStrange Device (APIO19_strange_device)C++17
100 / 100
1684 ms31120 KiB
#include<bits/stdc++.h> using namespace std; typedef long long int ll; typedef long double ld; #define sync ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0) #define pb push_back #define pii pair<int, int> #define mp make_pair #define fi first #define se second const ll inf = 2e18; int main() { int n; ll A, B, AB; cin >> n >> A >> B; A /= __gcd(A, (B + 1)); if(inf / A >= B) AB = A * B; else AB = inf; vector<pair<ll, ll> > vec; bool check = false; for(int i = 0; i < n; i++) { ll l, r; cin >> l >> r; if(check) { continue; } if(r - l + 1 >= AB) { check = true; continue; } r %= AB, l %= AB; if(l > r) { vec.pb(mp(0, r)); vec.pb(mp(l, AB - 1)); } else vec.pb(mp(l, r)); } sort(vec.begin(), vec.end()); ll ans = 0, mx = -1; for(auto tmp : vec) { ll x = tmp.fi, y = tmp.se; if(mx < x) ans += y - x + 1; else ans += max(ll(0), y - mx); mx = max(mx, y); } if(check) ans = AB; cout << ans << '\n'; }
#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...