Submission #232629

#TimeUsernameProblemLanguageResultExecution timeMemory
232629limabeansStrange Device (APIO19_strange_device)C++17
5 / 100
615 ms48532 KiB
#include <bits/stdc++.h> using namespace std; template<typename T> void out(T x) { cout << x << endl; exit(0); } #define watch(x) cout << (#x) << " is " << (x) << endl typedef long long ll; const ll mod = 1e9+7; const int maxn = 1e6 + 5; ll n, a, b; ll getx(ll t) { return (t+t/b)%a; } ll gety(ll t) { return t%b; } ll merge(vector<pair<ll,ll>> v) { sort(v.begin(), v.end()); // for (auto p: v) { // cout<<p.first<<" "<<p.second<<endl; // } ll res = 0; n = v.size(); auto cur = v.front(); for (int i=1; i<n; i++) { ll x=v[i].first; ll y=v[i].second; if (x>cur.second) { res += cur.second-cur.first+1; cur = v[i]; } else { cur.second=max(cur.second,y); } } res += cur.second-cur.first+1; return res; } vector<pair<ll,ll>> v; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin>>n>>a>>b; v.resize(n); for (int i=0; i<n; i++) { cin>>v[i].first>>v[i].second; } auto safe_lcm = [](ll x, ll y) { ll tmp = x / __gcd(x,y); if (tmp > 1e18/y) return (ll)1e18 + 1; return tmp*y; }; ll lcm = safe_lcm(a, b); if (lcm>1e18) { //merge intervals ll res = merge(v); out(res); } vector<pair<ll,ll>> cv; for (int i=0; i<n; i++) { v[i].first %= (a*b); v[i].second %= (a*b); if (v[i].second>=v[i].first) { cv.push_back(v[i]); } else { assert(v[i].first>v[i].second); cv.push_back({v[i].first,a*b}); cv.push_back({1,v[i].second}); } } ll ans = merge(cv); out(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...