Submission #154801

#TimeUsernameProblemLanguageResultExecution timeMemory
154801AkashiStrange Device (APIO19_strange_device)C++14
5 / 100
2744 ms53344 KiB
#include <bits/stdc++.h> using namespace std; struct interv{ long long l, r; bool operator < (const interv &aux)const{ if(l != aux.l) return l < aux.l; return r < aux.r; } }; interv a[1000005]; int n; long long A, B; int main() { cin >> n >> A >> B; long long lg1 = log2(A), lg2 = log2(B); long long prod = 0; if(lg1 + lg2 <= 63) prod = 1LL * A * B; int m = n; for(int i = 1; i <= n ; ++i){ cin >> a[i].l >> a[i].r; if(prod != 0){ a[i].l %= prod, a[i].r %= prod; if(a[i].r < a[i].l) a[++m].l = 0, a[m].r = a[i].r, a[i].r = prod - 1; } } n = m; sort(a + 1, a + n + 1); long long Sol = 0, l = -2, r = -3; for(int i = 1; i <= n ; ++i){ if(r < a[i].l){ Sol = Sol + (r - l + 1); l = a[i].l; r = a[i].r; } else r = max(r, a[i].r); } Sol = Sol + (r - l + 1); cout << Sol; return 0; }
#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...