#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18+7;
const ll MOD = 998244353;
typedef pair<ll,ll> ii;
#define iii pair<ii,ll>
#define f(i,a,b) for(ll i = a;i < b;i++)
#define pb push_back
#define vll vector<ll>
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
///I hope I will get uprating and don't make mistakes
///I will never stop programming
///sqrt(-1) Love C++
///Please don't hack me
///@TheofanisOrfanou Theo830
///Think different approaches (bs,dp,greedy,graphs,shortest paths,mst)
///Stay Calm
///Look for special cases
///Beware of overflow and array bounds
///Think the problem backwards
///Training
int main(void){
ios_base::sync_with_stdio(0);
cin.tie(0);
ll n,A,B;
cin>>n>>A>>B;
ll c = B;
ll g = __gcd(B+1,A);
A /= g;
ll maxi = 1e18 + 105;
if(maxi / c < A){
c = maxi;
}
else{
c *= A;
}
vector<ii>ex;
f(i,0,n){
ll l,r;
cin>>l>>r;
if(r - l + 1 >= c){
ex.pb(ii(0,c - 1));
}
else{
l %= c;
r %= c;
if(l <= r){
ex.pb(ii(l,r));
}
else{
ex.pb(ii(l,c-1));
ex.pb(ii(0,r));
}
}
}
sort(all(ex));
ll l = ex[0].F,r = ex[0].S;
ll ans = 0;
for(auto x:ex){
if(x.F <= r){
r = x.S;
}
else{
ans += r - l + 1;
l = x.F,r = x.S;
}
}
ans += r - l + 1;
cout<<ans<<"\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
6 ms |
984 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
368 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
316 KB |
Output is correct |
2 |
Correct |
629 ms |
53268 KB |
Output is correct |
3 |
Correct |
459 ms |
53336 KB |
Output is correct |
4 |
Correct |
463 ms |
53192 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
316 KB |
Output is correct |
2 |
Correct |
629 ms |
53268 KB |
Output is correct |
3 |
Correct |
459 ms |
53336 KB |
Output is correct |
4 |
Correct |
463 ms |
53192 KB |
Output is correct |
5 |
Correct |
1 ms |
316 KB |
Output is correct |
6 |
Correct |
548 ms |
53192 KB |
Output is correct |
7 |
Correct |
543 ms |
53192 KB |
Output is correct |
8 |
Correct |
510 ms |
53280 KB |
Output is correct |
9 |
Correct |
541 ms |
53260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
316 KB |
Output is correct |
2 |
Correct |
629 ms |
53268 KB |
Output is correct |
3 |
Correct |
459 ms |
53336 KB |
Output is correct |
4 |
Correct |
463 ms |
53192 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
46 ms |
5732 KB |
Output is correct |
7 |
Correct |
49 ms |
5692 KB |
Output is correct |
8 |
Correct |
49 ms |
5676 KB |
Output is correct |
9 |
Correct |
58 ms |
5612 KB |
Output is correct |
10 |
Correct |
42 ms |
5696 KB |
Output is correct |
11 |
Correct |
50 ms |
5664 KB |
Output is correct |
12 |
Correct |
53 ms |
5724 KB |
Output is correct |
13 |
Correct |
49 ms |
5648 KB |
Output is correct |
14 |
Correct |
44 ms |
5672 KB |
Output is correct |
15 |
Incorrect |
51 ms |
5656 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
47 ms |
5688 KB |
Output is correct |
3 |
Correct |
45 ms |
5648 KB |
Output is correct |
4 |
Correct |
740 ms |
53236 KB |
Output is correct |
5 |
Correct |
69 ms |
5700 KB |
Output is correct |
6 |
Correct |
52 ms |
5676 KB |
Output is correct |
7 |
Correct |
47 ms |
5660 KB |
Output is correct |
8 |
Correct |
62 ms |
5728 KB |
Output is correct |
9 |
Correct |
54 ms |
5700 KB |
Output is correct |
10 |
Correct |
46 ms |
5628 KB |
Output is correct |
11 |
Correct |
49 ms |
5652 KB |
Output is correct |
12 |
Correct |
47 ms |
5616 KB |
Output is correct |
13 |
Correct |
44 ms |
5652 KB |
Output is correct |
14 |
Incorrect |
555 ms |
53176 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
6 ms |
984 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |