Submission #206799

#TimeUsernameProblemLanguageResultExecution timeMemory
206799rkm0959Strange Device (APIO19_strange_device)C++14
65 / 100
609 ms33920 KiB
#include <bits/stdc++.h> #define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); using namespace std; typedef long long int ll; typedef long double ldb; ll gcd(ll x,ll y){if(!x||!y) return x+y; return x%y==0?y:gcd(y,x%y);} ll n, A, B, inf=2e18, ans; pair<ll, ll> wow[2111111]; int main(void) { fio; ll i, j, u, v, cnt=0; cin>>n>>A>>B; ll g=gcd(A, B+1); __int128 cc=(A/g); cc=cc*B; for(i=1 ; i<=n ; i++) { cin>>u>>v; if(cc>=inf) { wow[++cnt]=make_pair(u, v); continue; } u=(ll)(u%cc); v=(ll)(v%cc); if(u<=v) wow[++cnt]=make_pair(u, v); if(u>v) { wow[++cnt]=make_pair(u, (ll)cc-1LL); wow[++cnt]=make_pair(0LL, v); } } sort(wow+1, wow+cnt+1); for(i=1 ; i<=cnt ; i++) { j=i; ll rng=wow[i].second; while(j<=cnt && wow[j].first<=rng) { rng=max(rng, wow[j].second); j++; } j--; ans+=(rng-wow[i].first+1); i=j; } cout<<ans; return 0; }
#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...