Submission #363855

#TimeUsernameProblemLanguageResultExecution timeMemory
363855Mahdi_ShokoufiStrange Device (APIO19_strange_device)C++17
5 / 100
704 ms81096 KiB
//In the name of Allah #include <bits/stdc++.h> using namespace std; #define mp make_pair typedef long long ll; const ll inf = 1e18 + 10; int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll n, a, b; cin >> n >> a >> b; ll p = (inf / b < a / __gcd(a, b + 1) ? inf : a / __gcd(a, b + 1) * b); set < pair < ll , ll > > st; for (int i = 0; i < n; i ++){ ll l, r; cin >> l >> r; if (p <= r - l + 1) return cout << p, 0; l %= p; r %= p; if (l <= r) st.insert(mp(l, -r)); else st.insert(mp(l, -p + 1)), st.insert(mp(0, r)); } ll ans = 0, mx = -1; for (auto itr = st.begin(); itr != st.end(); itr ++){ ll x = itr -> first, y = -(itr -> second); ans += max(0LL, y - max(mx + 1, x) + 1); mx = max(mx, y); } cout << ans; 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...