Submission #1034561

#TimeUsernameProblemLanguageResultExecution timeMemory
1034561andrei_iorgulescuStrange Device (APIO19_strange_device)C++14
100 / 100
932 ms69868 KiB
#include <bits/stdc++.h> using namespace std; #define int long long int n,A,B; int l[1000005],r[1000005]; signed main() { cin >> n >> A >> B; for (int i = 1; i <= n; i++) cin >> l[i] >> r[i]; __int128 AA = A, BB = B; __int128 FF = AA * BB / __gcd(AA,BB + 1); if (FF > r[n]) { int sumlen = 0; for (int i = 1; i <= n; i++) sumlen += r[i] - l[i] + 1; cout << sumlen; } else { int F = FF; for (int i = 1; i <= n; i++) { if (r[i] - l[i] + 1 >= F) { cout << F; return 0; } } vector<pair<int,int>> h; for (int i = 1; i <= n; i++) { if (r[i] % F >= l[i] % F) h.push_back({l[i] % F,r[i] % F}); else h.push_back({0,r[i] % F}),h.push_back({l[i] % F,F - 1}); } sort(h.begin(),h.end()); int ans = F; int rmax = -1; if (h.back().second != F - 1) ans -= F - 1 - h.back().second; for (auto it : h) { if (it.first > rmax + 1) ans -= (it.first - rmax - 1); rmax = max(rmax,it.second); } cout << ans; } return 0; } ///cate resturi modulo A * B / gcd(A,B + 1) gasesc?
#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...