#include <bits/stdc++.h>
#define debug(x) cerr << #x << " " << x << "\n"
#define debugs(x) cerr << #x << " " << x << " "
#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx2")
using namespace std;
typedef long long ll;
typedef pair <ll, ll> pii;
const ll NMAX = 300001;
const int INF = 1e9;
const ll nrbits = 20;
const ll MOD = 998244353;
const ll VALMAX = 2e18;
signed main() {
#ifdef HOME
ifstream cin(".in");
ofstream cout(".out");
#endif // HOME
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
ll a, b;
cin >> n >> a >> b;
ll period;
ll g = __gcd(a, b + 1);
a /= g;
if(a >= VALMAX / b){
period = VALMAX;
}else{
period = a * b;
}
vector <pii> events;
while(n--){
ll l, r;
cin >> l >> r;
if(r - l + 1 >= period){
events.push_back({0, 1});
events.push_back({period, -1});
continue;
}
l %= period;
r %= period;
if(l <= r){
events.push_back({l, 1});
events.push_back({r + 1, -1});
}else{
events.push_back({0, 1});
events.push_back({r + 1, -1});
events.push_back({l, 1});
events.push_back({period, -1});
}
}
int s = 0;
ll total = 0;
sort(events.begin(), events.end());
for(int i = 0; i < events.size(); i++){
s += events[i].second;
if(events[i].first < period && (i < (events.size() - 1))){
if(s > 0)
total += (min(period, events[i + 1].first) - events[i].first);
}
}
cout << total;
return 0;
}
Compilation message
strange_device.cpp: In function 'int main()':
strange_device.cpp:61:22: 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]
61 | for(int i = 0; i < events.size(); i++){
| ~~^~~~~~~~~~~~~~~
strange_device.cpp:63:43: 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]
63 | if(events[i].first < period && (i < (events.size() - 1))){
| ~~^~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
6 ms |
1436 KB |
Output is correct |
3 |
Correct |
4 ms |
1244 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 |
1 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 |
0 ms |
348 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 |
6 ms |
1368 KB |
Output is correct |
17 |
Correct |
50 ms |
8404 KB |
Output is correct |
18 |
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 |
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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
254 ms |
46084 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
396 ms |
51356 KB |
Output is correct |
3 |
Correct |
395 ms |
51368 KB |
Output is correct |
4 |
Correct |
375 ms |
69104 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
396 ms |
51356 KB |
Output is correct |
3 |
Correct |
395 ms |
51368 KB |
Output is correct |
4 |
Correct |
375 ms |
69104 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
404 ms |
69036 KB |
Output is correct |
7 |
Correct |
383 ms |
69028 KB |
Output is correct |
8 |
Correct |
384 ms |
69924 KB |
Output is correct |
9 |
Correct |
452 ms |
70368 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
396 ms |
51356 KB |
Output is correct |
3 |
Correct |
395 ms |
51368 KB |
Output is correct |
4 |
Correct |
375 ms |
69104 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
38 ms |
9172 KB |
Output is correct |
7 |
Correct |
40 ms |
7372 KB |
Output is correct |
8 |
Correct |
37 ms |
7368 KB |
Output is correct |
9 |
Correct |
43 ms |
9168 KB |
Output is correct |
10 |
Correct |
36 ms |
8556 KB |
Output is correct |
11 |
Correct |
38 ms |
7880 KB |
Output is correct |
12 |
Correct |
36 ms |
7380 KB |
Output is correct |
13 |
Correct |
44 ms |
8068 KB |
Output is correct |
14 |
Correct |
37 ms |
9164 KB |
Output is correct |
15 |
Correct |
44 ms |
7884 KB |
Output is correct |
16 |
Correct |
51 ms |
8392 KB |
Output is correct |
17 |
Correct |
37 ms |
7380 KB |
Output is correct |
18 |
Correct |
407 ms |
69284 KB |
Output is correct |
19 |
Correct |
370 ms |
69580 KB |
Output is correct |
20 |
Correct |
482 ms |
69780 KB |
Output is correct |
21 |
Correct |
45 ms |
7880 KB |
Output is correct |
22 |
Correct |
33 ms |
8660 KB |
Output is correct |
23 |
Correct |
131 ms |
28000 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
42 ms |
7892 KB |
Output is correct |
3 |
Correct |
44 ms |
8608 KB |
Output is correct |
4 |
Correct |
543 ms |
60320 KB |
Output is correct |
5 |
Correct |
50 ms |
9036 KB |
Output is correct |
6 |
Correct |
57 ms |
9172 KB |
Output is correct |
7 |
Correct |
43 ms |
8720 KB |
Output is correct |
8 |
Correct |
45 ms |
9172 KB |
Output is correct |
9 |
Correct |
42 ms |
8140 KB |
Output is correct |
10 |
Correct |
48 ms |
7372 KB |
Output is correct |
11 |
Correct |
42 ms |
7628 KB |
Output is correct |
12 |
Correct |
37 ms |
8140 KB |
Output is correct |
13 |
Correct |
45 ms |
8208 KB |
Output is correct |
14 |
Correct |
476 ms |
60544 KB |
Output is correct |
15 |
Correct |
46 ms |
7628 KB |
Output is correct |
16 |
Correct |
371 ms |
70044 KB |
Output is correct |
17 |
Correct |
390 ms |
69288 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
6 ms |
1436 KB |
Output is correct |
3 |
Correct |
4 ms |
1244 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 |
1 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 |
0 ms |
348 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 |
6 ms |
1368 KB |
Output is correct |
17 |
Correct |
50 ms |
8404 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 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 |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
468 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
254 ms |
46084 KB |
Output is correct |
29 |
Correct |
0 ms |
344 KB |
Output is correct |
30 |
Correct |
396 ms |
51356 KB |
Output is correct |
31 |
Correct |
395 ms |
51368 KB |
Output is correct |
32 |
Correct |
375 ms |
69104 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
404 ms |
69036 KB |
Output is correct |
35 |
Correct |
383 ms |
69028 KB |
Output is correct |
36 |
Correct |
384 ms |
69924 KB |
Output is correct |
37 |
Correct |
452 ms |
70368 KB |
Output is correct |
38 |
Correct |
0 ms |
344 KB |
Output is correct |
39 |
Correct |
38 ms |
9172 KB |
Output is correct |
40 |
Correct |
40 ms |
7372 KB |
Output is correct |
41 |
Correct |
37 ms |
7368 KB |
Output is correct |
42 |
Correct |
43 ms |
9168 KB |
Output is correct |
43 |
Correct |
36 ms |
8556 KB |
Output is correct |
44 |
Correct |
38 ms |
7880 KB |
Output is correct |
45 |
Correct |
36 ms |
7380 KB |
Output is correct |
46 |
Correct |
44 ms |
8068 KB |
Output is correct |
47 |
Correct |
37 ms |
9164 KB |
Output is correct |
48 |
Correct |
44 ms |
7884 KB |
Output is correct |
49 |
Correct |
51 ms |
8392 KB |
Output is correct |
50 |
Correct |
37 ms |
7380 KB |
Output is correct |
51 |
Correct |
407 ms |
69284 KB |
Output is correct |
52 |
Correct |
370 ms |
69580 KB |
Output is correct |
53 |
Correct |
482 ms |
69780 KB |
Output is correct |
54 |
Correct |
45 ms |
7880 KB |
Output is correct |
55 |
Correct |
33 ms |
8660 KB |
Output is correct |
56 |
Correct |
131 ms |
28000 KB |
Output is correct |
57 |
Correct |
0 ms |
600 KB |
Output is correct |
58 |
Correct |
42 ms |
7892 KB |
Output is correct |
59 |
Correct |
44 ms |
8608 KB |
Output is correct |
60 |
Correct |
543 ms |
60320 KB |
Output is correct |
61 |
Correct |
50 ms |
9036 KB |
Output is correct |
62 |
Correct |
57 ms |
9172 KB |
Output is correct |
63 |
Correct |
43 ms |
8720 KB |
Output is correct |
64 |
Correct |
45 ms |
9172 KB |
Output is correct |
65 |
Correct |
42 ms |
8140 KB |
Output is correct |
66 |
Correct |
48 ms |
7372 KB |
Output is correct |
67 |
Correct |
42 ms |
7628 KB |
Output is correct |
68 |
Correct |
37 ms |
8140 KB |
Output is correct |
69 |
Correct |
45 ms |
8208 KB |
Output is correct |
70 |
Correct |
476 ms |
60544 KB |
Output is correct |
71 |
Correct |
46 ms |
7628 KB |
Output is correct |
72 |
Correct |
371 ms |
70044 KB |
Output is correct |
73 |
Correct |
390 ms |
69288 KB |
Output is correct |
74 |
Correct |
0 ms |
344 KB |
Output is correct |
75 |
Correct |
0 ms |
344 KB |
Output is correct |
76 |
Correct |
1 ms |
500 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 |
1248 KB |
Output is correct |
80 |
Correct |
525 ms |
69800 KB |
Output is correct |
81 |
Correct |
534 ms |
69200 KB |
Output is correct |
82 |
Correct |
447 ms |
70040 KB |
Output is correct |
83 |
Correct |
434 ms |
70076 KB |
Output is correct |
84 |
Correct |
463 ms |
69876 KB |
Output is correct |
85 |
Correct |
459 ms |
70060 KB |
Output is correct |
86 |
Correct |
112 ms |
28844 KB |
Output is correct |
87 |
Correct |
1 ms |
348 KB |
Output is correct |