Submission #783793

#TimeUsernameProblemLanguageResultExecution timeMemory
783793devariaotaStrange Device (APIO19_strange_device)C++17
100 / 100
726 ms62944 KiB
#include<bits/stdc++.h> using namespace std; #define ioss ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define int long long #define pii pair<int, int> #define fi first #define se second #define pb push_back int n, a, b; vector<pii> range; bool comp(pii a, pii b) { return (a.fi < b.fi || (a.fi == b.fi && a.se < b.se)); } signed main() { ioss; // cari cycle (bisa manual, baru cari pola) // --- a*b / fpb(a, b+1) // hitung segment aktif // line sweep cin >> n >> a >> b; __int128_t cycle = (__int128_t)a*b/(__gcd(a, (b+1))); int ans = 0; for(int i = 0; i < n; i++) { int l, r; cin >> l >> r; if((r-l)+1 >= cycle) ans = cycle; l %= cycle, r %= cycle; if(l <= r) range.pb({l, 1}), range.pb({r, 2}); else range.pb({l, 1}), range.pb({cycle-1, 2}), range.pb({0, 1}), range.pb({r, 2}); } sort(range.begin(), range.end(), comp); if(ans == cycle) { cout << ans << endl; return 0; } int l = -1, cnt = 0, r = 0; for(auto [val, type] : range) { if(type == 1) { if(l == -1) l = val; cnt++; } else r = val, cnt--; if(cnt == 0) ans += (r-l)+1, l = -1; // cout << " :: " << l << " " << r << " " << cnt << " " << ans << endl; } cout << ans << endl; }
#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...