#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
ll n,a,b;
cin>>n>>a>>b;
ll period=-1;
if(a/__gcd(a,b+1)>(1e18+10)/b+1) period=1e18+10;
else period=a/__gcd(a,b+1)*b;
map<ll,ll> ev;
for(int i=0;i<n;i++){
ll l,r;
cin>>l>>r;
if(r-l+1>=period){
ev[0]++;
ev[period]--;
continue;
}
l%=period;
r%=period;
if(l<=r){
ev[l]++;
ev[r+1]--;
}else{
ev[0]++;
ev[r+1]--;
ev[l]++;
ev[period]--;
}
}
ll res=0;
ll tren=0;
ll prosli=-1;
for(auto i:ev){
tren+=i.second;
if(tren>0){
if(prosli==-1) prosli=i.first;
}else{
if(res!=-1) res+=i.first-prosli;
prosli=-1;
}
}
cout<<res;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
15 ms |
852 KB |
Output is correct |
3 |
Correct |
15 ms |
852 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
16 ms |
864 KB |
Output is correct |
17 |
Correct |
154 ms |
6452 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
907 ms |
288 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1540 ms |
62932 KB |
Output is correct |
3 |
Correct |
1579 ms |
62908 KB |
Output is correct |
4 |
Correct |
1580 ms |
63012 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1540 ms |
62932 KB |
Output is correct |
3 |
Correct |
1579 ms |
62908 KB |
Output is correct |
4 |
Correct |
1580 ms |
63012 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1600 ms |
63044 KB |
Output is correct |
7 |
Correct |
1600 ms |
62952 KB |
Output is correct |
8 |
Correct |
1577 ms |
62940 KB |
Output is correct |
9 |
Correct |
1648 ms |
62856 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1540 ms |
62932 KB |
Output is correct |
3 |
Correct |
1579 ms |
62908 KB |
Output is correct |
4 |
Correct |
1580 ms |
63012 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
144 ms |
6456 KB |
Output is correct |
7 |
Correct |
149 ms |
6596 KB |
Output is correct |
8 |
Correct |
147 ms |
6604 KB |
Output is correct |
9 |
Correct |
157 ms |
6428 KB |
Output is correct |
10 |
Correct |
146 ms |
6492 KB |
Output is correct |
11 |
Correct |
146 ms |
6524 KB |
Output is correct |
12 |
Correct |
152 ms |
6448 KB |
Output is correct |
13 |
Correct |
158 ms |
6516 KB |
Output is correct |
14 |
Correct |
146 ms |
6440 KB |
Output is correct |
15 |
Correct |
154 ms |
6528 KB |
Output is correct |
16 |
Correct |
159 ms |
6496 KB |
Output is correct |
17 |
Correct |
150 ms |
6568 KB |
Output is correct |
18 |
Correct |
1529 ms |
62900 KB |
Output is correct |
19 |
Correct |
1570 ms |
62884 KB |
Output is correct |
20 |
Correct |
1627 ms |
62860 KB |
Output is correct |
21 |
Correct |
148 ms |
6476 KB |
Output is correct |
22 |
Correct |
148 ms |
6524 KB |
Output is correct |
23 |
Correct |
411 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
166 ms |
6484 KB |
Output is correct |
3 |
Correct |
162 ms |
6564 KB |
Output is correct |
4 |
Correct |
1591 ms |
62916 KB |
Output is correct |
5 |
Correct |
151 ms |
6576 KB |
Output is correct |
6 |
Correct |
159 ms |
6476 KB |
Output is correct |
7 |
Correct |
154 ms |
6476 KB |
Output is correct |
8 |
Correct |
153 ms |
6576 KB |
Output is correct |
9 |
Correct |
160 ms |
6452 KB |
Output is correct |
10 |
Correct |
149 ms |
6508 KB |
Output is correct |
11 |
Correct |
148 ms |
6540 KB |
Output is correct |
12 |
Correct |
154 ms |
6500 KB |
Output is correct |
13 |
Correct |
156 ms |
6456 KB |
Output is correct |
14 |
Correct |
1623 ms |
63020 KB |
Output is correct |
15 |
Correct |
146 ms |
6476 KB |
Output is correct |
16 |
Correct |
1528 ms |
63036 KB |
Output is correct |
17 |
Correct |
1550 ms |
63004 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
15 ms |
852 KB |
Output is correct |
3 |
Correct |
15 ms |
852 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
16 ms |
864 KB |
Output is correct |
17 |
Correct |
154 ms |
6452 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
0 ms |
212 KB |
Output is correct |
25 |
Correct |
2 ms |
340 KB |
Output is correct |
26 |
Correct |
2 ms |
340 KB |
Output is correct |
27 |
Correct |
2 ms |
340 KB |
Output is correct |
28 |
Correct |
907 ms |
288 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
1540 ms |
62932 KB |
Output is correct |
31 |
Correct |
1579 ms |
62908 KB |
Output is correct |
32 |
Correct |
1580 ms |
63012 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
1600 ms |
63044 KB |
Output is correct |
35 |
Correct |
1600 ms |
62952 KB |
Output is correct |
36 |
Correct |
1577 ms |
62940 KB |
Output is correct |
37 |
Correct |
1648 ms |
62856 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
144 ms |
6456 KB |
Output is correct |
40 |
Correct |
149 ms |
6596 KB |
Output is correct |
41 |
Correct |
147 ms |
6604 KB |
Output is correct |
42 |
Correct |
157 ms |
6428 KB |
Output is correct |
43 |
Correct |
146 ms |
6492 KB |
Output is correct |
44 |
Correct |
146 ms |
6524 KB |
Output is correct |
45 |
Correct |
152 ms |
6448 KB |
Output is correct |
46 |
Correct |
158 ms |
6516 KB |
Output is correct |
47 |
Correct |
146 ms |
6440 KB |
Output is correct |
48 |
Correct |
154 ms |
6528 KB |
Output is correct |
49 |
Correct |
159 ms |
6496 KB |
Output is correct |
50 |
Correct |
150 ms |
6568 KB |
Output is correct |
51 |
Correct |
1529 ms |
62900 KB |
Output is correct |
52 |
Correct |
1570 ms |
62884 KB |
Output is correct |
53 |
Correct |
1627 ms |
62860 KB |
Output is correct |
54 |
Correct |
148 ms |
6476 KB |
Output is correct |
55 |
Correct |
148 ms |
6524 KB |
Output is correct |
56 |
Correct |
411 ms |
332 KB |
Output is correct |
57 |
Correct |
0 ms |
212 KB |
Output is correct |
58 |
Correct |
166 ms |
6484 KB |
Output is correct |
59 |
Correct |
162 ms |
6564 KB |
Output is correct |
60 |
Correct |
1591 ms |
62916 KB |
Output is correct |
61 |
Correct |
151 ms |
6576 KB |
Output is correct |
62 |
Correct |
159 ms |
6476 KB |
Output is correct |
63 |
Correct |
154 ms |
6476 KB |
Output is correct |
64 |
Correct |
153 ms |
6576 KB |
Output is correct |
65 |
Correct |
160 ms |
6452 KB |
Output is correct |
66 |
Correct |
149 ms |
6508 KB |
Output is correct |
67 |
Correct |
148 ms |
6540 KB |
Output is correct |
68 |
Correct |
154 ms |
6500 KB |
Output is correct |
69 |
Correct |
156 ms |
6456 KB |
Output is correct |
70 |
Correct |
1623 ms |
63020 KB |
Output is correct |
71 |
Correct |
146 ms |
6476 KB |
Output is correct |
72 |
Correct |
1528 ms |
63036 KB |
Output is correct |
73 |
Correct |
1550 ms |
63004 KB |
Output is correct |
74 |
Correct |
1 ms |
212 KB |
Output is correct |
75 |
Correct |
1 ms |
304 KB |
Output is correct |
76 |
Correct |
1 ms |
212 KB |
Output is correct |
77 |
Correct |
1 ms |
212 KB |
Output is correct |
78 |
Correct |
1 ms |
212 KB |
Output is correct |
79 |
Correct |
17 ms |
1204 KB |
Output is correct |
80 |
Correct |
1716 ms |
99916 KB |
Output is correct |
81 |
Correct |
1687 ms |
100160 KB |
Output is correct |
82 |
Correct |
1807 ms |
100024 KB |
Output is correct |
83 |
Correct |
2135 ms |
99912 KB |
Output is correct |
84 |
Correct |
1749 ms |
100044 KB |
Output is correct |
85 |
Correct |
1670 ms |
100040 KB |
Output is correct |
86 |
Correct |
424 ms |
12804 KB |
Output is correct |
87 |
Correct |
1 ms |
212 KB |
Output is correct |