# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
933754 | irmuun | Strange Device (APIO19_strange_device) | C++17 | 418 ms | 71472 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
ll n,a,b;
cin>>n>>a>>b;
ll l[n+5],r[n+5];
ll g=a/gcd((b+1)%a,a),MX=1e18+1;
if(MX/b>=g){
g=g*b;
}
else{
g=MX;
}
for(ll i=1;i<=n;i++){
cin>>l[i]>>r[i];
}
vector<pair<ll,ll>>v;
for(ll i=1;i<=n;i++){
if(r[i]-l[i]+1>=g){
cout<<g;
return 0;
}
ll L=l[i]%g,R=r[i]%g;
if(L<=R){
v.pb({L,R});
}
else{
v.pb({0,R});
v.pb({L,g-1});
}
}
sort(all(v));
ll ans=0;
for(ll i=0;i<v.size();){
ll nxt=i,curR=v[i].ss;
while(nxt+1<v.size()&&v[nxt+1].ff<=curR){
nxt++;
curR=max(curR,v[nxt].ss);
}
ans+=curR-v[i].ff+1;
i=nxt+1;
}
cout<<ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |