Submission #258125

#TimeUsernameProblemLanguageResultExecution timeMemory
258125amoo_safarStrange Device (APIO19_strange_device)C++17
100 / 100
742 ms69168 KiB
// Zende bad Shoma nasime faghat ! #include <bits/stdc++.h> #define pb push_back #define F first #define S second #define all(x) x.begin(), x.end() #define debug(x) cerr << #x << " : " << x << '\n' using namespace std; typedef __int128 ll; typedef long double ld; typedef string str; typedef pair<ll, ll> pll; const ll Mod = 1000000007LL; const int N = 2e5 + 10; const ll Inf = 2242545357980376863LL; const ll Log = 30; int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n, A, B; cin >> n >> A >> B; ll z = A / __gcd(A, B + 1); ll L = z * B; vector<pll> V; long long l, r; for(int i = 0; i < n; i++){ cin >> l >> r; if(r - l + 1 >= L) return cout << (long long)(L) << '\n', 0; if(l % L <= r % L) V.pb({l % L, r % L}); else { V.pb({l % L, L - 1}); V.pb({0, r % L}); } } sort(all(V)); ll ans = L; ll la = -1; for(auto x : V){ ans -= max(__int128(0), x.F - la - 1); la = max(la, x.S); } ans -= max(__int128(0), L - la - 1); cout << (long long)(ans) << '\n'; 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...