#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<unordered_set>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
#define all(x) x.begin(),x.end()
ll gcd(ll a,ll b){
return (b?gcd(b,a%b):a);
}
int main(){
ll n,A,B;
cin>>n>>A>>B;
ll M=A/gcd(A,B+1)*B; //cerr<<M<<endl;
vector<P> v;
rep(i,n){
ll l,r;
cin>>l>>r;
ll L=l/M,R=r/M;
if(L+2<=R){
v.push_back(make_pair(0,+1));
v.push_back(make_pair(M,-1));
}
else if(L+1==R){
v.push_back(make_pair(0,+1));
v.push_back(make_pair(r%M+1,-1));
v.push_back(make_pair(l%M,+1));
v.push_back(make_pair(M,-1));
}
else{
v.push_back(make_pair(l%M,+1));
v.push_back(make_pair(r%M+1,-1));
}
}
sort(all(v));
ll ans=0,rui=0,bef=0;
for(auto e:v){
ll t=e.first,di=e.second;
//cout<<"#"<<t<<" "<<di<<endl;
ans+=(rui>0)*(t-bef);
rui+=di;
bef=t;
}
cout<<ans<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
28 ms |
1268 KB |
Output is correct |
3 |
Correct |
29 ms |
1396 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
256 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
256 KB |
Output is correct |
10 |
Correct |
6 ms |
256 KB |
Output is correct |
11 |
Correct |
5 ms |
256 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
27 ms |
1396 KB |
Output is correct |
17 |
Correct |
239 ms |
7268 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
256 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
7 ms |
376 KB |
Output is correct |
3 |
Correct |
7 ms |
376 KB |
Output is correct |
4 |
Correct |
7 ms |
376 KB |
Output is correct |
5 |
Correct |
1627 ms |
33760 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
2314 ms |
33808 KB |
Output is correct |
3 |
Correct |
2330 ms |
33852 KB |
Output is correct |
4 |
Correct |
2277 ms |
37844 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
2314 ms |
33808 KB |
Output is correct |
3 |
Correct |
2330 ms |
33852 KB |
Output is correct |
4 |
Correct |
2277 ms |
37844 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
2324 ms |
37612 KB |
Output is correct |
7 |
Correct |
2288 ms |
37820 KB |
Output is correct |
8 |
Correct |
2294 ms |
37876 KB |
Output is correct |
9 |
Correct |
2416 ms |
37912 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
2314 ms |
33808 KB |
Output is correct |
3 |
Correct |
2330 ms |
33852 KB |
Output is correct |
4 |
Correct |
2277 ms |
37844 KB |
Output is correct |
5 |
Correct |
5 ms |
256 KB |
Output is correct |
6 |
Correct |
233 ms |
7272 KB |
Output is correct |
7 |
Correct |
235 ms |
7272 KB |
Output is correct |
8 |
Correct |
233 ms |
7396 KB |
Output is correct |
9 |
Correct |
234 ms |
7268 KB |
Output is correct |
10 |
Correct |
231 ms |
7268 KB |
Output is correct |
11 |
Correct |
233 ms |
7268 KB |
Output is correct |
12 |
Correct |
228 ms |
7288 KB |
Output is correct |
13 |
Correct |
242 ms |
7268 KB |
Output is correct |
14 |
Correct |
237 ms |
7268 KB |
Output is correct |
15 |
Correct |
244 ms |
7268 KB |
Output is correct |
16 |
Correct |
240 ms |
7268 KB |
Output is correct |
17 |
Correct |
238 ms |
7268 KB |
Output is correct |
18 |
Correct |
2303 ms |
37696 KB |
Output is correct |
19 |
Correct |
2245 ms |
37888 KB |
Output is correct |
20 |
Correct |
2407 ms |
37820 KB |
Output is correct |
21 |
Correct |
243 ms |
7364 KB |
Output is correct |
22 |
Correct |
225 ms |
7272 KB |
Output is correct |
23 |
Correct |
744 ms |
21232 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
240 ms |
7268 KB |
Output is correct |
3 |
Correct |
240 ms |
7428 KB |
Output is correct |
4 |
Correct |
2442 ms |
37760 KB |
Output is correct |
5 |
Correct |
239 ms |
7268 KB |
Output is correct |
6 |
Correct |
238 ms |
7268 KB |
Output is correct |
7 |
Correct |
238 ms |
7268 KB |
Output is correct |
8 |
Correct |
248 ms |
7252 KB |
Output is correct |
9 |
Correct |
237 ms |
7268 KB |
Output is correct |
10 |
Correct |
249 ms |
7516 KB |
Output is correct |
11 |
Correct |
238 ms |
7328 KB |
Output is correct |
12 |
Correct |
232 ms |
7288 KB |
Output is correct |
13 |
Correct |
244 ms |
7268 KB |
Output is correct |
14 |
Correct |
2400 ms |
37636 KB |
Output is correct |
15 |
Correct |
245 ms |
7540 KB |
Output is correct |
16 |
Correct |
2264 ms |
38004 KB |
Output is correct |
17 |
Correct |
2421 ms |
37564 KB |
Output is correct |
18 |
Correct |
5 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
28 ms |
1268 KB |
Output is correct |
3 |
Correct |
29 ms |
1396 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
256 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
256 KB |
Output is correct |
10 |
Correct |
6 ms |
256 KB |
Output is correct |
11 |
Correct |
5 ms |
256 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
27 ms |
1396 KB |
Output is correct |
17 |
Correct |
239 ms |
7268 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is correct |
19 |
Correct |
5 ms |
256 KB |
Output is correct |
20 |
Correct |
5 ms |
376 KB |
Output is correct |
21 |
Correct |
5 ms |
256 KB |
Output is correct |
22 |
Correct |
5 ms |
256 KB |
Output is correct |
23 |
Correct |
5 ms |
376 KB |
Output is correct |
24 |
Correct |
5 ms |
256 KB |
Output is correct |
25 |
Correct |
7 ms |
376 KB |
Output is correct |
26 |
Correct |
7 ms |
376 KB |
Output is correct |
27 |
Correct |
7 ms |
376 KB |
Output is correct |
28 |
Correct |
1627 ms |
33760 KB |
Output is correct |
29 |
Correct |
5 ms |
256 KB |
Output is correct |
30 |
Correct |
2314 ms |
33808 KB |
Output is correct |
31 |
Correct |
2330 ms |
33852 KB |
Output is correct |
32 |
Correct |
2277 ms |
37844 KB |
Output is correct |
33 |
Correct |
5 ms |
376 KB |
Output is correct |
34 |
Correct |
2324 ms |
37612 KB |
Output is correct |
35 |
Correct |
2288 ms |
37820 KB |
Output is correct |
36 |
Correct |
2294 ms |
37876 KB |
Output is correct |
37 |
Correct |
2416 ms |
37912 KB |
Output is correct |
38 |
Correct |
5 ms |
256 KB |
Output is correct |
39 |
Correct |
233 ms |
7272 KB |
Output is correct |
40 |
Correct |
235 ms |
7272 KB |
Output is correct |
41 |
Correct |
233 ms |
7396 KB |
Output is correct |
42 |
Correct |
234 ms |
7268 KB |
Output is correct |
43 |
Correct |
231 ms |
7268 KB |
Output is correct |
44 |
Correct |
233 ms |
7268 KB |
Output is correct |
45 |
Correct |
228 ms |
7288 KB |
Output is correct |
46 |
Correct |
242 ms |
7268 KB |
Output is correct |
47 |
Correct |
237 ms |
7268 KB |
Output is correct |
48 |
Correct |
244 ms |
7268 KB |
Output is correct |
49 |
Correct |
240 ms |
7268 KB |
Output is correct |
50 |
Correct |
238 ms |
7268 KB |
Output is correct |
51 |
Correct |
2303 ms |
37696 KB |
Output is correct |
52 |
Correct |
2245 ms |
37888 KB |
Output is correct |
53 |
Correct |
2407 ms |
37820 KB |
Output is correct |
54 |
Correct |
243 ms |
7364 KB |
Output is correct |
55 |
Correct |
225 ms |
7272 KB |
Output is correct |
56 |
Correct |
744 ms |
21232 KB |
Output is correct |
57 |
Correct |
5 ms |
256 KB |
Output is correct |
58 |
Correct |
240 ms |
7268 KB |
Output is correct |
59 |
Correct |
240 ms |
7428 KB |
Output is correct |
60 |
Correct |
2442 ms |
37760 KB |
Output is correct |
61 |
Correct |
239 ms |
7268 KB |
Output is correct |
62 |
Correct |
238 ms |
7268 KB |
Output is correct |
63 |
Correct |
238 ms |
7268 KB |
Output is correct |
64 |
Correct |
248 ms |
7252 KB |
Output is correct |
65 |
Correct |
237 ms |
7268 KB |
Output is correct |
66 |
Correct |
249 ms |
7516 KB |
Output is correct |
67 |
Correct |
238 ms |
7328 KB |
Output is correct |
68 |
Correct |
232 ms |
7288 KB |
Output is correct |
69 |
Correct |
244 ms |
7268 KB |
Output is correct |
70 |
Correct |
2400 ms |
37636 KB |
Output is correct |
71 |
Correct |
245 ms |
7540 KB |
Output is correct |
72 |
Correct |
2264 ms |
38004 KB |
Output is correct |
73 |
Correct |
2421 ms |
37564 KB |
Output is correct |
74 |
Correct |
5 ms |
256 KB |
Output is correct |
75 |
Correct |
5 ms |
256 KB |
Output is correct |
76 |
Correct |
5 ms |
256 KB |
Output is correct |
77 |
Correct |
5 ms |
256 KB |
Output is correct |
78 |
Correct |
5 ms |
256 KB |
Output is correct |
79 |
Correct |
28 ms |
1268 KB |
Output is correct |
80 |
Correct |
2449 ms |
37924 KB |
Output is correct |
81 |
Correct |
2446 ms |
38024 KB |
Output is correct |
82 |
Correct |
2396 ms |
37628 KB |
Output is correct |
83 |
Correct |
2422 ms |
37632 KB |
Output is correct |
84 |
Correct |
2411 ms |
38080 KB |
Output is correct |
85 |
Correct |
2375 ms |
37924 KB |
Output is correct |
86 |
Correct |
740 ms |
21232 KB |
Output is correct |
87 |
Correct |
5 ms |
256 KB |
Output is correct |