Submission #1136469

#TimeUsernameProblemLanguageResultExecution timeMemory
1136469AldkStrange Device (APIO19_strange_device)C++20
100 / 100
282 ms16992 KiB
#include<bits/stdc++.h> #define pb push_back #define pf push_front //#define mp make_pair #define F first #define S second #define ff first #define ss second #define str string #define ll long long #define ull unsigned ll #define ld long double #define pll pair<ll,ll> #define plll pair<pll,ll> #define pllll pair<pll,pll> #define pld pair<ld,ld> #define vi vector<int> #define vl vector<ll> #define vll vector<pll> #define vlll vector<plll> #define vllll vector<pllll> #define vb vector<bool> #define sz(x) (x).size() #define fr front() //#define tp top() #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define bk back(); #define rep(i,a,b) for(int i=a;i<b;++i) //#pragma GCC target( "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") //#pragma GCC optimize("Ofast,unroll-loops,fast-math,O3") using namespace std; const ld pi=acos(-1.0); const ll e5=1e5; const ll e6=1e6; const ll e9=1e9; const ll inf=1e18; const ll mod=1e9+7; const ll mod2=998244353; const ll MOD=106710087877475399; const ll N=1e6+10; ll bpm(ll x,ll y,ll m){if(y==0)return 1%m;if(y==1)return x%m;ll p=bpm(x,y/2,m); if(y%2==0)return p*p%m;else return p*p%m*x%m;} ll bp(ll x,ll y){if(y==0)return 1;if(y==1)return x;ll p=bp(x,y/2); if(y%2==0)return p*p;else return p*p*x;} void solve(){ ll n,a,b,k,ans=0; cin>>n>>a>>b; k=a/gcd(a,b+1); if(inf/b>=k) k*=b; else k=inf+1; vll v; for(ll i=1;i<=n;i++){ ll l,r; cin>>l>>r; if(l+k<=r){ cout<<k; return; } l%=k, r%=k; if(l<=r) v.pb({l,r}); else v.pb({l,k-1}), v.pb({0,r}); } sort(all(v)); ll p=0; for(auto [l,r]:v){ if(p>r) continue; if(p<l) ans+=r-l+1, p=r+1; else ans+=r-p+1, p=r+1; } cout<<ans; return; } int main(/*Aldk*/){ ios_base::sync_with_stdio(false); cin.tie(NULL); //freopen("sequence.in", "r", stdin); //freopen("sequence.out ", "w", stdout); //cout<<setprecision(9)<<fixed; ll test=1; //cin>>test; for(ll i=1;i<=test;i++){ solve(); cout<<'\n'; } 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...