#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define ppb pop_back
#define ep insert
#define endl '\n'
#define elif else if
#define pow pwr
#define sqrt sqrtt
#define int long long
typedef unsigned long long ull;
using namespace std;
const int N=1e6+5;
int l[3][N],r[3][N],n,a,b;
int32_t main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
cin>>n>>a>>b;
int g=__gcd(a,b+1);
a/=g;
int step=(b+1)/g;
for (int i=1;i<=n;i++){
int L,R;cin>>L>>R;
for (int m=0;m<b;m++){
int ll=0,rr=1e18/b,mid,lx=-1,rx=-1;
while (ll<=rr){
mid=ll+(rr-ll)/2;
if (mid*b+m>=L){
lx=mid;
rr=mid-1;
}else ll=mid+1;
}
ll=0,rr=1e18/b;
while (ll<=rr){
mid=ll+(rr-ll)/2;
if (mid*b+m<=R){
rx=mid;
ll=mid+1;
}else rr=mid-1;
}
if (lx>rx) l[m][i]=r[m][i]=-1;
else{
l[m][i]=lx;
r[m][i]=rx;
}
}
}int ans=0;
for (int m=0;m<b;m++){
vector<pair<int,int>> v;
for (int i=1;i<=n;i++){
if (l[m][i]==-1) continue;
if (l[m][i]-r[m][i]>=a) {v.pb({0,a-1});continue;}
int L=(l[m][i])%a;
int R=(r[m][i])%a;
if (L<=R){
v.pb({L,R});
}
else{
v.pb({L,a-1});
v.pb({0,R});
}
}
if (v.empty()) continue;
sort(v.begin(),v.end());
//for (auto u:v) cout<<u.F<<' '<<u.S<<endl;
set<pair<int,int>> s;
pair<int,int> cur=v[0];
for (int i=0;i<v.size();i++){
int l=max(cur.F,v[i].F),r=min(cur.S,v[i].S);
if (l>r){
s.ep(cur);
cur=v[i];
}
else{
cur.F=min(cur.F,v[i].F);
cur.S=max(cur.S,v[i].S);
}
}
s.ep(cur);
for (auto u:s) ans+=u.S-u.F+1;
}cout<<ans<<endl;
return 0;
}
Compilation message
strange_device.cpp: In function 'int32_t main()':
strange_device.cpp:68:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
68 | for (int i=0;i<v.size();i++){
| ~^~~~~~~~~
strange_device.cpp:21:9: warning: unused variable 'step' [-Wunused-variable]
21 | int step=(b+1)/g;
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Runtime error |
10 ms |
21180 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2392 KB |
Output is correct |
2 |
Runtime error |
11 ms |
21340 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Runtime error |
10 ms |
21176 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2396 KB |
Output is correct |
2 |
Correct |
768 ms |
97484 KB |
Output is correct |
3 |
Correct |
884 ms |
97344 KB |
Output is correct |
4 |
Correct |
996 ms |
97768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2396 KB |
Output is correct |
2 |
Correct |
768 ms |
97484 KB |
Output is correct |
3 |
Correct |
884 ms |
97344 KB |
Output is correct |
4 |
Correct |
996 ms |
97768 KB |
Output is correct |
5 |
Correct |
2 ms |
2396 KB |
Output is correct |
6 |
Correct |
1463 ms |
112344 KB |
Output is correct |
7 |
Incorrect |
1111 ms |
76640 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2396 KB |
Output is correct |
2 |
Correct |
768 ms |
97484 KB |
Output is correct |
3 |
Correct |
884 ms |
97344 KB |
Output is correct |
4 |
Correct |
996 ms |
97768 KB |
Output is correct |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
6 |
Runtime error |
11 ms |
21340 KB |
Execution killed with signal 11 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Runtime error |
15 ms |
21340 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Runtime error |
10 ms |
21180 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |