Submission #732782

#TimeUsernameProblemLanguageResultExecution timeMemory
732782Magikarp4000Strange Device (APIO19_strange_device)C++17
0 / 100
1 ms212 KiB
#include <bits/stdc++.h> using namespace std; #define OPTM ios_base::sync_with_stdio(0); cin.tie(0); #define INF int(1e9+7) #define ln '\n' #define ll long long #define ull unsigned long long #define ui unsigned int #define us unsigned short #define FOR(i,s,n) for (int i = s; i < n; i++) #define FORR(i,n,s) for (int i = n; i > s; i--) #define FORX(u, arr) for (auto u : arr) #define PB push_back #define in(v,x) (v.find(x) != v.end()) #define F first #define S second #define PII pair<int, int> #define PLL pair<ll, ll> #define UM unordered_map #define US unordered_set #define PQ priority_queue #define ALL(v) v.begin(), v.end() const ll LLINF = 1e18+1; #define int long long int n,a,b; vector<PII> v; int gcd(int a, int b) { return (b == 0) ? a : gcd(b,a%b); } signed main() { //freopen("","r",stdin); //freopen("","w",stdout); OPTM; cin >> n >> a >> b; int p = a*b/gcd(a,b+1); FOR(i,0,n) { int l,r; cin >> l >> r; int c = l%p, d = r%p; if (r-l+1 >= p) return p; if (d >= c) v.PB({c,d}); else { v.PB({c,p-1}); v.PB({0,d}); } } int res = 0; sort(ALL(v)); int vn = v.size(); int s = v[0].F, e = v[0].S; FOR(i,1,vn) { if (v[i].F <= e) e = max(e,v[i].S); else { res += e-s+1; s = v[i].F; e = v[i].S; } } res += e-s+1; cout << res; }
#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...