Submission #154803

#TimeUsernameProblemLanguageResultExecution timeMemory
154803AkashiStrange Device (APIO19_strange_device)C++14
10 / 100
2703 ms16548 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[2000005]; int n; long long A, B; int main() { cin >> n >> A >> B; double lg1 = log2((double)A), lg2 = log2((double)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){ if(a[i].r - a[i].l + 1 >= prod){ a[i].l = 0; a[i].r = prod - 1; continue ; } 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...