#include<bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
#define int ll
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define pb push_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define mispertion ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define F first
#define S second
#define getlast(s) (*s.rbegin())
#define debg cout << "OK\n"
const ld PI = 3.1415926535;
const int N = 1e6 + 1;
const int M = 50 + 1;
const int mod = 1e9+7;
const int infi = INT_MAX;
const ll infl = LLONG_MAX;
const int P = 31;
int mult(int a, int b) {
return a * 1LL * b % mod;
}
int sum(int a, int b) {
if (a + b < 0)
return a + b + mod;
if (a + b >= mod)
return a + b - mod;
return a + b;
}
ll binpow(ll a, ll n) {
if (n == 0)
return 1;
if (n % 2 == 1) {
return binpow(a, n - 1) * a % mod;
} else {
ll b = binpow(a, n / 2);
return b * b % mod;
}
}
int n, A, B;
map<int, int> mp;
void solve(){
cin >> n >> A >> B;
int x = A / __gcd(A, B + 1), y = B;
if(x >= infl / y){
int ans = 0;
for(int i = 1; i <= n; i++){
int l, r;
cin >> l >> r;
ans += (r - l + 1);
}
cout << ans << '\n';
return;
}
int ccl = x * y;
for(int i = 1; i <= n; i++){
int l, r;
cin >> l >> r;
if(r - l + 1 >= ccl){
mp[0]++;
mp[ccl]--;
}else{
if(l % ccl <= r % ccl){
mp[l % ccl]++;
mp[r % ccl + 1]--;
}else{
mp[l % ccl]++;
mp[ccl]--;
mp[0]++;
mp[r % ccl + 1]--;
}
}
}
int cur = 0, ans = 0;
for(auto it = mp.begin(); it != (--mp.end()); it++){
auto it1 = it;
it1++;
cur += it->S;
if(cur != 0)
ans += (it1->F - it->F);
}
cout << ans << '\n';
}
signed main() {
mispertion;
int t = 1;
//cin >> t;
while(t--){
solve();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
5 ms |
1372 KB |
Output is correct |
3 |
Correct |
5 ms |
1372 KB |
Output is correct |
4 |
Correct |
1 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 |
460 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
456 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
4 ms |
1372 KB |
Output is correct |
17 |
Correct |
49 ms |
10276 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
181 ms |
22996 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
493 ms |
95684 KB |
Output is correct |
3 |
Correct |
506 ms |
95724 KB |
Output is correct |
4 |
Correct |
627 ms |
95824 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
493 ms |
95684 KB |
Output is correct |
3 |
Correct |
506 ms |
95724 KB |
Output is correct |
4 |
Correct |
627 ms |
95824 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
529 ms |
95696 KB |
Output is correct |
7 |
Correct |
512 ms |
95776 KB |
Output is correct |
8 |
Correct |
515 ms |
95640 KB |
Output is correct |
9 |
Correct |
629 ms |
96084 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
493 ms |
95684 KB |
Output is correct |
3 |
Correct |
506 ms |
95724 KB |
Output is correct |
4 |
Correct |
627 ms |
95824 KB |
Output is correct |
5 |
Correct |
0 ms |
360 KB |
Output is correct |
6 |
Correct |
39 ms |
10068 KB |
Output is correct |
7 |
Correct |
41 ms |
10064 KB |
Output is correct |
8 |
Correct |
59 ms |
10048 KB |
Output is correct |
9 |
Correct |
47 ms |
10068 KB |
Output is correct |
10 |
Correct |
37 ms |
10064 KB |
Output is correct |
11 |
Correct |
41 ms |
10284 KB |
Output is correct |
12 |
Correct |
41 ms |
10096 KB |
Output is correct |
13 |
Correct |
48 ms |
10064 KB |
Output is correct |
14 |
Correct |
40 ms |
10072 KB |
Output is correct |
15 |
Correct |
50 ms |
10256 KB |
Output is correct |
16 |
Correct |
44 ms |
10068 KB |
Output is correct |
17 |
Correct |
50 ms |
10176 KB |
Output is correct |
18 |
Correct |
456 ms |
95828 KB |
Output is correct |
19 |
Correct |
562 ms |
95808 KB |
Output is correct |
20 |
Correct |
603 ms |
95608 KB |
Output is correct |
21 |
Correct |
43 ms |
10236 KB |
Output is correct |
22 |
Correct |
42 ms |
10068 KB |
Output is correct |
23 |
Correct |
69 ms |
11940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
51 ms |
10064 KB |
Output is correct |
3 |
Correct |
48 ms |
10068 KB |
Output is correct |
4 |
Correct |
579 ms |
95828 KB |
Output is correct |
5 |
Correct |
53 ms |
10488 KB |
Output is correct |
6 |
Correct |
53 ms |
10064 KB |
Output is correct |
7 |
Correct |
50 ms |
10188 KB |
Output is correct |
8 |
Correct |
50 ms |
10064 KB |
Output is correct |
9 |
Correct |
50 ms |
10240 KB |
Output is correct |
10 |
Correct |
40 ms |
10132 KB |
Output is correct |
11 |
Correct |
42 ms |
10064 KB |
Output is correct |
12 |
Correct |
43 ms |
10132 KB |
Output is correct |
13 |
Correct |
45 ms |
10256 KB |
Output is correct |
14 |
Correct |
525 ms |
95824 KB |
Output is correct |
15 |
Correct |
50 ms |
10064 KB |
Output is correct |
16 |
Correct |
451 ms |
95784 KB |
Output is correct |
17 |
Correct |
500 ms |
95824 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
5 ms |
1372 KB |
Output is correct |
3 |
Correct |
5 ms |
1372 KB |
Output is correct |
4 |
Correct |
1 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 |
460 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
456 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
4 ms |
1372 KB |
Output is correct |
17 |
Correct |
49 ms |
10276 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
181 ms |
22996 KB |
Output is correct |
29 |
Correct |
0 ms |
344 KB |
Output is correct |
30 |
Correct |
493 ms |
95684 KB |
Output is correct |
31 |
Correct |
506 ms |
95724 KB |
Output is correct |
32 |
Correct |
627 ms |
95824 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
529 ms |
95696 KB |
Output is correct |
35 |
Correct |
512 ms |
95776 KB |
Output is correct |
36 |
Correct |
515 ms |
95640 KB |
Output is correct |
37 |
Correct |
629 ms |
96084 KB |
Output is correct |
38 |
Correct |
0 ms |
360 KB |
Output is correct |
39 |
Correct |
39 ms |
10068 KB |
Output is correct |
40 |
Correct |
41 ms |
10064 KB |
Output is correct |
41 |
Correct |
59 ms |
10048 KB |
Output is correct |
42 |
Correct |
47 ms |
10068 KB |
Output is correct |
43 |
Correct |
37 ms |
10064 KB |
Output is correct |
44 |
Correct |
41 ms |
10284 KB |
Output is correct |
45 |
Correct |
41 ms |
10096 KB |
Output is correct |
46 |
Correct |
48 ms |
10064 KB |
Output is correct |
47 |
Correct |
40 ms |
10072 KB |
Output is correct |
48 |
Correct |
50 ms |
10256 KB |
Output is correct |
49 |
Correct |
44 ms |
10068 KB |
Output is correct |
50 |
Correct |
50 ms |
10176 KB |
Output is correct |
51 |
Correct |
456 ms |
95828 KB |
Output is correct |
52 |
Correct |
562 ms |
95808 KB |
Output is correct |
53 |
Correct |
603 ms |
95608 KB |
Output is correct |
54 |
Correct |
43 ms |
10236 KB |
Output is correct |
55 |
Correct |
42 ms |
10068 KB |
Output is correct |
56 |
Correct |
69 ms |
11940 KB |
Output is correct |
57 |
Correct |
1 ms |
344 KB |
Output is correct |
58 |
Correct |
51 ms |
10064 KB |
Output is correct |
59 |
Correct |
48 ms |
10068 KB |
Output is correct |
60 |
Correct |
579 ms |
95828 KB |
Output is correct |
61 |
Correct |
53 ms |
10488 KB |
Output is correct |
62 |
Correct |
53 ms |
10064 KB |
Output is correct |
63 |
Correct |
50 ms |
10188 KB |
Output is correct |
64 |
Correct |
50 ms |
10064 KB |
Output is correct |
65 |
Correct |
50 ms |
10240 KB |
Output is correct |
66 |
Correct |
40 ms |
10132 KB |
Output is correct |
67 |
Correct |
42 ms |
10064 KB |
Output is correct |
68 |
Correct |
43 ms |
10132 KB |
Output is correct |
69 |
Correct |
45 ms |
10256 KB |
Output is correct |
70 |
Correct |
525 ms |
95824 KB |
Output is correct |
71 |
Correct |
50 ms |
10064 KB |
Output is correct |
72 |
Correct |
451 ms |
95784 KB |
Output is correct |
73 |
Correct |
500 ms |
95824 KB |
Output is correct |
74 |
Correct |
1 ms |
344 KB |
Output is correct |
75 |
Correct |
0 ms |
348 KB |
Output is correct |
76 |
Correct |
0 ms |
348 KB |
Output is correct |
77 |
Correct |
0 ms |
348 KB |
Output is correct |
78 |
Correct |
0 ms |
348 KB |
Output is correct |
79 |
Correct |
4 ms |
1372 KB |
Output is correct |
80 |
Correct |
519 ms |
100160 KB |
Output is correct |
81 |
Correct |
622 ms |
100176 KB |
Output is correct |
82 |
Correct |
560 ms |
100040 KB |
Output is correct |
83 |
Correct |
555 ms |
100176 KB |
Output is correct |
84 |
Correct |
537 ms |
100176 KB |
Output is correct |
85 |
Correct |
516 ms |
100096 KB |
Output is correct |
86 |
Correct |
79 ms |
12884 KB |
Output is correct |
87 |
Correct |
0 ms |
604 KB |
Output is correct |