#include<bits/stdc++.h>
using namespace std;
#define all(fl) fl.begin(),fl.end()
#define pb push_back
#define fi first
#define se second
#define for1(i,j,k) for(int i=j;i<=k;i++)
#define for2(i,j,k) for(int i=j;i>=k;i--)
#define for3(i,j,k,l) for(int i=j;i<=k;i+=l)
#define lb lower_bound
#define ub upper_bound
#define sz(a) (int)a.size()
#define gcd __gcd
#define lcm(x,y) x*y/__gcd(x,y)
using pii=pair<int,int>;
using pli=pair<long long,int>;
using pil=pair<int,long long>;
using pll=pair<long long,long long>;
const int maxn=1e6+9;
pll a[maxn];
vector<pll>b[maxn];
int bit[maxn];
signed main(){
srand(time(0));
ios_base::sync_with_stdio(0);
cin.tie(0);
//freopen("usaco.INP","r",stdin);
//freopen("usaco.OUT","w",stdout);
int n;
long long x,y;
cin>>n>>x>>y;
for1(i,1,n){
cin>>a[i].fi>>a[i].se;
}
long long d=a[n].se/y;
if (d<x){
long long ans=0;
for1(i,1,n){
ans+=(a[i].se-a[i].fi+1);
}
cout<<ans;
return 0;
}
long long z=x*y;
if (n==1){
long long d=(a[1].fi)/z;
a[1].fi-=z*d;
a[1].se-=z*d;
long long t1=a[1].fi/z,t2=a[1].se/z;
if (t1+1<t2){
cout<<z;
return 0;
}
if (t1==t2){
cout<<(a[1].se-a[1].fi+1);
return 0;
}
pll l1={a[1].fi,z-1};
pll l2={0,a[1].se%z};
if (l1.se>=l2.fi){
cout<<z;
return 0;
}
cout<<l1.se-l1.fi+1+l2.se-l2.fi+1;
return 0;
}
for1(i,1,n){
long long d=(a[i].fi)/z;
a[i].fi-=z*d;
a[i].se-=z*d;
long long t1=a[i].fi/z,t2=a[i].se/z;
if (t1+1<t2){
b[i].pb({0,z-1});
continue;
}
if (t1==t2){
b[i].pb({a[i].fi%z,a[i].se%z});
continue;
}
pll l1={a[i].fi,z-1};
pll l2={0,a[i].se%z};
b[i].pb(l1);
b[i].pb(l2);
}
for1(i,1,n){
for (auto v:b[i]){
bit[v.fi]++;
bit[v.se+1]--;
//cout<<v.fi<<" "<<v.se<<'\n';
}
}
int ans=0;
for1(i,1,z){
bit[i]+=bit[i-1];
//if (bit[i])ans++;
}
for1(i,0,z){
if (bit[i])ans++;
}
cout<<ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Runtime error |
35 ms |
49452 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
23820 KB |
Output is correct |
2 |
Correct |
11 ms |
23764 KB |
Output is correct |
3 |
Correct |
12 ms |
23808 KB |
Output is correct |
4 |
Correct |
12 ms |
23764 KB |
Output is correct |
5 |
Correct |
12 ms |
23772 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
23764 KB |
Output is correct |
2 |
Correct |
17 ms |
27556 KB |
Output is correct |
3 |
Correct |
17 ms |
27676 KB |
Output is correct |
4 |
Correct |
17 ms |
27036 KB |
Output is correct |
5 |
Correct |
323 ms |
99904 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
23764 KB |
Output is correct |
2 |
Runtime error |
443 ms |
150016 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
23764 KB |
Output is correct |
2 |
Runtime error |
443 ms |
150016 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
23764 KB |
Output is correct |
2 |
Runtime error |
443 ms |
150016 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
23832 KB |
Output is correct |
2 |
Runtime error |
86 ms |
57512 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Runtime error |
35 ms |
49452 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |