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;
typedef long long ll;
int main(){
ll n,a,b;
cin>>n>>a>>b;
ll period=-1;
if(a/__gcd(a,b+1)>(1e18+10)/b+1) period=1e18+10;
else period=a/__gcd(a,b+1)*b;
map<ll,ll> ev;
for(int i=0;i<n;i++){
ll l,r;
cin>>l>>r;
if(r-l+1>=period){
ev[0]++;
ev[period]--;
continue;
}
l%=period;
r%=period;
if(l<=r){
ev[l]++;
ev[r+1]--;
}else{
ev[0]++;
ev[r+1]--;
ev[l]++;
ev[period]--;
}
}
ll res=0;
ll tren=0;
ll prosli=-1;
for(auto i:ev){
tren+=i.second;
if(tren>0){
if(prosli==-1) prosli=i.first;
}else{
if(res!=-1) res+=i.first-prosli;
prosli=-1;
}
}
cout<<res;
return 0;
}
# | 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... |