Submission #975039

#TimeUsernameProblemLanguageResultExecution timeMemory
975039hirayuu_ojStrange Device (APIO19_strange_device)C++17
10 / 100
356 ms54036 KiB
#include<bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0; i<n; i++) #define all(x) x.begin(),x.end() using ll=long long; const ll INF=1LL<<61; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); ll n,A,B; cin>>n>>A>>B; ll rp=A*B; if((INF/A)/B==0LL){ rp=INF; } vector<pair<ll,ll>> segs; rep(i,n){ ll l,r; cin>>l>>r; r++; if(r-l>=rp){ cout<<rp<<"\n"; return 0; } l%=rp; r%=rp; if(l<r){ segs.emplace_back(pair<ll,ll>(l,r)); } if(l>r){ segs.emplace_back(pair<ll,ll>(l,rp)); segs.emplace_back(pair<ll,ll>(0,r)); } } sort(all(segs)); ll lf=0,ri=0; ll ans=0; for(auto &[nl,nr]:segs){ if(nl<ri){ ri=max(ri,nr); } else{ ans+=ri-lf; lf=nl; ri=nr; } } ans+=ri-lf; 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...