Submission #810248

#TimeUsernameProblemLanguageResultExecution timeMemory
810248petezaStrange Device (APIO19_strange_device)C++14
0 / 100
398 ms36940 KiB
#include <bits/stdc++.h> using namespace std; int n; long long a, b, mod; long long l, r, last=0, sum = 0; vector<pair<long long, bool>> vec; int ctr = 0; int main() { cin.tie(0) -> sync_with_stdio(0); cin >> n >> a >> b; a /= __gcd(a, b); if(a >= 4e18/b) mod = 4e18; else mod = a*b; while(n--) { cin >> l >> r; if(r-l+1 >= mod) { cout << mod; return 0; } l %= mod; r %= mod; if(l <= r) vec.emplace_back(l, 0), vec.emplace_back(r+1, 1); else vec.emplace_back(l, 0), vec.emplace_back(mod, 1), vec.emplace_back(0, 0), vec.emplace_back(r+1, 1); } sort(vec.begin(), vec.end()); for(auto e:vec) { sum += min(ctr, 1) * (e.first-last); if(e.second) ctr--; else ctr++; last = e.first; } cout << sum; }
#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...