#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});
}
}
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:56: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]
56 | for (int i = 1 ; i < lst.size() ; i++){
| ~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2384 KB |
Output is correct |
2 |
Correct |
4 ms |
2896 KB |
Output is correct |
3 |
Correct |
4 ms |
2896 KB |
Output is correct |
4 |
Correct |
1 ms |
2384 KB |
Output is correct |
5 |
Correct |
1 ms |
2384 KB |
Output is correct |
6 |
Correct |
1 ms |
2384 KB |
Output is correct |
7 |
Correct |
1 ms |
2384 KB |
Output is correct |
8 |
Correct |
1 ms |
2384 KB |
Output is correct |
9 |
Correct |
1 ms |
2652 KB |
Output is correct |
10 |
Correct |
1 ms |
2384 KB |
Output is correct |
11 |
Correct |
1 ms |
2384 KB |
Output is correct |
12 |
Correct |
1 ms |
2640 KB |
Output is correct |
13 |
Correct |
1 ms |
2384 KB |
Output is correct |
14 |
Correct |
1 ms |
2556 KB |
Output is correct |
15 |
Correct |
1 ms |
2384 KB |
Output is correct |
16 |
Correct |
3 ms |
2896 KB |
Output is correct |
17 |
Correct |
32 ms |
10184 KB |
Output is correct |
18 |
Correct |
1 ms |
2384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2552 KB |
Output is correct |
2 |
Correct |
1 ms |
2384 KB |
Output is correct |
3 |
Correct |
1 ms |
2384 KB |
Output is correct |
4 |
Correct |
1 ms |
2384 KB |
Output is correct |
5 |
Correct |
1 ms |
2384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2384 KB |
Output is correct |
2 |
Correct |
1 ms |
2384 KB |
Output is correct |
3 |
Correct |
1 ms |
2384 KB |
Output is correct |
4 |
Correct |
1 ms |
2384 KB |
Output is correct |
5 |
Correct |
198 ms |
34488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2384 KB |
Output is correct |
2 |
Correct |
274 ms |
34488 KB |
Output is correct |
3 |
Correct |
256 ms |
34552 KB |
Output is correct |
4 |
Correct |
273 ms |
34544 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2384 KB |
Output is correct |
2 |
Correct |
274 ms |
34488 KB |
Output is correct |
3 |
Correct |
256 ms |
34552 KB |
Output is correct |
4 |
Correct |
273 ms |
34544 KB |
Output is correct |
5 |
Correct |
1 ms |
2384 KB |
Output is correct |
6 |
Correct |
258 ms |
34544 KB |
Output is correct |
7 |
Correct |
267 ms |
34496 KB |
Output is correct |
8 |
Correct |
275 ms |
34488 KB |
Output is correct |
9 |
Correct |
303 ms |
34488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2384 KB |
Output is correct |
2 |
Correct |
274 ms |
34488 KB |
Output is correct |
3 |
Correct |
256 ms |
34552 KB |
Output is correct |
4 |
Correct |
273 ms |
34544 KB |
Output is correct |
5 |
Correct |
1 ms |
2552 KB |
Output is correct |
6 |
Correct |
29 ms |
9932 KB |
Output is correct |
7 |
Correct |
32 ms |
9932 KB |
Output is correct |
8 |
Correct |
28 ms |
10008 KB |
Output is correct |
9 |
Correct |
31 ms |
9932 KB |
Output is correct |
10 |
Correct |
29 ms |
9988 KB |
Output is correct |
11 |
Correct |
31 ms |
9924 KB |
Output is correct |
12 |
Correct |
31 ms |
9932 KB |
Output is correct |
13 |
Correct |
32 ms |
9944 KB |
Output is correct |
14 |
Correct |
28 ms |
9932 KB |
Output is correct |
15 |
Correct |
33 ms |
9932 KB |
Output is correct |
16 |
Correct |
33 ms |
9932 KB |
Output is correct |
17 |
Correct |
41 ms |
9984 KB |
Output is correct |
18 |
Correct |
286 ms |
34488 KB |
Output is correct |
19 |
Correct |
265 ms |
34464 KB |
Output is correct |
20 |
Correct |
313 ms |
34488 KB |
Output is correct |
21 |
Correct |
32 ms |
9932 KB |
Output is correct |
22 |
Correct |
29 ms |
9932 KB |
Output is correct |
23 |
Correct |
83 ms |
21180 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2384 KB |
Output is correct |
2 |
Correct |
31 ms |
9932 KB |
Output is correct |
3 |
Correct |
30 ms |
9924 KB |
Output is correct |
4 |
Correct |
325 ms |
34552 KB |
Output is correct |
5 |
Correct |
32 ms |
9924 KB |
Output is correct |
6 |
Correct |
31 ms |
9932 KB |
Output is correct |
7 |
Correct |
31 ms |
9932 KB |
Output is correct |
8 |
Correct |
32 ms |
9924 KB |
Output is correct |
9 |
Correct |
31 ms |
9924 KB |
Output is correct |
10 |
Correct |
31 ms |
9932 KB |
Output is correct |
11 |
Correct |
35 ms |
10004 KB |
Output is correct |
12 |
Correct |
27 ms |
9932 KB |
Output is correct |
13 |
Correct |
32 ms |
9932 KB |
Output is correct |
14 |
Correct |
311 ms |
34488 KB |
Output is correct |
15 |
Correct |
31 ms |
9932 KB |
Output is correct |
16 |
Correct |
290 ms |
34488 KB |
Output is correct |
17 |
Correct |
273 ms |
34544 KB |
Output is correct |
18 |
Correct |
1 ms |
2384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2384 KB |
Output is correct |
2 |
Correct |
4 ms |
2896 KB |
Output is correct |
3 |
Correct |
4 ms |
2896 KB |
Output is correct |
4 |
Correct |
1 ms |
2384 KB |
Output is correct |
5 |
Correct |
1 ms |
2384 KB |
Output is correct |
6 |
Correct |
1 ms |
2384 KB |
Output is correct |
7 |
Correct |
1 ms |
2384 KB |
Output is correct |
8 |
Correct |
1 ms |
2384 KB |
Output is correct |
9 |
Correct |
1 ms |
2652 KB |
Output is correct |
10 |
Correct |
1 ms |
2384 KB |
Output is correct |
11 |
Correct |
1 ms |
2384 KB |
Output is correct |
12 |
Correct |
1 ms |
2640 KB |
Output is correct |
13 |
Correct |
1 ms |
2384 KB |
Output is correct |
14 |
Correct |
1 ms |
2556 KB |
Output is correct |
15 |
Correct |
1 ms |
2384 KB |
Output is correct |
16 |
Correct |
3 ms |
2896 KB |
Output is correct |
17 |
Correct |
32 ms |
10184 KB |
Output is correct |
18 |
Correct |
1 ms |
2384 KB |
Output is correct |
19 |
Correct |
1 ms |
2552 KB |
Output is correct |
20 |
Correct |
1 ms |
2384 KB |
Output is correct |
21 |
Correct |
1 ms |
2384 KB |
Output is correct |
22 |
Correct |
1 ms |
2384 KB |
Output is correct |
23 |
Correct |
1 ms |
2384 KB |
Output is correct |
24 |
Correct |
1 ms |
2384 KB |
Output is correct |
25 |
Correct |
1 ms |
2384 KB |
Output is correct |
26 |
Correct |
1 ms |
2384 KB |
Output is correct |
27 |
Correct |
1 ms |
2384 KB |
Output is correct |
28 |
Correct |
198 ms |
34488 KB |
Output is correct |
29 |
Correct |
1 ms |
2384 KB |
Output is correct |
30 |
Correct |
274 ms |
34488 KB |
Output is correct |
31 |
Correct |
256 ms |
34552 KB |
Output is correct |
32 |
Correct |
273 ms |
34544 KB |
Output is correct |
33 |
Correct |
1 ms |
2384 KB |
Output is correct |
34 |
Correct |
258 ms |
34544 KB |
Output is correct |
35 |
Correct |
267 ms |
34496 KB |
Output is correct |
36 |
Correct |
275 ms |
34488 KB |
Output is correct |
37 |
Correct |
303 ms |
34488 KB |
Output is correct |
38 |
Correct |
1 ms |
2552 KB |
Output is correct |
39 |
Correct |
29 ms |
9932 KB |
Output is correct |
40 |
Correct |
32 ms |
9932 KB |
Output is correct |
41 |
Correct |
28 ms |
10008 KB |
Output is correct |
42 |
Correct |
31 ms |
9932 KB |
Output is correct |
43 |
Correct |
29 ms |
9988 KB |
Output is correct |
44 |
Correct |
31 ms |
9924 KB |
Output is correct |
45 |
Correct |
31 ms |
9932 KB |
Output is correct |
46 |
Correct |
32 ms |
9944 KB |
Output is correct |
47 |
Correct |
28 ms |
9932 KB |
Output is correct |
48 |
Correct |
33 ms |
9932 KB |
Output is correct |
49 |
Correct |
33 ms |
9932 KB |
Output is correct |
50 |
Correct |
41 ms |
9984 KB |
Output is correct |
51 |
Correct |
286 ms |
34488 KB |
Output is correct |
52 |
Correct |
265 ms |
34464 KB |
Output is correct |
53 |
Correct |
313 ms |
34488 KB |
Output is correct |
54 |
Correct |
32 ms |
9932 KB |
Output is correct |
55 |
Correct |
29 ms |
9932 KB |
Output is correct |
56 |
Correct |
83 ms |
21180 KB |
Output is correct |
57 |
Correct |
1 ms |
2384 KB |
Output is correct |
58 |
Correct |
31 ms |
9932 KB |
Output is correct |
59 |
Correct |
30 ms |
9924 KB |
Output is correct |
60 |
Correct |
325 ms |
34552 KB |
Output is correct |
61 |
Correct |
32 ms |
9924 KB |
Output is correct |
62 |
Correct |
31 ms |
9932 KB |
Output is correct |
63 |
Correct |
31 ms |
9932 KB |
Output is correct |
64 |
Correct |
32 ms |
9924 KB |
Output is correct |
65 |
Correct |
31 ms |
9924 KB |
Output is correct |
66 |
Correct |
31 ms |
9932 KB |
Output is correct |
67 |
Correct |
35 ms |
10004 KB |
Output is correct |
68 |
Correct |
27 ms |
9932 KB |
Output is correct |
69 |
Correct |
32 ms |
9932 KB |
Output is correct |
70 |
Correct |
311 ms |
34488 KB |
Output is correct |
71 |
Correct |
31 ms |
9932 KB |
Output is correct |
72 |
Correct |
290 ms |
34488 KB |
Output is correct |
73 |
Correct |
273 ms |
34544 KB |
Output is correct |
74 |
Correct |
1 ms |
2384 KB |
Output is correct |
75 |
Correct |
1 ms |
2384 KB |
Output is correct |
76 |
Correct |
1 ms |
2384 KB |
Output is correct |
77 |
Correct |
1 ms |
2384 KB |
Output is correct |
78 |
Correct |
1 ms |
2384 KB |
Output is correct |
79 |
Correct |
3 ms |
2896 KB |
Output is correct |
80 |
Correct |
330 ms |
34552 KB |
Output is correct |
81 |
Correct |
294 ms |
34488 KB |
Output is correct |
82 |
Correct |
289 ms |
34556 KB |
Output is correct |
83 |
Correct |
301 ms |
34488 KB |
Output is correct |
84 |
Correct |
302 ms |
34488 KB |
Output is correct |
85 |
Correct |
286 ms |
34548 KB |
Output is correct |
86 |
Correct |
78 ms |
21180 KB |
Output is correct |
87 |
Correct |
1 ms |
2384 KB |
Output is correct |