Submission #732830

#TimeUsernameProblemLanguageResultExecution timeMemory
732830Magikarp4000Strange Device (APIO19_strange_device)C++17
35 / 100
517 ms18140 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 = 2e18; ll n,a,b; vector<PLL> v; ll gcd(ll a, ll b) { return (b == 0) ? a : gcd(b,a%b); } int main() { OPTM; cin >> n >> a >> b; ll prod = a*b; ll p = 1; if (a != 0 && prod/a != b) p = LLINF; else p = a*b/gcd(a,b+1); FOR(i,0,n) { ll l,r; cin >> l >> r; ll c = l%p, d = r%p; if (r-l+1 >= p) v.PB({0,p-1}); else if (d >= c) v.PB({c,d}); else { v.PB({c,p-1}); v.PB({0,d}); } } ll res = 0; sort(ALL(v)); ll vn = v.size(); ll 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...