Submission #519136

#TimeUsernameProblemLanguageResultExecution timeMemory
519136cadmiumskyStrange Device (APIO19_strange_device)C++14
35 / 100
1751 ms100200 KiB
#include <bits/stdc++.h> #define int long long using namespace std; signed main() { int a,b,q; bool ok = 0; cin >> q >> a >> b; map<int,int> smen; int per = a * b / __gcd(b + 1, a); // formula magica care e motivata din.. niste calcule de clasa a 7a de algebra modulara O_o if(log2((double)a / (double)__gcd(b + 1, a)) + log2(b) > 60) per = 1e18 + 1; for(int i = 0, cl, cr, l, r; i < q; i ++) { cin >> l >> r; cl = per * ceil((double)l / (double)per); cr = per * floor((double)r / (double)per); if(cl < cr) { ok = 1; } if(cl == cr && l < cl && cr <= r) { l %= per; r %= per; smen[l]++; smen[0]++; smen[r + 1]--; //cout << l << ' '<< -per - 1 << '\n' << 0 << ' ' << r << '\n'; } else { l %= per; r %= per; smen[l]++; smen[r + 1]--; //cout << l << ' ' << r << '\n'; } } if(ok) { cout << per << '\n'; return 0; } smen[per]; int total = 0, cnt = 0, last = -1; for(auto x : smen) { if(last != x.first && cnt > 0) total += x.first - last; if(x.first >= per) break; //cout << x.first << ' '<< x.second << '\n'; cnt += x.second; last = x.first; } cout << total << '\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...