#include <iostream>
#include <fstream>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <cstring>
#include <vector>
#include <algorithm>
#include <deque>
#include <set>
#include <utility>
#include <array>
#include <complex>
#include <map>
using u32 = unsigned;
using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f64 = double;
using f80 = long double;
using namespace std;
using pt = complex<f80>;
#define ALL(x) begin(x), end(x)
#define ShinLena cin.tie(nullptr)->sync_with_stdio(false);
#define N 400005
i64 n, a, b, l[N], r[N];
int main()
{
ShinLena;
cin >> n >> a >> b;
for (int i = 0; i < n; ++i) cin >> l[i] >> r[i];
if (b == 1)
{
constexpr i64 W=3000000;
vector<i64> t(W), lz(W),L(W),R(W);int alc=0;
auto e=[&](i64 x){return x<=0?0ll:x/2;};
auto _e=[&](int v,i64 l,i64 r){
if(L[v])return;
L[v]=++alc;R[v]=++alc;
};
auto _p=[&](int v,i64 l,i64 r){
_e(v,l,r);
if(lz[v]){t[v]=e(r)-e(l-1);if(l-r)lz[L[v]]=lz[R[v]]=lz[v];lz[v]=0;}
};
auto _u=[&](auto _u,i64 v,i64 l,i64 r,i64 x,int y){
_p(v,l,r);
if(r<x||y<l)return;
if(x<=l&&r<=y){lz[v]=1;_p(v,l,r);return;}
_u(_u,L[v],l,(l+r)/2,x,y);_u(_u,R[v],(l+r)/2+1,r,x,y);
t[v]=t[L[v]]+t[R[v]];
};
a*=2;
for (int i = 0; i < n; ++i)
{
l[i]*=2,r[i]*=2;
int lg = ::l[i] / a, rg = ::r[i] / a;
int ll = ::l[i] % a, rr = ::r[i] % a;
if (lg == rg)
{
_u(_u,0,0,a,ll,rr);
}
else if (lg + 1 == rg)
{
if (rr >= ll)
_u(_u,0,0,a,0,a);
else
{
_u(_u,0,0,a,0,rr);
_u(_u,0,0,a,ll,a);
}
}
else
{
_u(_u,0,0,a,0,a);
}
}
_p(0,0,a);
cout << t[0] << '\n';
return 0;
}
{
vector<pair<i64, i64>> v;
for (int i = 0; i < n; ++i) for (i64 j = l[i]; j <= r[i]; ++j)
v.push_back({(j+j/b)%a, j%b});
sort(ALL(v)); return cout << unique(ALL(v)) - begin(v), 0;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
17 ms |
96348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
15 ms |
96348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
15 ms |
96344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
15 ms |
96344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
15 ms |
96344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
15 ms |
96344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
14 ms |
96348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
17 ms |
96348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |