#include<bits/stdc++.h>
#define ll long long
#define ldb long double
#define fi first
#define se second
#define sza(a) (int)a.size()
#define pir pair<int,int>
#define pirll pair<ll,ll>
using namespace std;
const ll inf = 1e18 + 1e17;
const int maxn = 1e6 + 5;
ll l[maxn],r[maxn];
vector <pirll> lst;
void input(int n){
for (int i = 1 ; i <= n ; i++) cin >> l[i] >> r[i];
}
ll get_val(ll A,ll B){
A /= __gcd(A,B + 1);
if (A > inf/B) return inf;
return A * B;
}
void gen_pir(int n,ll T){
for (int i = 1 ; i <= n ; i++){
ll L = l[i],R = r[i];
if (L/T == R/T){
lst.push_back({L % T,R % T});
continue;
}
if (R/T > L/T + 1){
lst.push_back({0,T - 1});
return;
}
ll NL = L + (T - L % T) - 1;
if (NL >= L)
lst.push_back({L % T,NL % T});
ll NR = R - R % T;
lst.push_back({NR % T,R % T});
//L..R
}
}
ll solve(int n,ll T){
gen_pir(n,T);
sort(lst.begin(),lst.end());
ll L = lst[0].fi,R = lst[0].se;
ll res = lst[0].se - lst[0].fi + 1,cur = R;
for (int i = 1 ; i < lst.size() ; i++){
L = lst[i].fi;R = lst[i].se;
if (R > cur) res += R - max(cur + 1,L) + 1;
cur = max(cur,R);
}
return res;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int n;ll A,B;
cin >> n >> A >> B;
input(n);
ll T = get_val(A,B);
cout << solve(n,T);
return 0;
}
Compilation message
strange_device.cpp: In function 'long long int solve(int, long long int)':
strange_device.cpp:57:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
57 | for (int i = 1 ; i < lst.size() ; i++){
| ~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
3 ms |
1372 KB |
Output is correct |
3 |
Correct |
3 ms |
1372 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
1372 KB |
Output is correct |
17 |
Correct |
32 ms |
7720 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
209 ms |
57796 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
289 ms |
69560 KB |
Output is correct |
3 |
Correct |
295 ms |
69900 KB |
Output is correct |
4 |
Correct |
284 ms |
69572 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
289 ms |
69560 KB |
Output is correct |
3 |
Correct |
295 ms |
69900 KB |
Output is correct |
4 |
Correct |
284 ms |
69572 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
316 ms |
69564 KB |
Output is correct |
7 |
Correct |
285 ms |
69472 KB |
Output is correct |
8 |
Correct |
287 ms |
69720 KB |
Output is correct |
9 |
Correct |
333 ms |
69828 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
289 ms |
69560 KB |
Output is correct |
3 |
Correct |
295 ms |
69900 KB |
Output is correct |
4 |
Correct |
284 ms |
69572 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
28 ms |
7884 KB |
Output is correct |
7 |
Correct |
30 ms |
7896 KB |
Output is correct |
8 |
Correct |
28 ms |
7808 KB |
Output is correct |
9 |
Correct |
29 ms |
7888 KB |
Output is correct |
10 |
Correct |
28 ms |
7884 KB |
Output is correct |
11 |
Correct |
29 ms |
7732 KB |
Output is correct |
12 |
Correct |
28 ms |
7756 KB |
Output is correct |
13 |
Correct |
31 ms |
7800 KB |
Output is correct |
14 |
Correct |
28 ms |
7892 KB |
Output is correct |
15 |
Correct |
31 ms |
7888 KB |
Output is correct |
16 |
Correct |
30 ms |
7888 KB |
Output is correct |
17 |
Correct |
29 ms |
7924 KB |
Output is correct |
18 |
Correct |
288 ms |
69992 KB |
Output is correct |
19 |
Correct |
292 ms |
69568 KB |
Output is correct |
20 |
Correct |
332 ms |
69732 KB |
Output is correct |
21 |
Correct |
36 ms |
7736 KB |
Output is correct |
22 |
Correct |
27 ms |
7884 KB |
Output is correct |
23 |
Correct |
84 ms |
26504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
31 ms |
7888 KB |
Output is correct |
3 |
Correct |
31 ms |
7884 KB |
Output is correct |
4 |
Correct |
334 ms |
69580 KB |
Output is correct |
5 |
Correct |
31 ms |
7824 KB |
Output is correct |
6 |
Correct |
31 ms |
7892 KB |
Output is correct |
7 |
Correct |
32 ms |
7920 KB |
Output is correct |
8 |
Correct |
32 ms |
7944 KB |
Output is correct |
9 |
Correct |
37 ms |
7876 KB |
Output is correct |
10 |
Correct |
32 ms |
7832 KB |
Output is correct |
11 |
Correct |
33 ms |
7700 KB |
Output is correct |
12 |
Correct |
29 ms |
7844 KB |
Output is correct |
13 |
Correct |
34 ms |
7720 KB |
Output is correct |
14 |
Correct |
371 ms |
69700 KB |
Output is correct |
15 |
Correct |
30 ms |
7884 KB |
Output is correct |
16 |
Correct |
310 ms |
69680 KB |
Output is correct |
17 |
Correct |
303 ms |
69600 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
3 ms |
1372 KB |
Output is correct |
3 |
Correct |
3 ms |
1372 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
1372 KB |
Output is correct |
17 |
Correct |
32 ms |
7720 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
209 ms |
57796 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
289 ms |
69560 KB |
Output is correct |
31 |
Correct |
295 ms |
69900 KB |
Output is correct |
32 |
Correct |
284 ms |
69572 KB |
Output is correct |
33 |
Correct |
0 ms |
344 KB |
Output is correct |
34 |
Correct |
316 ms |
69564 KB |
Output is correct |
35 |
Correct |
285 ms |
69472 KB |
Output is correct |
36 |
Correct |
287 ms |
69720 KB |
Output is correct |
37 |
Correct |
333 ms |
69828 KB |
Output is correct |
38 |
Correct |
0 ms |
344 KB |
Output is correct |
39 |
Correct |
28 ms |
7884 KB |
Output is correct |
40 |
Correct |
30 ms |
7896 KB |
Output is correct |
41 |
Correct |
28 ms |
7808 KB |
Output is correct |
42 |
Correct |
29 ms |
7888 KB |
Output is correct |
43 |
Correct |
28 ms |
7884 KB |
Output is correct |
44 |
Correct |
29 ms |
7732 KB |
Output is correct |
45 |
Correct |
28 ms |
7756 KB |
Output is correct |
46 |
Correct |
31 ms |
7800 KB |
Output is correct |
47 |
Correct |
28 ms |
7892 KB |
Output is correct |
48 |
Correct |
31 ms |
7888 KB |
Output is correct |
49 |
Correct |
30 ms |
7888 KB |
Output is correct |
50 |
Correct |
29 ms |
7924 KB |
Output is correct |
51 |
Correct |
288 ms |
69992 KB |
Output is correct |
52 |
Correct |
292 ms |
69568 KB |
Output is correct |
53 |
Correct |
332 ms |
69732 KB |
Output is correct |
54 |
Correct |
36 ms |
7736 KB |
Output is correct |
55 |
Correct |
27 ms |
7884 KB |
Output is correct |
56 |
Correct |
84 ms |
26504 KB |
Output is correct |
57 |
Correct |
0 ms |
344 KB |
Output is correct |
58 |
Correct |
31 ms |
7888 KB |
Output is correct |
59 |
Correct |
31 ms |
7884 KB |
Output is correct |
60 |
Correct |
334 ms |
69580 KB |
Output is correct |
61 |
Correct |
31 ms |
7824 KB |
Output is correct |
62 |
Correct |
31 ms |
7892 KB |
Output is correct |
63 |
Correct |
32 ms |
7920 KB |
Output is correct |
64 |
Correct |
32 ms |
7944 KB |
Output is correct |
65 |
Correct |
37 ms |
7876 KB |
Output is correct |
66 |
Correct |
32 ms |
7832 KB |
Output is correct |
67 |
Correct |
33 ms |
7700 KB |
Output is correct |
68 |
Correct |
29 ms |
7844 KB |
Output is correct |
69 |
Correct |
34 ms |
7720 KB |
Output is correct |
70 |
Correct |
371 ms |
69700 KB |
Output is correct |
71 |
Correct |
30 ms |
7884 KB |
Output is correct |
72 |
Correct |
310 ms |
69680 KB |
Output is correct |
73 |
Correct |
303 ms |
69600 KB |
Output is correct |
74 |
Correct |
0 ms |
348 KB |
Output is correct |
75 |
Correct |
1 ms |
344 KB |
Output is correct |
76 |
Correct |
0 ms |
348 KB |
Output is correct |
77 |
Correct |
0 ms |
464 KB |
Output is correct |
78 |
Correct |
0 ms |
348 KB |
Output is correct |
79 |
Correct |
4 ms |
1372 KB |
Output is correct |
80 |
Correct |
355 ms |
69672 KB |
Output is correct |
81 |
Correct |
366 ms |
69696 KB |
Output is correct |
82 |
Correct |
328 ms |
69776 KB |
Output is correct |
83 |
Correct |
324 ms |
69904 KB |
Output is correct |
84 |
Correct |
391 ms |
69716 KB |
Output is correct |
85 |
Correct |
389 ms |
69820 KB |
Output is correct |
86 |
Correct |
124 ms |
26564 KB |
Output is correct |
87 |
Correct |
0 ms |
348 KB |
Output is correct |