Submission #972561

#TimeUsernameProblemLanguageResultExecution timeMemory
972561simona1230Strange Device (APIO19_strange_device)C++17
100 / 100
358 ms54440 KiB
#include <bits/stdc++.h> using namespace std; long long n,a,b; pair<long long,long long> p[2000001]; void solve() { int cnt=n; long long h=1e18+1; a/=__gcd(a,b+1); if(1e18/a>=b)h=b*a; //cout<<h<<endl; for(long long i=1;i<=n;i++) { long long l,r; cin>>l>>r; if(r-l+1>=h) { cout<<h<<endl; return; } p[i]={l%(h),r%(h)}; if(p[i].first>p[i].second) { cnt++; p[cnt].first=0; p[cnt].second=p[i].second; p[i].second=h-1; } } long long ans=0; sort(p+1,p+cnt+1); long long r=-1; for(long long i=1;i<=cnt;i++) { if(p[i].second>r) { if(p[i].first>r) ans+=p[i].second-p[i].first+1; else ans+=p[i].second-r; } r=max(r,p[i].second); } cout<<ans<<endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin>>n>>a>>b; solve(); 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...