# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1085658 | 4QT0R | Strange Device (APIO19_strange_device) | C++17 | 0 ms | 0 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 __int128_t
void fastscan(ll &n){
n=0;
for(char zn=getchar();47<zn && zn<58; zn=getchar()){
n=10*n+zn-48;
}
}
set<pair<ll,ll>> s;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
ll n,A,B;
fastscan(n);
fastscan(A);
fastscan(B);
A/=gcd(A,B+1);
ll mod=A*B;
for (ll i = 1; i<=n; i++){
ll l,p;
fastscan(l);
fastscan(p);
if (l/mod!=p/mod){
s.insert({l%mod,mod-1});
s.insert({0,p%mod});
}
else s.insert({l%mod,p%mod});
}
ll mx=-1;
ll ans=0;
for (auto [l,p] : s){
if (p<=mx)continue;
ans+=p-max(mx+1,l)+1;
mx=max(mx,p);
}
cout << (long long)ans << '\n';
}