#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long double ld;
typedef pair<ll, ll> pll;
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define ROF(i, a, b) for(int i = a; i >= b; i--)
#define ms memset
#define pb push_back
#define F first
#define S second
ll MOD = 1000000007;
ll INF = 1000000000;
ll power(ll base, ll n){
if (n == 0) return 1;
if (n == 1) return base;
ll halfn = power(base, n/2);
if (n % 2 == 0) return (halfn * halfn) % MOD;
return (((halfn * halfn) % MOD) * base) % MOD;
}
ll inverse(ll n){
return power(n, MOD-2);
}
ll add(ll a, ll b){
return (a+b) % MOD;
}
ll mul(ll a, ll b){
return (a*b) % MOD;
}
ll gcd(ll a, ll b){
if (a == 0) return b;
if (a == 1) return 1;
return gcd(b%a, a);
}
int check(ll n){
ll m = n;
int cnt = 0;
while (m > 0){
m /= 2;
cnt++;
}
return cnt;
}
ll len = MOD*MOD;
int main(){
ios::sync_with_stdio(false);
int n; cin >> n;
ll a, b; cin >> a >> b;
ll c = a / gcd(a, b+1);
if (check(b) + check(c) < 63){
len = b*c;
}
vector<pll> range;
FOR(i, 0, n){
ll l, r; cin >> l >> r;
if (r - l + 1 > len){
cout << len << '\n';
return 0;
}
l%=len; r%=len;
if (l > r){
range.pb({0, r%len});
range.pb({l%len, len-1});
}else{
range.pb({l, r});
}
}
sort(range.begin(), range.end());
ll ans = 0;
ll l = range[0].F; ll r = range[0].S;
FOR(i, 0, range.size()){
if (range[i].F - r > 1){
ans += r - l + 1;
l = range[i].F; r = range[i].S;
continue;
}
r = max(range[i].S, r);
}
ans += r - l + 1;
cout << ans << '\n';
}
Compilation message
strange_device.cpp: In function 'int main()':
strange_device.cpp:9:39: 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]
9 | #define FOR(i, a, b) for(int i = a; i < b; i++)
......
80 | FOR(i, 0, range.size()){
| ~~~~~~~~~~~~~~~~~~
strange_device.cpp:80:2: note: in expansion of macro 'FOR'
80 | FOR(i, 0, range.size()){
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
6 ms |
976 KB |
Output is correct |
3 |
Correct |
6 ms |
984 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
308 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
308 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
6 ms |
980 KB |
Output is correct |
17 |
Correct |
55 ms |
3232 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
324 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
368 KB |
Output is correct |
5 |
Correct |
373 ms |
17736 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
501 ms |
17060 KB |
Output is correct |
3 |
Correct |
516 ms |
17444 KB |
Output is correct |
4 |
Correct |
478 ms |
17448 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
501 ms |
17060 KB |
Output is correct |
3 |
Correct |
516 ms |
17444 KB |
Output is correct |
4 |
Correct |
478 ms |
17448 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
490 ms |
17468 KB |
Output is correct |
7 |
Correct |
522 ms |
18008 KB |
Output is correct |
8 |
Correct |
485 ms |
18100 KB |
Output is correct |
9 |
Correct |
522 ms |
18092 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
501 ms |
17060 KB |
Output is correct |
3 |
Correct |
516 ms |
17444 KB |
Output is correct |
4 |
Correct |
478 ms |
17448 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
64 ms |
2892 KB |
Output is correct |
7 |
Correct |
52 ms |
3008 KB |
Output is correct |
8 |
Correct |
70 ms |
2896 KB |
Output is correct |
9 |
Correct |
62 ms |
3004 KB |
Output is correct |
10 |
Correct |
49 ms |
2916 KB |
Output is correct |
11 |
Correct |
50 ms |
2984 KB |
Output is correct |
12 |
Correct |
48 ms |
2908 KB |
Output is correct |
13 |
Correct |
59 ms |
2880 KB |
Output is correct |
14 |
Correct |
49 ms |
2928 KB |
Output is correct |
15 |
Correct |
53 ms |
2944 KB |
Output is correct |
16 |
Correct |
53 ms |
2932 KB |
Output is correct |
17 |
Correct |
49 ms |
2896 KB |
Output is correct |
18 |
Correct |
500 ms |
17568 KB |
Output is correct |
19 |
Correct |
476 ms |
16772 KB |
Output is correct |
20 |
Correct |
564 ms |
16888 KB |
Output is correct |
21 |
Correct |
53 ms |
3008 KB |
Output is correct |
22 |
Correct |
49 ms |
3004 KB |
Output is correct |
23 |
Correct |
159 ms |
9208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
52 ms |
3188 KB |
Output is correct |
3 |
Correct |
54 ms |
3128 KB |
Output is correct |
4 |
Correct |
559 ms |
16916 KB |
Output is correct |
5 |
Correct |
52 ms |
3132 KB |
Output is correct |
6 |
Correct |
52 ms |
3224 KB |
Output is correct |
7 |
Correct |
56 ms |
3188 KB |
Output is correct |
8 |
Correct |
52 ms |
3136 KB |
Output is correct |
9 |
Correct |
51 ms |
3128 KB |
Output is correct |
10 |
Correct |
52 ms |
3280 KB |
Output is correct |
11 |
Correct |
54 ms |
3040 KB |
Output is correct |
12 |
Correct |
48 ms |
3036 KB |
Output is correct |
13 |
Correct |
53 ms |
3264 KB |
Output is correct |
14 |
Correct |
523 ms |
16968 KB |
Output is correct |
15 |
Correct |
53 ms |
3000 KB |
Output is correct |
16 |
Correct |
500 ms |
16816 KB |
Output is correct |
17 |
Correct |
490 ms |
16872 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
6 ms |
976 KB |
Output is correct |
3 |
Correct |
6 ms |
984 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
308 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
308 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
6 ms |
980 KB |
Output is correct |
17 |
Correct |
55 ms |
3232 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
1 ms |
204 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
1 ms |
324 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
368 KB |
Output is correct |
28 |
Correct |
373 ms |
17736 KB |
Output is correct |
29 |
Correct |
1 ms |
204 KB |
Output is correct |
30 |
Correct |
501 ms |
17060 KB |
Output is correct |
31 |
Correct |
516 ms |
17444 KB |
Output is correct |
32 |
Correct |
478 ms |
17448 KB |
Output is correct |
33 |
Correct |
1 ms |
204 KB |
Output is correct |
34 |
Correct |
490 ms |
17468 KB |
Output is correct |
35 |
Correct |
522 ms |
18008 KB |
Output is correct |
36 |
Correct |
485 ms |
18100 KB |
Output is correct |
37 |
Correct |
522 ms |
18092 KB |
Output is correct |
38 |
Correct |
1 ms |
204 KB |
Output is correct |
39 |
Correct |
64 ms |
2892 KB |
Output is correct |
40 |
Correct |
52 ms |
3008 KB |
Output is correct |
41 |
Correct |
70 ms |
2896 KB |
Output is correct |
42 |
Correct |
62 ms |
3004 KB |
Output is correct |
43 |
Correct |
49 ms |
2916 KB |
Output is correct |
44 |
Correct |
50 ms |
2984 KB |
Output is correct |
45 |
Correct |
48 ms |
2908 KB |
Output is correct |
46 |
Correct |
59 ms |
2880 KB |
Output is correct |
47 |
Correct |
49 ms |
2928 KB |
Output is correct |
48 |
Correct |
53 ms |
2944 KB |
Output is correct |
49 |
Correct |
53 ms |
2932 KB |
Output is correct |
50 |
Correct |
49 ms |
2896 KB |
Output is correct |
51 |
Correct |
500 ms |
17568 KB |
Output is correct |
52 |
Correct |
476 ms |
16772 KB |
Output is correct |
53 |
Correct |
564 ms |
16888 KB |
Output is correct |
54 |
Correct |
53 ms |
3008 KB |
Output is correct |
55 |
Correct |
49 ms |
3004 KB |
Output is correct |
56 |
Correct |
159 ms |
9208 KB |
Output is correct |
57 |
Correct |
1 ms |
204 KB |
Output is correct |
58 |
Correct |
52 ms |
3188 KB |
Output is correct |
59 |
Correct |
54 ms |
3128 KB |
Output is correct |
60 |
Correct |
559 ms |
16916 KB |
Output is correct |
61 |
Correct |
52 ms |
3132 KB |
Output is correct |
62 |
Correct |
52 ms |
3224 KB |
Output is correct |
63 |
Correct |
56 ms |
3188 KB |
Output is correct |
64 |
Correct |
52 ms |
3136 KB |
Output is correct |
65 |
Correct |
51 ms |
3128 KB |
Output is correct |
66 |
Correct |
52 ms |
3280 KB |
Output is correct |
67 |
Correct |
54 ms |
3040 KB |
Output is correct |
68 |
Correct |
48 ms |
3036 KB |
Output is correct |
69 |
Correct |
53 ms |
3264 KB |
Output is correct |
70 |
Correct |
523 ms |
16968 KB |
Output is correct |
71 |
Correct |
53 ms |
3000 KB |
Output is correct |
72 |
Correct |
500 ms |
16816 KB |
Output is correct |
73 |
Correct |
490 ms |
16872 KB |
Output is correct |
74 |
Correct |
1 ms |
204 KB |
Output is correct |
75 |
Correct |
1 ms |
204 KB |
Output is correct |
76 |
Correct |
1 ms |
204 KB |
Output is correct |
77 |
Correct |
1 ms |
312 KB |
Output is correct |
78 |
Correct |
1 ms |
204 KB |
Output is correct |
79 |
Correct |
6 ms |
1076 KB |
Output is correct |
80 |
Correct |
565 ms |
18356 KB |
Output is correct |
81 |
Correct |
587 ms |
18340 KB |
Output is correct |
82 |
Correct |
532 ms |
18284 KB |
Output is correct |
83 |
Correct |
525 ms |
18152 KB |
Output is correct |
84 |
Correct |
541 ms |
18768 KB |
Output is correct |
85 |
Correct |
525 ms |
18596 KB |
Output is correct |
86 |
Correct |
156 ms |
18420 KB |
Output is correct |
87 |
Correct |
1 ms |
204 KB |
Output is correct |