// FUCKED UP FUCKED UP FUCKED UP FUCKED UP FUCKED UP
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O2,no-stack-protector,unroll-loops,fast-math")
#define F first
#define S second
#define pb push_back
#define SZ(x) (ll)(x.size())
#define all(x) x.begin(),x.end()
#define MP make_pair
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll maxn=1e6+10, maxm=1e6+10, lg=21, mod=998244353, inf=1e18+10;
ll n,A,B,m;
map<ll,ll> ss;
int main(){
ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
cin>>n>>A>>B;
ll g=__gcd(A,B+1);
m=A/g;
if(B>inf/m+10) m=inf;
else m*=B;
while(n--){
ll l,r; cin>>l>>r; r++;
if(r-l>=m) return cout<<m,0;
l%=m, r%=m;
ss[l]++, ss[r]--;
if(l>=r) ss[0]++, ss[m]--;
}
ll ans=0,ls=0,ps=0;
for(auto x:ss){
if(ps) ans+=x.F-ls;
ls=x.F, ps+=x.S;
}
cout<<ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
8 ms |
1292 KB |
Output is correct |
3 |
Correct |
8 ms |
1408 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
7 ms |
1408 KB |
Output is correct |
17 |
Correct |
82 ms |
10364 KB |
Output is correct |
18 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
512 KB |
Output is correct |
3 |
Correct |
1 ms |
512 KB |
Output is correct |
4 |
Correct |
1 ms |
512 KB |
Output is correct |
5 |
Correct |
331 ms |
3704 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
787 ms |
68460 KB |
Output is correct |
3 |
Correct |
806 ms |
68472 KB |
Output is correct |
4 |
Correct |
861 ms |
68592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
787 ms |
68460 KB |
Output is correct |
3 |
Correct |
806 ms |
68472 KB |
Output is correct |
4 |
Correct |
861 ms |
68592 KB |
Output is correct |
5 |
Correct |
0 ms |
388 KB |
Output is correct |
6 |
Correct |
844 ms |
68408 KB |
Output is correct |
7 |
Correct |
865 ms |
68600 KB |
Output is correct |
8 |
Correct |
832 ms |
68476 KB |
Output is correct |
9 |
Correct |
959 ms |
68388 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
787 ms |
68460 KB |
Output is correct |
3 |
Correct |
806 ms |
68472 KB |
Output is correct |
4 |
Correct |
861 ms |
68592 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
75 ms |
10360 KB |
Output is correct |
7 |
Correct |
75 ms |
10360 KB |
Output is correct |
8 |
Correct |
79 ms |
10360 KB |
Output is correct |
9 |
Correct |
87 ms |
10360 KB |
Output is correct |
10 |
Correct |
74 ms |
10304 KB |
Output is correct |
11 |
Correct |
69 ms |
10360 KB |
Output is correct |
12 |
Correct |
80 ms |
10360 KB |
Output is correct |
13 |
Correct |
87 ms |
10360 KB |
Output is correct |
14 |
Correct |
80 ms |
10332 KB |
Output is correct |
15 |
Correct |
89 ms |
10336 KB |
Output is correct |
16 |
Correct |
86 ms |
10276 KB |
Output is correct |
17 |
Correct |
75 ms |
10360 KB |
Output is correct |
18 |
Correct |
1020 ms |
68600 KB |
Output is correct |
19 |
Correct |
828 ms |
68472 KB |
Output is correct |
20 |
Correct |
884 ms |
68476 KB |
Output is correct |
21 |
Correct |
81 ms |
10364 KB |
Output is correct |
22 |
Correct |
75 ms |
10360 KB |
Output is correct |
23 |
Correct |
149 ms |
12920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
87 ms |
10360 KB |
Output is correct |
3 |
Correct |
98 ms |
10400 KB |
Output is correct |
4 |
Correct |
905 ms |
68524 KB |
Output is correct |
5 |
Correct |
85 ms |
10360 KB |
Output is correct |
6 |
Correct |
96 ms |
10360 KB |
Output is correct |
7 |
Correct |
89 ms |
10488 KB |
Output is correct |
8 |
Correct |
79 ms |
10360 KB |
Output is correct |
9 |
Correct |
84 ms |
10360 KB |
Output is correct |
10 |
Correct |
75 ms |
10300 KB |
Output is correct |
11 |
Correct |
84 ms |
10360 KB |
Output is correct |
12 |
Correct |
77 ms |
10360 KB |
Output is correct |
13 |
Correct |
88 ms |
10360 KB |
Output is correct |
14 |
Correct |
889 ms |
68600 KB |
Output is correct |
15 |
Correct |
72 ms |
10360 KB |
Output is correct |
16 |
Correct |
780 ms |
68472 KB |
Output is correct |
17 |
Correct |
770 ms |
68472 KB |
Output is correct |
18 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
8 ms |
1292 KB |
Output is correct |
3 |
Correct |
8 ms |
1408 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
7 ms |
1408 KB |
Output is correct |
17 |
Correct |
82 ms |
10364 KB |
Output is correct |
18 |
Correct |
0 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
0 ms |
384 KB |
Output is correct |
21 |
Correct |
0 ms |
384 KB |
Output is correct |
22 |
Correct |
0 ms |
384 KB |
Output is correct |
23 |
Correct |
0 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
384 KB |
Output is correct |
25 |
Correct |
1 ms |
512 KB |
Output is correct |
26 |
Correct |
1 ms |
512 KB |
Output is correct |
27 |
Correct |
1 ms |
512 KB |
Output is correct |
28 |
Correct |
331 ms |
3704 KB |
Output is correct |
29 |
Correct |
0 ms |
384 KB |
Output is correct |
30 |
Correct |
787 ms |
68460 KB |
Output is correct |
31 |
Correct |
806 ms |
68472 KB |
Output is correct |
32 |
Correct |
861 ms |
68592 KB |
Output is correct |
33 |
Correct |
0 ms |
388 KB |
Output is correct |
34 |
Correct |
844 ms |
68408 KB |
Output is correct |
35 |
Correct |
865 ms |
68600 KB |
Output is correct |
36 |
Correct |
832 ms |
68476 KB |
Output is correct |
37 |
Correct |
959 ms |
68388 KB |
Output is correct |
38 |
Correct |
1 ms |
384 KB |
Output is correct |
39 |
Correct |
75 ms |
10360 KB |
Output is correct |
40 |
Correct |
75 ms |
10360 KB |
Output is correct |
41 |
Correct |
79 ms |
10360 KB |
Output is correct |
42 |
Correct |
87 ms |
10360 KB |
Output is correct |
43 |
Correct |
74 ms |
10304 KB |
Output is correct |
44 |
Correct |
69 ms |
10360 KB |
Output is correct |
45 |
Correct |
80 ms |
10360 KB |
Output is correct |
46 |
Correct |
87 ms |
10360 KB |
Output is correct |
47 |
Correct |
80 ms |
10332 KB |
Output is correct |
48 |
Correct |
89 ms |
10336 KB |
Output is correct |
49 |
Correct |
86 ms |
10276 KB |
Output is correct |
50 |
Correct |
75 ms |
10360 KB |
Output is correct |
51 |
Correct |
1020 ms |
68600 KB |
Output is correct |
52 |
Correct |
828 ms |
68472 KB |
Output is correct |
53 |
Correct |
884 ms |
68476 KB |
Output is correct |
54 |
Correct |
81 ms |
10364 KB |
Output is correct |
55 |
Correct |
75 ms |
10360 KB |
Output is correct |
56 |
Correct |
149 ms |
12920 KB |
Output is correct |
57 |
Correct |
1 ms |
384 KB |
Output is correct |
58 |
Correct |
87 ms |
10360 KB |
Output is correct |
59 |
Correct |
98 ms |
10400 KB |
Output is correct |
60 |
Correct |
905 ms |
68524 KB |
Output is correct |
61 |
Correct |
85 ms |
10360 KB |
Output is correct |
62 |
Correct |
96 ms |
10360 KB |
Output is correct |
63 |
Correct |
89 ms |
10488 KB |
Output is correct |
64 |
Correct |
79 ms |
10360 KB |
Output is correct |
65 |
Correct |
84 ms |
10360 KB |
Output is correct |
66 |
Correct |
75 ms |
10300 KB |
Output is correct |
67 |
Correct |
84 ms |
10360 KB |
Output is correct |
68 |
Correct |
77 ms |
10360 KB |
Output is correct |
69 |
Correct |
88 ms |
10360 KB |
Output is correct |
70 |
Correct |
889 ms |
68600 KB |
Output is correct |
71 |
Correct |
72 ms |
10360 KB |
Output is correct |
72 |
Correct |
780 ms |
68472 KB |
Output is correct |
73 |
Correct |
770 ms |
68472 KB |
Output is correct |
74 |
Correct |
0 ms |
384 KB |
Output is correct |
75 |
Correct |
0 ms |
384 KB |
Output is correct |
76 |
Correct |
0 ms |
384 KB |
Output is correct |
77 |
Correct |
0 ms |
384 KB |
Output is correct |
78 |
Correct |
0 ms |
384 KB |
Output is correct |
79 |
Correct |
8 ms |
1408 KB |
Output is correct |
80 |
Correct |
891 ms |
70908 KB |
Output is correct |
81 |
Correct |
865 ms |
70776 KB |
Output is correct |
82 |
Correct |
888 ms |
70776 KB |
Output is correct |
83 |
Correct |
895 ms |
70904 KB |
Output is correct |
84 |
Correct |
899 ms |
70904 KB |
Output is correct |
85 |
Correct |
840 ms |
70776 KB |
Output is correct |
86 |
Correct |
152 ms |
12792 KB |
Output is correct |
87 |
Correct |
1 ms |
384 KB |
Output is correct |