// be name khoda
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
//#define mp make_pair
typedef long long ll;
#define int long long
#pragma GCC optimize("Ofast")
const int maxn = 2e5+10;
const int mod = 1e9+7;
const ll inf = 1e18+10;
//const int N = 2e6+10;
int n, m, A, B;
signed main()
{
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin>> n >> A >> B;
m = A / __gcd(A,B+1);
if(m <= inf/B) m *= B;
else m = inf;
bool T = 0;
vector<pair<int,int>> seg;
for(int i = 1, l, r; i <= n; i++)
{
cin>> l >> r;
if(r-l+1 >= m) T = 1;
l %= m; r %= m;
if(l <= r)
seg.push_back({l,r});
else
{
seg.push_back({l,m-1});
seg.push_back({0,r});
}
}
if(T)
return cout<< m, 0;
sort(seg.begin(), seg.end());
ll ans = 0, mx = -1;
for(int i = 0; i < seg.size(); i++)
{
int l = seg[i].F, r = seg[i].S;
//cout<< l <<" "<< r <<"\n";
mx = max(mx,l-1);
ans += r-mx;
mx = max(mx,r);
}
cout<< ans;
}
/*
3 3 3
4 4
7 9
17 18
3 5 10
1 20
50 68
89 98
2 16 13
2 5
18 18
*/
Compilation message
strange_device.cpp: In function 'int main()':
strange_device.cpp:49:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < seg.size(); i++)
~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Incorrect |
9 ms |
768 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Incorrect |
530 ms |
17120 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Incorrect |
530 ms |
17120 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Incorrect |
530 ms |
17120 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Incorrect |
57 ms |
2544 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Incorrect |
9 ms |
768 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |