#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,a,b;
ll l[1000005],r[1000005];
ll gcd(ll a, ll b){
if (b==0) return a;
return gcd(b,a%b);
}
ll lcm (ll a, ll b){
return a/gcd(a,b)*b;
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin>>n>>a>>b;
ll t;
ll x;
if ((b+1)%a==0){
t=b;
}
else{
t=a*b;
}
// cout<<t;
// t=lcm(t,b);
set <pair<ll,ll>> st;
for (int i=1;i<=n;i++){
cin>>l[i]>>r[i];
ll u=r[i]-l[i]+1;
if (u>=t){
l[i]=1;
r[i]=t;
}
else{
ll q=r[i]-l[i];
ll p=l[i]%t;
l[i]=p;
r[i]=l[i]+q;
}
if (r[i<=t])
st.insert({l[i],r[i]});
else{
st.insert({l[i],t});
st.insert({1,(u-(t-l[i]+1))});
}
// cout<<l[i]<<" "<<r[i]<<endl;
}
vector <pair<ll,ll>> pasang;
for (auto z:st){
pasang.push_back(z);
// cout<<z.first<<" "<<z.second<<endl;
}
// sort(pasang+1,pasang+n+1);
vector <pair<ll,ll>> jawab;
ll last=pasang[0].second,previous=pasang[0].first;
pasang.push_back({(ll)1e18+100,(ll)1e18+100});
sort(pasang.begin(),pasang.end());
for (int i=1;i<=n;i++){
if (pasang[i].first<=last){
last=pasang[i].second;
}
else{
jawab.push_back({previous,last});
previous=pasang[i].first;
last=pasang[i].second;
}
}
// if (previous>jawab[jawab.size()-1].second){
// // jawab.push_back({previous,last});
// }
ll ans=0;
for (int i=0;i<jawab.size();i++){
ans+=jawab[i].second-jawab[i].first+1;
}
cout<<ans;
}
Compilation message
strange_device.cpp: In function 'int main()':
strange_device.cpp:72:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
72 | for (int i=0;i<jawab.size();i++){
| ~^~~~~~~~~~~~~
strange_device.cpp:17:8: warning: unused variable 'x' [-Wunused-variable]
17 | ll x;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
5 ms |
1576 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
509 ms |
118800 KB |
Output is correct |
3 |
Incorrect |
513 ms |
118924 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
509 ms |
118800 KB |
Output is correct |
3 |
Incorrect |
513 ms |
118924 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
509 ms |
118800 KB |
Output is correct |
3 |
Incorrect |
513 ms |
118924 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
53 ms |
12804 KB |
Output is correct |
3 |
Correct |
57 ms |
12732 KB |
Output is correct |
4 |
Correct |
527 ms |
119260 KB |
Output is correct |
5 |
Correct |
54 ms |
14404 KB |
Output is correct |
6 |
Correct |
52 ms |
14424 KB |
Output is correct |
7 |
Correct |
54 ms |
14364 KB |
Output is correct |
8 |
Correct |
58 ms |
14396 KB |
Output is correct |
9 |
Correct |
52 ms |
14352 KB |
Output is correct |
10 |
Correct |
65 ms |
14436 KB |
Output is correct |
11 |
Correct |
52 ms |
14396 KB |
Output is correct |
12 |
Correct |
48 ms |
14420 KB |
Output is correct |
13 |
Correct |
50 ms |
14348 KB |
Output is correct |
14 |
Incorrect |
544 ms |
119260 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
5 ms |
1576 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |