#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define debug(x) cout << "Line " << __LINE__ << ", " << #x << " is " << x << endl
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ll long long
#define pll pair<ll, ll>
#define ull unsigned long long
#define ld long double
#define pii pair<ll, ll>
#define nl '\n'
#define tb '\t'
#define sp ' '
using namespace std;
const ll MX=1000001, MOD=998244353, BLOCK=330, INF=1e9+7, INFF=2e18;
const ld ERR=1e-7, pi=3.14159265358979323846;
ll N, A, B, cyc, last=0, GCD;
vector<pll> L;
int main(){
fastio;
cin >> N >> A >> B;
A/=__gcd(A, B+1ll);
cyc=(INFF+A-1)/A;
if(B>=cyc)
cyc=INFF;
else
cyc=A*B;
for(int i=0, x, y; i<N; i++){
cin >> x >> y;
if(y-x+1>=cyc){
L.pb({0, cyc-1});
}else{
x%=cyc;
y%=cyc;
if(x<=y)
L.pb({x, y});
else{
L.pb({0, y});
L.pb({x, cyc-1});
}
}
}
N=L.size();
sort(L.begin(), L.end());
ll ans=0;
for(auto i:L){
ll x=i.fi, y=i.se;
if(y<last)
continue;
x=max(last, x);
ans+=y-x+1;
last=max(last, y+1);
}
cout << ans << nl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Incorrect |
1 ms |
848 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
107 ms |
33256 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
107 ms |
33256 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
107 ms |
33256 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Incorrect |
10 ms |
4548 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Incorrect |
1 ms |
848 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |