제출 #612379

#제출 시각아이디문제언어결과실행 시간메모리
612379Theo830Strange Device (APIO19_strange_device)C++17
100 / 100
478 ms53380 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll INF = 1e18+7; const ll MOD = 998244353; typedef pair<ll,ll> ii; #define iii pair<ii,ll> #define f(i,a,b) for(ll i = a;i < b;i++) #define pb push_back #define vll vector<ll> #define F first #define S second #define all(x) (x).begin(), (x).end() ///I hope I will get uprating and don't make mistakes ///I will never stop programming ///sqrt(-1) Love C++ ///Please don't hack me ///@TheofanisOrfanou Theo830 ///Think different approaches (bs,dp,greedy,graphs,shortest paths,mst) ///Stay Calm ///Look for special cases ///Beware of overflow and array bounds ///Think the problem backwards ///Training int main(void){ ios_base::sync_with_stdio(0); cin.tie(0); ll n,A,B; cin>>n>>A>>B; ll c = B; ll g = __gcd(B+1,A); A /= g; ll maxi = 1e18 + 105; if(maxi / c < A){ c = maxi; } else{ c *= A; } vector<ii>ex; f(i,0,n){ ll l,r; cin>>l>>r; if(r - l + 1 >= c){ ex.pb(ii(0,c - 1)); } else{ l %= c; r %= c; if(l <= r){ ex.pb(ii(l,r)); } else{ ex.pb(ii(l,c-1)); ex.pb(ii(0,r)); } } } sort(all(ex)); ll l = ex[0].F,r = ex[0].S; ll ans = 0; for(auto x:ex){ if(x.F <= r){ r = max(r,x.S); } else{ ans += r - l + 1; l = x.F,r = x.S; } } ans += r - l + 1; cout<<ans<<"\n"; }
#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...