/* made by amunduzbaev */
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(),x.rend()
#define NeedForSpeed ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define vv vector
#define tut(x) array<int, x>
#define int long long
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vii;
typedef vector<pii> vpii;
template<class T> bool umin(T& a, const T& b) { return a > b? a = b, true:false; }
template<class T> bool umax(T& a, const T& b) { return a < b? a = b, true:false; }
//void usaco(string s) { freopen((s+".in").c_str(),"r",stdin);
//freopen((s+".out").c_str(),"w",stdout); }
//template<class T> tree<T,
//less<T>, null_type, rb_tree_tag,
//tree_order_statistics_node_update> ordered_set;
const int N = 1e6+5;
const int mod = 1e9+7;
const ll inf = 1e18;
const ld Pi = acos(-1);
#define MULTI 0
int n, m, K, s, ans, q, res, a;
int b, l[N], r[N];
bool cmp(pii a, pii b){
if(a.ff != b.ff) return a.ff < b.ff;
else return a.ss > b.ss;
}
void solve(int t_case){
cin>>n>>a>>b;
int cyc = a / __gcd(a, b+1);
if(cyc > inf / b) cyc = inf;
else cyc = cyc * b;
vpii tt;
for(int i=0;i<n;i++){
cin>>l[i]>>r[i];
if(r[i] - l[i] + 1 >= cyc){
cout<<cyc<<"\n";
return;
}
int lx = l[i] % cyc, rx = r[i] % cyc;
if(lx <= rx) tt.pb({lx, rx});
else tt.pb({lx, cyc - 1}), tt.pb({0, rx});
}
sort(all(tt));
int lx = -1, rx = -1;
for(auto x : tt){
if(x.ff > rx){
if(~lx && ~rx) res += (rx - lx + 1);
lx = x.ff, rx = x.ss;
} else umax(rx, x.ss);
}
if(~lx && ~rx) res += (rx - lx + 1);
cout<<res<<"\n";
}
signed main(){
NeedForSpeed
if(!MULTI) {
solve(1);
} else {
int t; cin>>t;
for(int t_case = 1; t_case <= t; t_case++) solve(t_case);
} return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
6 ms |
1096 KB |
Output is correct |
3 |
Correct |
6 ms |
1176 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
324 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
324 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
5 ms |
1228 KB |
Output is correct |
17 |
Correct |
52 ms |
7308 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
324 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
361 ms |
57072 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
486 ms |
68956 KB |
Output is correct |
3 |
Correct |
474 ms |
68880 KB |
Output is correct |
4 |
Correct |
471 ms |
68960 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
486 ms |
68956 KB |
Output is correct |
3 |
Correct |
474 ms |
68880 KB |
Output is correct |
4 |
Correct |
471 ms |
68960 KB |
Output is correct |
5 |
Correct |
1 ms |
324 KB |
Output is correct |
6 |
Correct |
473 ms |
68876 KB |
Output is correct |
7 |
Correct |
485 ms |
69028 KB |
Output is correct |
8 |
Correct |
479 ms |
68860 KB |
Output is correct |
9 |
Correct |
518 ms |
68876 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
486 ms |
68956 KB |
Output is correct |
3 |
Correct |
474 ms |
68880 KB |
Output is correct |
4 |
Correct |
471 ms |
68960 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
50 ms |
7312 KB |
Output is correct |
7 |
Correct |
49 ms |
7284 KB |
Output is correct |
8 |
Correct |
51 ms |
7312 KB |
Output is correct |
9 |
Correct |
49 ms |
7228 KB |
Output is correct |
10 |
Correct |
48 ms |
7200 KB |
Output is correct |
11 |
Correct |
48 ms |
7228 KB |
Output is correct |
12 |
Correct |
46 ms |
7228 KB |
Output is correct |
13 |
Correct |
50 ms |
7240 KB |
Output is correct |
14 |
Correct |
47 ms |
7356 KB |
Output is correct |
15 |
Correct |
50 ms |
7204 KB |
Output is correct |
16 |
Correct |
50 ms |
7248 KB |
Output is correct |
17 |
Correct |
48 ms |
7224 KB |
Output is correct |
18 |
Correct |
490 ms |
68844 KB |
Output is correct |
19 |
Correct |
470 ms |
68924 KB |
Output is correct |
20 |
Correct |
526 ms |
68960 KB |
Output is correct |
21 |
Correct |
50 ms |
7296 KB |
Output is correct |
22 |
Correct |
45 ms |
7280 KB |
Output is correct |
23 |
Correct |
147 ms |
23820 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
53 ms |
7212 KB |
Output is correct |
3 |
Correct |
49 ms |
7208 KB |
Output is correct |
4 |
Correct |
554 ms |
68916 KB |
Output is correct |
5 |
Correct |
49 ms |
7228 KB |
Output is correct |
6 |
Correct |
49 ms |
7236 KB |
Output is correct |
7 |
Correct |
49 ms |
7228 KB |
Output is correct |
8 |
Correct |
50 ms |
7224 KB |
Output is correct |
9 |
Correct |
48 ms |
7224 KB |
Output is correct |
10 |
Correct |
50 ms |
7324 KB |
Output is correct |
11 |
Correct |
51 ms |
7260 KB |
Output is correct |
12 |
Correct |
44 ms |
7284 KB |
Output is correct |
13 |
Correct |
49 ms |
7244 KB |
Output is correct |
14 |
Correct |
635 ms |
68880 KB |
Output is correct |
15 |
Correct |
49 ms |
7228 KB |
Output is correct |
16 |
Correct |
480 ms |
68896 KB |
Output is correct |
17 |
Correct |
475 ms |
69076 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
6 ms |
1096 KB |
Output is correct |
3 |
Correct |
6 ms |
1176 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
324 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
324 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
5 ms |
1228 KB |
Output is correct |
17 |
Correct |
52 ms |
7308 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
324 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
336 KB |
Output is correct |
28 |
Correct |
361 ms |
57072 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
Correct |
486 ms |
68956 KB |
Output is correct |
31 |
Correct |
474 ms |
68880 KB |
Output is correct |
32 |
Correct |
471 ms |
68960 KB |
Output is correct |
33 |
Correct |
1 ms |
324 KB |
Output is correct |
34 |
Correct |
473 ms |
68876 KB |
Output is correct |
35 |
Correct |
485 ms |
69028 KB |
Output is correct |
36 |
Correct |
479 ms |
68860 KB |
Output is correct |
37 |
Correct |
518 ms |
68876 KB |
Output is correct |
38 |
Correct |
1 ms |
332 KB |
Output is correct |
39 |
Correct |
50 ms |
7312 KB |
Output is correct |
40 |
Correct |
49 ms |
7284 KB |
Output is correct |
41 |
Correct |
51 ms |
7312 KB |
Output is correct |
42 |
Correct |
49 ms |
7228 KB |
Output is correct |
43 |
Correct |
48 ms |
7200 KB |
Output is correct |
44 |
Correct |
48 ms |
7228 KB |
Output is correct |
45 |
Correct |
46 ms |
7228 KB |
Output is correct |
46 |
Correct |
50 ms |
7240 KB |
Output is correct |
47 |
Correct |
47 ms |
7356 KB |
Output is correct |
48 |
Correct |
50 ms |
7204 KB |
Output is correct |
49 |
Correct |
50 ms |
7248 KB |
Output is correct |
50 |
Correct |
48 ms |
7224 KB |
Output is correct |
51 |
Correct |
490 ms |
68844 KB |
Output is correct |
52 |
Correct |
470 ms |
68924 KB |
Output is correct |
53 |
Correct |
526 ms |
68960 KB |
Output is correct |
54 |
Correct |
50 ms |
7296 KB |
Output is correct |
55 |
Correct |
45 ms |
7280 KB |
Output is correct |
56 |
Correct |
147 ms |
23820 KB |
Output is correct |
57 |
Correct |
1 ms |
332 KB |
Output is correct |
58 |
Correct |
53 ms |
7212 KB |
Output is correct |
59 |
Correct |
49 ms |
7208 KB |
Output is correct |
60 |
Correct |
554 ms |
68916 KB |
Output is correct |
61 |
Correct |
49 ms |
7228 KB |
Output is correct |
62 |
Correct |
49 ms |
7236 KB |
Output is correct |
63 |
Correct |
49 ms |
7228 KB |
Output is correct |
64 |
Correct |
50 ms |
7224 KB |
Output is correct |
65 |
Correct |
48 ms |
7224 KB |
Output is correct |
66 |
Correct |
50 ms |
7324 KB |
Output is correct |
67 |
Correct |
51 ms |
7260 KB |
Output is correct |
68 |
Correct |
44 ms |
7284 KB |
Output is correct |
69 |
Correct |
49 ms |
7244 KB |
Output is correct |
70 |
Correct |
635 ms |
68880 KB |
Output is correct |
71 |
Correct |
49 ms |
7228 KB |
Output is correct |
72 |
Correct |
480 ms |
68896 KB |
Output is correct |
73 |
Correct |
475 ms |
69076 KB |
Output is correct |
74 |
Correct |
1 ms |
332 KB |
Output is correct |
75 |
Correct |
1 ms |
332 KB |
Output is correct |
76 |
Correct |
1 ms |
332 KB |
Output is correct |
77 |
Correct |
1 ms |
204 KB |
Output is correct |
78 |
Correct |
1 ms |
204 KB |
Output is correct |
79 |
Correct |
5 ms |
1228 KB |
Output is correct |
80 |
Correct |
542 ms |
68880 KB |
Output is correct |
81 |
Correct |
546 ms |
68948 KB |
Output is correct |
82 |
Correct |
523 ms |
68880 KB |
Output is correct |
83 |
Correct |
504 ms |
68948 KB |
Output is correct |
84 |
Correct |
525 ms |
68880 KB |
Output is correct |
85 |
Correct |
513 ms |
68860 KB |
Output is correct |
86 |
Correct |
146 ms |
23848 KB |
Output is correct |
87 |
Correct |
1 ms |
332 KB |
Output is correct |