#include <bits/stdc++.h>
#define SPEEDUP ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define fr first
#define sc second
#define pb push_back
#define mk make_pair
#define all(s) s.begin(),s.end()
#define int long long
using namespace std;
const int N = (1e6 + 12);
const int mod = (1e9 + 7);
const int inf = (1e18 + 7);
int l[N], r[N], used[N];
main(){
SPEEDUP;
int n, A, B;
cin >> n >> A >> B;
// for(int i = 0; i <= 25; i++){
// cout << i << " ";
// }
// cout << endl;
// vector<int > vec;
// for(int i = 0;i <= 25; i++){
// cout << ((i + (i + B - 1) / B)) << " ";
// vec.pb(((i + (i + B - 1) / B)));
// }
// cout << endl;
// for(int i = 0;i <= 25; i++){
// cout << (i % B) << " ";
// }
// cout << endl;
// for(auto to : vec){
// cout << to % A << " ";
// }
// cout << endl;
for(int i = 1; i <= n; i++){
cin >> l[i] >> r[i];
}
int ans = 0;
int la = -1, ra = -1;
for(int i = 1; i <= n; i++){
if(la == -1){
la = l[i], ra = r[i];
}
else{
la = max(la, l[i]);
ra = max(ra, r[i]);
}
ans += ra - la + 1;
la = ra + 1;
}
int x;
if(0 == (A % (B + 1ll))){
if(inf / B >= (A / (B + 1ll))){
x = B * (A / (B + 1ll));
}
else{
cout << ans << endl;
return 0;
}
}
else{
if(inf / A >= B){
x = A * B;
}
else{
cout << ans << endl;
return 0;
}
}
// set<pair<int,int >> st;
ans = 0;
for(int i = 1;i <= n; i++){
if(x <= r[i] - l[i] + 1){
cout << x << endl;
return 0;
}
if(r[i] % x >= l[i] % x){
// cout << i << " ! " << l[i] % x << " " << r[i] % x <<endl;
// st.insert({l[i] % x, r[i] % x});
for(int j = l[i] % x; j <= r[i] % x; j++){
if(used[j]){
continue;
}
ans++;
used[j] = 1;
}
}
else{
// cout << i << " ? " << 0 << " " << r[i] % x << endl;
// cout << i << " ? " << l[i] % x << " " << x - 1 << endl;
// st.insert({0, r[i] % x});
for(int j = 0; j <= r[i] % x; j++){
if(used[j]){
continue;
}
ans++;
used[j] = 1;
}
// st.insert({l[i] % x, x - 1});
for(int j = l[i] % x; j <= x - 1; j++){
if(used[j]){
continue;
}
ans++;
used[j] = 1;
}
}
}
// la = -1, ra = -1;
// for(auto to : st){
// if(la == -1){
// la = to.fr, ra = to.sc;
// }
// else{
// la = max(la, to.fr);
// ra = max(ra, to.sc);
// }
// if(la <= ra){
// ans += ra - la + 1;
// la = ra + 1;
// }
// }
cout << ans;
}
Compilation message
strange_device.cpp:19:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
19 | main(){
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Runtime error |
7 ms |
896 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Runtime error |
53 ms |
48548 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
5 ms |
5100 KB |
Output is correct |
3 |
Correct |
6 ms |
5100 KB |
Output is correct |
4 |
Correct |
5 ms |
4716 KB |
Output is correct |
5 |
Execution timed out |
5060 ms |
23788 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
392 ms |
22508 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
392 ms |
22508 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
392 ms |
22508 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Runtime error |
41 ms |
3788 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Runtime error |
7 ms |
896 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |