#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (int)(a.size())
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD (ll)(1e9+7)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
ll gcd(ll A,ll B) {if(!B)return A;return gcd(B,A%B);}
int main()
{
ll n,a,b;
cin>>n>>a>>b;
ll C = a/gcd(a,b+1) > INF/b?INF+1:(a/gcd(a,b+1))*b;
// cout<<C<<'\n';
vector<PII>s;
for(int i=0;i<n;i++){
ll l,r;
cin>>l>>r;
if(r-l+1 > C){cout<<C;return 0;}
l%=C;
r%=C;
if(r >= l){
s.pb({l,r});
}else{
s.pb({l,C-1});
s.pb({0,r});
}
}
sort(all(s));
ll ans = 0;
ll lf = 0;
ll rg = -1;
for(int i=0;i<sz(s);i++){
//cout<<s[i].fi<<" "<<s[i].se<<'\n';
if(s[i].fi > rg){
ans+=rg-lf+1;
lf = s[i].fi;
rg = s[i].se;
if(i == sz(s)-1)ans+=rg-lf+1;
}else{
rg = max(rg,s[i].se);
if(i == sz(s)-1)ans+=rg-lf+1;
}
//cout<<ans<<'\n';
}
cout<<ans<<'\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
15 ms |
748 KB |
Output is correct |
3 |
Correct |
15 ms |
748 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
0 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
0 ms |
364 KB |
Output is correct |
11 |
Correct |
0 ms |
364 KB |
Output is correct |
12 |
Correct |
0 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
17 ms |
764 KB |
Output is correct |
17 |
Correct |
154 ms |
2528 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
3 ms |
364 KB |
Output is correct |
3 |
Correct |
2 ms |
364 KB |
Output is correct |
4 |
Correct |
3 ms |
364 KB |
Output is correct |
5 |
Correct |
1066 ms |
16956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
1463 ms |
17084 KB |
Output is correct |
3 |
Correct |
1461 ms |
16896 KB |
Output is correct |
4 |
Correct |
1439 ms |
17160 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
1463 ms |
17084 KB |
Output is correct |
3 |
Correct |
1461 ms |
16896 KB |
Output is correct |
4 |
Correct |
1439 ms |
17160 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1445 ms |
17252 KB |
Output is correct |
7 |
Correct |
1459 ms |
16968 KB |
Output is correct |
8 |
Correct |
1451 ms |
17104 KB |
Output is correct |
9 |
Correct |
1490 ms |
16976 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
1463 ms |
17084 KB |
Output is correct |
3 |
Correct |
1461 ms |
16896 KB |
Output is correct |
4 |
Correct |
1439 ms |
17160 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
154 ms |
2560 KB |
Output is correct |
7 |
Correct |
147 ms |
2528 KB |
Output is correct |
8 |
Correct |
146 ms |
2528 KB |
Output is correct |
9 |
Correct |
148 ms |
2700 KB |
Output is correct |
10 |
Correct |
144 ms |
2528 KB |
Output is correct |
11 |
Correct |
147 ms |
2528 KB |
Output is correct |
12 |
Correct |
142 ms |
2528 KB |
Output is correct |
13 |
Correct |
147 ms |
2528 KB |
Output is correct |
14 |
Correct |
144 ms |
2528 KB |
Output is correct |
15 |
Correct |
149 ms |
2528 KB |
Output is correct |
16 |
Correct |
149 ms |
2528 KB |
Output is correct |
17 |
Correct |
147 ms |
2528 KB |
Output is correct |
18 |
Correct |
1454 ms |
16968 KB |
Output is correct |
19 |
Correct |
1442 ms |
16968 KB |
Output is correct |
20 |
Correct |
1503 ms |
17076 KB |
Output is correct |
21 |
Correct |
149 ms |
2656 KB |
Output is correct |
22 |
Correct |
143 ms |
2528 KB |
Output is correct |
23 |
Correct |
485 ms |
8796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
147 ms |
2528 KB |
Output is correct |
3 |
Correct |
147 ms |
2528 KB |
Output is correct |
4 |
Correct |
1534 ms |
16956 KB |
Output is correct |
5 |
Correct |
147 ms |
2528 KB |
Output is correct |
6 |
Correct |
148 ms |
2528 KB |
Output is correct |
7 |
Correct |
148 ms |
2528 KB |
Output is correct |
8 |
Correct |
148 ms |
2528 KB |
Output is correct |
9 |
Correct |
147 ms |
2712 KB |
Output is correct |
10 |
Correct |
149 ms |
2528 KB |
Output is correct |
11 |
Correct |
150 ms |
2528 KB |
Output is correct |
12 |
Correct |
144 ms |
2656 KB |
Output is correct |
13 |
Correct |
156 ms |
2528 KB |
Output is correct |
14 |
Correct |
1496 ms |
16968 KB |
Output is correct |
15 |
Correct |
147 ms |
2528 KB |
Output is correct |
16 |
Correct |
1498 ms |
16904 KB |
Output is correct |
17 |
Correct |
1451 ms |
17116 KB |
Output is correct |
18 |
Correct |
0 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
15 ms |
748 KB |
Output is correct |
3 |
Correct |
15 ms |
748 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
0 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
0 ms |
364 KB |
Output is correct |
11 |
Correct |
0 ms |
364 KB |
Output is correct |
12 |
Correct |
0 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
17 ms |
764 KB |
Output is correct |
17 |
Correct |
154 ms |
2528 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
0 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
492 KB |
Output is correct |
25 |
Correct |
3 ms |
364 KB |
Output is correct |
26 |
Correct |
2 ms |
364 KB |
Output is correct |
27 |
Correct |
3 ms |
364 KB |
Output is correct |
28 |
Correct |
1066 ms |
16956 KB |
Output is correct |
29 |
Correct |
0 ms |
364 KB |
Output is correct |
30 |
Correct |
1463 ms |
17084 KB |
Output is correct |
31 |
Correct |
1461 ms |
16896 KB |
Output is correct |
32 |
Correct |
1439 ms |
17160 KB |
Output is correct |
33 |
Correct |
1 ms |
364 KB |
Output is correct |
34 |
Correct |
1445 ms |
17252 KB |
Output is correct |
35 |
Correct |
1459 ms |
16968 KB |
Output is correct |
36 |
Correct |
1451 ms |
17104 KB |
Output is correct |
37 |
Correct |
1490 ms |
16976 KB |
Output is correct |
38 |
Correct |
1 ms |
364 KB |
Output is correct |
39 |
Correct |
154 ms |
2560 KB |
Output is correct |
40 |
Correct |
147 ms |
2528 KB |
Output is correct |
41 |
Correct |
146 ms |
2528 KB |
Output is correct |
42 |
Correct |
148 ms |
2700 KB |
Output is correct |
43 |
Correct |
144 ms |
2528 KB |
Output is correct |
44 |
Correct |
147 ms |
2528 KB |
Output is correct |
45 |
Correct |
142 ms |
2528 KB |
Output is correct |
46 |
Correct |
147 ms |
2528 KB |
Output is correct |
47 |
Correct |
144 ms |
2528 KB |
Output is correct |
48 |
Correct |
149 ms |
2528 KB |
Output is correct |
49 |
Correct |
149 ms |
2528 KB |
Output is correct |
50 |
Correct |
147 ms |
2528 KB |
Output is correct |
51 |
Correct |
1454 ms |
16968 KB |
Output is correct |
52 |
Correct |
1442 ms |
16968 KB |
Output is correct |
53 |
Correct |
1503 ms |
17076 KB |
Output is correct |
54 |
Correct |
149 ms |
2656 KB |
Output is correct |
55 |
Correct |
143 ms |
2528 KB |
Output is correct |
56 |
Correct |
485 ms |
8796 KB |
Output is correct |
57 |
Correct |
1 ms |
364 KB |
Output is correct |
58 |
Correct |
147 ms |
2528 KB |
Output is correct |
59 |
Correct |
147 ms |
2528 KB |
Output is correct |
60 |
Correct |
1534 ms |
16956 KB |
Output is correct |
61 |
Correct |
147 ms |
2528 KB |
Output is correct |
62 |
Correct |
148 ms |
2528 KB |
Output is correct |
63 |
Correct |
148 ms |
2528 KB |
Output is correct |
64 |
Correct |
148 ms |
2528 KB |
Output is correct |
65 |
Correct |
147 ms |
2712 KB |
Output is correct |
66 |
Correct |
149 ms |
2528 KB |
Output is correct |
67 |
Correct |
150 ms |
2528 KB |
Output is correct |
68 |
Correct |
144 ms |
2656 KB |
Output is correct |
69 |
Correct |
156 ms |
2528 KB |
Output is correct |
70 |
Correct |
1496 ms |
16968 KB |
Output is correct |
71 |
Correct |
147 ms |
2528 KB |
Output is correct |
72 |
Correct |
1498 ms |
16904 KB |
Output is correct |
73 |
Correct |
1451 ms |
17116 KB |
Output is correct |
74 |
Correct |
0 ms |
364 KB |
Output is correct |
75 |
Correct |
1 ms |
364 KB |
Output is correct |
76 |
Correct |
1 ms |
316 KB |
Output is correct |
77 |
Correct |
1 ms |
364 KB |
Output is correct |
78 |
Correct |
1 ms |
364 KB |
Output is correct |
79 |
Correct |
18 ms |
1132 KB |
Output is correct |
80 |
Correct |
1543 ms |
53452 KB |
Output is correct |
81 |
Correct |
1546 ms |
53468 KB |
Output is correct |
82 |
Correct |
1500 ms |
53748 KB |
Output is correct |
83 |
Correct |
1503 ms |
53572 KB |
Output is correct |
84 |
Correct |
1509 ms |
53592 KB |
Output is correct |
85 |
Correct |
1516 ms |
53564 KB |
Output is correct |
86 |
Correct |
486 ms |
18644 KB |
Output is correct |
87 |
Correct |
1 ms |
364 KB |
Output is correct |