Submission #124469

#TimeUsernameProblemLanguageResultExecution timeMemory
124469amiratouStrange Device (APIO19_strange_device)C++14
5 / 100
654 ms56956 KiB
#include <bits/stdc++.h> using namespace std; #define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0) #define fi first #define se second #define debug(x) cerr << " - " << #x << ": " << x << endl; #define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl; #define debugii(x) cerr << " - " << #x << ": " << x.fi<<","<<x.se << endl; #define sep() cerr << "--------------------" << endl; #define all(x) (x).begin(),(x).end() #define sz(x) (ll)x.size() #define ll long long #define ii pair<ll,ll> #define v vector<int> #define vii vector<ii> #define vv vector<vector<int> > #define mp make_pair #define INF 1000000000 #define pb push_back #define EPS 1e-9 const int MOD = 1000000007; // 998244353 ll l[1000005],r[1000005]; vii vec; int main(){ boost; ll n,A,B; cin>>n>>A>>B; for (int i = 0; i < n; ++i){ cin>>l[i]>>r[i]; //if(!(A&1))l[i]*=2LL,r[i]*=2LL; } if(A<2){ cout<<1;return 0; } A/=__gcd(A,(B+1)); //if(!(A&1))A/=2; for (int i = 0; i < n; ++i) { if((r[i]-l[i]+1)>=A){vec.pb(ii(0,A-1));break;} if((r[i]%A)<(l[i]%A)){ ll lefty=l[i]%A,righty=A-1; vec.pb(ii(lefty,righty)); lefty=0,righty=r[i]%A; vec.pb(ii(lefty,righty)); continue; } vec.pb(ii(l[i]%A,r[i]%A)); } sort(all(vec)); vii final; ll lefty=vec[0].fi,righty=vec[0].se; for (int i = 1; i < sz(vec); ++i) { if(vec[i].fi<=righty){ righty=max(righty,vec[i].se); } else{ final.pb(ii(lefty,righty)); lefty=vec[i].fi,righty=vec[i].se; } } final.pb(ii(lefty,righty)); ll ans=0; for(auto it:final) ans+=(it.se-it.fi+1); cout<<ans; return 0; } //long long //array bounds //special cases //binary search
#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...