Submission #1044633

#TimeUsernameProblemLanguageResultExecution timeMemory
1044633vjudge1Strange Device (APIO19_strange_device)C++17
100 / 100
280 ms54044 KiB
#include "bits/stdc++.h" using namespace std; #define int int64_t #define pb push_back using lint=__int128_t; const int lim=200100; const int mod=1e9+7; using pii=pair<int,int>; signed main(){ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #ifdef Local freopen(".in","r",stdin);freopen(".out","w",stdout); #endif int n,a,b; cin>>n>>a>>b; lint cntofdif=a/__gcd(a,(b+1)); cntofdif*=b; cntofdif=min(cntofdif,lint(2e18)); int all=cntofdif; //cerr<<all<<"\n"; vector<pii>ranges; for(int i=0;i<n;i++){ int l,r; cin>>l>>r; if(all<=r-l+1){ cout<<all; return 0; } l%=all; r%=all; if(l<=r){ ranges.pb({l,r}); //cerr<<"inserted "<<l<<" "<<r<<"\n"; } else{ //cerr<<"oops "<<l<<" "<<r<<"\n"; ranges.pb({l,all-1}); ranges.pb({0,r}); } } sort(ranges.begin(),ranges.end()); int cnt=0,left=-1; for(auto[f,s]:ranges){ if(left<f){ cnt+=s-f+1; }else if(left<s){ cnt+=s-left; } left=max(left,s); } cout<<cnt<<"\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...