Submission #348119

#TimeUsernameProblemLanguageResultExecution timeMemory
348119arnold518Strange Device (APIO19_strange_device)C++14
100 / 100
867 ms82936 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAXN = 1e6; int N; ll A, B, L; pll P[MAXN+10]; map<ll, ll> M; void addrange(ll l, ll r) { M[l]++; M[r+1]--; } int main() { scanf("%d%lld%lld", &N, &A, &B); for(int i=1; i<=N; i++) scanf("%lld%lld", &P[i].first, &P[i].second); L=__gcd(A, B+1); if(A/L>=(ll)1e18/B) L=1e18; else L=A/L*B; for(int i=1; i<=N; i++) { ll l=P[i].first, r=P[i].second; if(r-l+1>=L) return !printf("%lld\n", L); if(l%L<=r%L) addrange(l%L, r%L); else { addrange(l%L, L-1); addrange(0, r%L); } } M[L]; ll t=0, ans=0; for(auto it=M.begin(); it!=M.end(); it++) { if(it->first==L) break; t+=it->second; if(t) ans+=next(it)->first-it->first; } printf("%lld\n", ans); }

Compilation message (stderr)

strange_device.cpp: In function 'int main()':
strange_device.cpp:24:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   24 |  scanf("%d%lld%lld", &N, &A, &B);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
strange_device.cpp:25:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   25 |  for(int i=1; i<=N; i++) scanf("%lld%lld", &P[i].first, &P[i].second);
      |                          ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...