Submission #519138

#TimeUsernameProblemLanguageResultExecution timeMemory
519138cadmiumskyStrange Device (APIO19_strange_device)C++14
0 / 100
1 ms204 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(log10((double)a / (double)__gcd(b + 1, a)) + log10(b) >= 18) per = 1e18 + 1; for(int i = 0, cl, cr, l, r; i < q; i ++) { cin >> l >> r; cl = per * (l / per + 1); cr = per * (r / per); if(cl < cr) { ok = 1; } if(cl == cr) { 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...