Submission #706121

#TimeUsernameProblemLanguageResultExecution timeMemory
706121heavylightdecompStrange Device (APIO19_strange_device)C++14
100 / 100
1961 ms77780 KiB
#include<bits/stdc++.h> using namespace std; #define int long long int n,a,b; const int inf = 2e18+5; #define gcd(a,b) __gcd(a,b) signed main() { cin >> n >> a >> b; int p; if(a/gcd(a,b+1) > inf/b) { p = inf; } else { p = a / gcd(a,b+1) * b; } vector<pair<int,int>> range; for(int i = 0; i < n; i++) { int l,r; cin >> l >> r; if(r-l >= p) { range.push_back({0,p-1}); } else { l = l % p, r = r % p; if(l > r) { range.push_back({l, p-1}); range.push_back({0, r}); } else { range.push_back({l,r}); } } } sort(begin(range), end(range)); vector<pair<int,int>> jake; for(auto it : range) { if(jake.empty() or jake.back().second < it.first) { jake.push_back(it); } else { jake.back().second = max(jake.back().second, it.second); } } int res = 0; for(auto it : jake) res += it.second - it.first + 1; cout << res <<'\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...