//by szh
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pb push_back
#define debug(x) cerr<<#x<<"="<<x<<endl
#define pq priority_queue
#define inf 0x3f
#define rep(i,a,b) for (int i=a;i<(b);i++)
#define MP make_pair
#define SZ(x) (int(x.size()))
#define ll long long
#define ALL(x) x.begin(),x.end()
const ll big = 1000000000000000000;
ll mod;
int n;
ll a,b;
vector <pll> range;
int main() {
// freopen("input.txt","r",stdin);
std::ios::sync_with_stdio(false);cin.tie();
cin>>n>>a>>b;
ll tmp = __gcd(a,b+1);
tmp = a/tmp;
if (1.0*big/tmp<(double)b) mod = big;
else mod = b*tmp;
debug(mod);
rep(i,0,n) {
ll l,r;cin>>l>>r;
if (l/mod==r/mod) range.pb({l%mod,r%mod});
else range.pb({l%mod,mod-1}),range.pb({0,r%mod});
}
sort(ALL(range));
ll cur = -1,ans=0;
for (auto x:range) {
if (x.fi<=cur) ans+=max(0ll,x.se-cur),cur = max(cur,x.se);
else ans+=x.se-x.fi+1,cur = x.se;
}
cout<<ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
5 ms |
984 KB |
Output is correct |
3 |
Correct |
6 ms |
976 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
320 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
316 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
320 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 |
320 KB |
Output is correct |
16 |
Correct |
5 ms |
984 KB |
Output is correct |
17 |
Correct |
47 ms |
5688 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
324 KB |
Output is correct |
5 |
Correct |
1 ms |
324 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Correct |
337 ms |
20224 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
454 ms |
24556 KB |
Output is correct |
3 |
Correct |
456 ms |
27596 KB |
Output is correct |
4 |
Correct |
412 ms |
23384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
454 ms |
24556 KB |
Output is correct |
3 |
Correct |
456 ms |
27596 KB |
Output is correct |
4 |
Correct |
412 ms |
23384 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
424 ms |
23472 KB |
Output is correct |
7 |
Correct |
446 ms |
24576 KB |
Output is correct |
8 |
Correct |
409 ms |
23960 KB |
Output is correct |
9 |
Correct |
461 ms |
23868 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
454 ms |
24556 KB |
Output is correct |
3 |
Correct |
456 ms |
27596 KB |
Output is correct |
4 |
Correct |
412 ms |
23384 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
43 ms |
5672 KB |
Output is correct |
7 |
Correct |
42 ms |
5624 KB |
Output is correct |
8 |
Correct |
45 ms |
5696 KB |
Output is correct |
9 |
Correct |
45 ms |
5700 KB |
Output is correct |
10 |
Correct |
44 ms |
5644 KB |
Output is correct |
11 |
Correct |
42 ms |
5696 KB |
Output is correct |
12 |
Correct |
43 ms |
5616 KB |
Output is correct |
13 |
Correct |
46 ms |
5696 KB |
Output is correct |
14 |
Correct |
43 ms |
5704 KB |
Output is correct |
15 |
Correct |
46 ms |
5600 KB |
Output is correct |
16 |
Correct |
47 ms |
5700 KB |
Output is correct |
17 |
Correct |
47 ms |
5696 KB |
Output is correct |
18 |
Correct |
419 ms |
23604 KB |
Output is correct |
19 |
Correct |
411 ms |
23768 KB |
Output is correct |
20 |
Correct |
453 ms |
23840 KB |
Output is correct |
21 |
Correct |
48 ms |
5632 KB |
Output is correct |
22 |
Correct |
42 ms |
5716 KB |
Output is correct |
23 |
Correct |
136 ms |
18428 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
49 ms |
5720 KB |
Output is correct |
3 |
Correct |
46 ms |
5704 KB |
Output is correct |
4 |
Correct |
510 ms |
27096 KB |
Output is correct |
5 |
Correct |
43 ms |
5632 KB |
Output is correct |
6 |
Correct |
45 ms |
5676 KB |
Output is correct |
7 |
Correct |
55 ms |
5692 KB |
Output is correct |
8 |
Correct |
48 ms |
5652 KB |
Output is correct |
9 |
Correct |
45 ms |
5672 KB |
Output is correct |
10 |
Correct |
48 ms |
5604 KB |
Output is correct |
11 |
Correct |
47 ms |
5780 KB |
Output is correct |
12 |
Correct |
42 ms |
5692 KB |
Output is correct |
13 |
Correct |
44 ms |
5696 KB |
Output is correct |
14 |
Correct |
472 ms |
23748 KB |
Output is correct |
15 |
Correct |
45 ms |
5660 KB |
Output is correct |
16 |
Correct |
418 ms |
23732 KB |
Output is correct |
17 |
Correct |
425 ms |
23568 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
5 ms |
984 KB |
Output is correct |
3 |
Correct |
6 ms |
976 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
320 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
316 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
320 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 |
320 KB |
Output is correct |
16 |
Correct |
5 ms |
984 KB |
Output is correct |
17 |
Correct |
47 ms |
5688 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
324 KB |
Output is correct |
23 |
Correct |
1 ms |
324 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
328 KB |
Output is correct |
28 |
Correct |
337 ms |
20224 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
454 ms |
24556 KB |
Output is correct |
31 |
Correct |
456 ms |
27596 KB |
Output is correct |
32 |
Correct |
412 ms |
23384 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
424 ms |
23472 KB |
Output is correct |
35 |
Correct |
446 ms |
24576 KB |
Output is correct |
36 |
Correct |
409 ms |
23960 KB |
Output is correct |
37 |
Correct |
461 ms |
23868 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
43 ms |
5672 KB |
Output is correct |
40 |
Correct |
42 ms |
5624 KB |
Output is correct |
41 |
Correct |
45 ms |
5696 KB |
Output is correct |
42 |
Correct |
45 ms |
5700 KB |
Output is correct |
43 |
Correct |
44 ms |
5644 KB |
Output is correct |
44 |
Correct |
42 ms |
5696 KB |
Output is correct |
45 |
Correct |
43 ms |
5616 KB |
Output is correct |
46 |
Correct |
46 ms |
5696 KB |
Output is correct |
47 |
Correct |
43 ms |
5704 KB |
Output is correct |
48 |
Correct |
46 ms |
5600 KB |
Output is correct |
49 |
Correct |
47 ms |
5700 KB |
Output is correct |
50 |
Correct |
47 ms |
5696 KB |
Output is correct |
51 |
Correct |
419 ms |
23604 KB |
Output is correct |
52 |
Correct |
411 ms |
23768 KB |
Output is correct |
53 |
Correct |
453 ms |
23840 KB |
Output is correct |
54 |
Correct |
48 ms |
5632 KB |
Output is correct |
55 |
Correct |
42 ms |
5716 KB |
Output is correct |
56 |
Correct |
136 ms |
18428 KB |
Output is correct |
57 |
Correct |
1 ms |
212 KB |
Output is correct |
58 |
Correct |
49 ms |
5720 KB |
Output is correct |
59 |
Correct |
46 ms |
5704 KB |
Output is correct |
60 |
Correct |
510 ms |
27096 KB |
Output is correct |
61 |
Correct |
43 ms |
5632 KB |
Output is correct |
62 |
Correct |
45 ms |
5676 KB |
Output is correct |
63 |
Correct |
55 ms |
5692 KB |
Output is correct |
64 |
Correct |
48 ms |
5652 KB |
Output is correct |
65 |
Correct |
45 ms |
5672 KB |
Output is correct |
66 |
Correct |
48 ms |
5604 KB |
Output is correct |
67 |
Correct |
47 ms |
5780 KB |
Output is correct |
68 |
Correct |
42 ms |
5692 KB |
Output is correct |
69 |
Correct |
44 ms |
5696 KB |
Output is correct |
70 |
Correct |
472 ms |
23748 KB |
Output is correct |
71 |
Correct |
45 ms |
5660 KB |
Output is correct |
72 |
Correct |
418 ms |
23732 KB |
Output is correct |
73 |
Correct |
425 ms |
23568 KB |
Output is correct |
74 |
Correct |
1 ms |
212 KB |
Output is correct |
75 |
Correct |
1 ms |
212 KB |
Output is correct |
76 |
Correct |
1 ms |
320 KB |
Output is correct |
77 |
Correct |
0 ms |
212 KB |
Output is correct |
78 |
Correct |
1 ms |
212 KB |
Output is correct |
79 |
Correct |
6 ms |
1060 KB |
Output is correct |
80 |
Correct |
530 ms |
47852 KB |
Output is correct |
81 |
Correct |
497 ms |
47692 KB |
Output is correct |
82 |
Correct |
496 ms |
47784 KB |
Output is correct |
83 |
Correct |
478 ms |
47824 KB |
Output is correct |
84 |
Correct |
504 ms |
48152 KB |
Output is correct |
85 |
Correct |
497 ms |
48652 KB |
Output is correct |
86 |
Correct |
137 ms |
18472 KB |
Output is correct |
87 |
Correct |
1 ms |
212 KB |
Output is correct |