Submission #897821

#TimeUsernameProblemLanguageResultExecution timeMemory
897821Dec0DeddStrange Device (APIO19_strange_device)C++14
100 / 100
1377 ms118904 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> pii; void solve() { ll n, a, b; cin>>n>>a>>b; a/=__gcd(a, b+1); ll md=1e18+10; if (a <= LLONG_MAX/b) md=a*b; map<ll, ll> cnt; for (int i=1; i<=n; ++i) { ll lf, rf; cin>>lf>>rf; if (rf-lf+1 >= md) { cout<<md<<"\n"; return; } lf%=md, rf%=md; if (lf <= rf) { ++cnt[lf], --cnt[rf+1]; } else { ++cnt[lf], --cnt[md]; ++cnt[0], --cnt[rf+1]; } } vector<pii> v; for (auto u : cnt) v.push_back(u); ll ans=0, sz=v.size(), sm=0; for (int i=0; i+1<sz; ++i) { sm+=v[i].second; if (sm > 0) ans+=v[i+1].first-v[i].first; } cout<<ans<<"\n"; } int main() { int t=1; //cin>>t; while (t--) solve(); }
#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...