Submission #678146

#TimeUsernameProblemLanguageResultExecution timeMemory
678146faribourzStrange Device (APIO19_strange_device)C++14
100 / 100
779 ms67948 KiB
// Only GOD // believe in yourself // Nemidam Del Be In Darde Donya! #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> pii; #define F first #define S second #define pb push_back #define all(x) x.begin(), x.end() #define bit(x, y) ((x >> y)&1) #define sz(x) (int)x.size() #define kill(x) return cout << x << '\n', void() #define KILL(x) return cout << x << '\n', 0 #define int ll const int INF = 1e18; map<int, int> M; int32_t main(){ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); int A, B, n; cin >> n >> A >> B; int g = __gcd(A, B+1); int AB; A /= g; if(INF / A < B+1){ AB = INF; } else AB = A*B; int ans = 0; for(int i = 0; i < n; i++){ int l, r; cin >> l >> r; if(r-l+1 >= AB) ans = AB; l %= AB, r %= AB; if(!r){ M[0]++; M[1]--; if(l) M[l]++, M[AB]--; continue; } if(l <= r){ M[l]++; M[r+1]--; } else{ M[0]++; M[l]++; M[AB]--; M[r+1]--; } } if(ans) KILL(ans); int sum = 0, lst = -1; ans = 0; for(auto x : M){ if(lst == -1){ sum += x.S; lst = x.F; continue; } if(sum > 0){ ans += x.F-lst; } sum += x.S; lst = x.F; } cout << min(ans, AB); }
#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...