Submission #721884

# Submission time Handle Problem Language Result Execution time Memory
721884 2023-04-11T08:18:28 Z LittleCube Strange Device (APIO19_strange_device) C++17
100 / 100
776 ms 63460 KB
#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define F first
#define S second
using namespace std;

ll N, A, B;
map<ll, int> mp;

ll safe_mul(ll a, ll b)
{
	if(b >= 2e18 / a)
		return 2e18;
	return a * b;
}

signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	cin >> N >> A >> B;
	ll g = __gcd(A, B + 1);
	A /= g;
	A = safe_mul(A, B);
	for (int i = 1; i <= N; i++)
	{
		ll l, r;
		cin >> l >> r;
		if(r - l + 1 >= A)
		{
			cout << A << '\n';
			return 0;
		}
		l %= A, r %= A;
		if(r < l)
		{
			mp[l]++;
			mp[A]--;
			mp[0]++;
			mp[r + 1]--;
		}
		else
		{
			mp[l]++;
			mp[r + 1]--;
		}
	}
	ll last = 0, cnt = 0, ans = 0;
	for (auto [p, v] : mp)
	{
		if(cnt > 0)
			ans += p - last;
		last = p;
		cnt += v;
	}
	cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 8 ms 1096 KB Output is correct
3 Correct 7 ms 984 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 1 ms 216 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
11 Correct 1 ms 320 KB Output is correct
12 Correct 1 ms 316 KB Output is correct
13 Correct 1 ms 320 KB Output is correct
14 Correct 1 ms 316 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 7 ms 1056 KB Output is correct
17 Correct 74 ms 6736 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 249 ms 328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 641 ms 63364 KB Output is correct
3 Correct 674 ms 63460 KB Output is correct
4 Correct 694 ms 63200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 641 ms 63364 KB Output is correct
3 Correct 674 ms 63460 KB Output is correct
4 Correct 694 ms 63200 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 653 ms 63144 KB Output is correct
7 Correct 662 ms 63224 KB Output is correct
8 Correct 646 ms 63164 KB Output is correct
9 Correct 697 ms 63000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 641 ms 63364 KB Output is correct
3 Correct 674 ms 63460 KB Output is correct
4 Correct 694 ms 63200 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 55 ms 6736 KB Output is correct
7 Correct 60 ms 6708 KB Output is correct
8 Correct 58 ms 6692 KB Output is correct
9 Correct 64 ms 6640 KB Output is correct
10 Correct 54 ms 6648 KB Output is correct
11 Correct 54 ms 6704 KB Output is correct
12 Correct 60 ms 6616 KB Output is correct
13 Correct 64 ms 6668 KB Output is correct
14 Correct 58 ms 6696 KB Output is correct
15 Correct 69 ms 6604 KB Output is correct
16 Correct 70 ms 6644 KB Output is correct
17 Correct 72 ms 6648 KB Output is correct
18 Correct 637 ms 63188 KB Output is correct
19 Correct 664 ms 63244 KB Output is correct
20 Correct 751 ms 63200 KB Output is correct
21 Correct 67 ms 6660 KB Output is correct
22 Correct 72 ms 6720 KB Output is correct
23 Correct 112 ms 444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 72 ms 6984 KB Output is correct
3 Correct 79 ms 6856 KB Output is correct
4 Correct 705 ms 63060 KB Output is correct
5 Correct 70 ms 6892 KB Output is correct
6 Correct 70 ms 6832 KB Output is correct
7 Correct 72 ms 6792 KB Output is correct
8 Correct 72 ms 6796 KB Output is correct
9 Correct 72 ms 6920 KB Output is correct
10 Correct 62 ms 7016 KB Output is correct
11 Correct 68 ms 6844 KB Output is correct
12 Correct 73 ms 6808 KB Output is correct
13 Correct 66 ms 6816 KB Output is correct
14 Correct 742 ms 62996 KB Output is correct
15 Correct 81 ms 6832 KB Output is correct
16 Correct 660 ms 63108 KB Output is correct
17 Correct 622 ms 63256 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 8 ms 1096 KB Output is correct
3 Correct 7 ms 984 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 1 ms 216 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
11 Correct 1 ms 320 KB Output is correct
12 Correct 1 ms 316 KB Output is correct
13 Correct 1 ms 320 KB Output is correct
14 Correct 1 ms 316 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 7 ms 1056 KB Output is correct
17 Correct 74 ms 6736 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 320 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 324 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 249 ms 328 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 641 ms 63364 KB Output is correct
31 Correct 674 ms 63460 KB Output is correct
32 Correct 694 ms 63200 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 653 ms 63144 KB Output is correct
35 Correct 662 ms 63224 KB Output is correct
36 Correct 646 ms 63164 KB Output is correct
37 Correct 697 ms 63000 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 55 ms 6736 KB Output is correct
40 Correct 60 ms 6708 KB Output is correct
41 Correct 58 ms 6692 KB Output is correct
42 Correct 64 ms 6640 KB Output is correct
43 Correct 54 ms 6648 KB Output is correct
44 Correct 54 ms 6704 KB Output is correct
45 Correct 60 ms 6616 KB Output is correct
46 Correct 64 ms 6668 KB Output is correct
47 Correct 58 ms 6696 KB Output is correct
48 Correct 69 ms 6604 KB Output is correct
49 Correct 70 ms 6644 KB Output is correct
50 Correct 72 ms 6648 KB Output is correct
51 Correct 637 ms 63188 KB Output is correct
52 Correct 664 ms 63244 KB Output is correct
53 Correct 751 ms 63200 KB Output is correct
54 Correct 67 ms 6660 KB Output is correct
55 Correct 72 ms 6720 KB Output is correct
56 Correct 112 ms 444 KB Output is correct
57 Correct 1 ms 316 KB Output is correct
58 Correct 72 ms 6984 KB Output is correct
59 Correct 79 ms 6856 KB Output is correct
60 Correct 705 ms 63060 KB Output is correct
61 Correct 70 ms 6892 KB Output is correct
62 Correct 70 ms 6832 KB Output is correct
63 Correct 72 ms 6792 KB Output is correct
64 Correct 72 ms 6796 KB Output is correct
65 Correct 72 ms 6920 KB Output is correct
66 Correct 62 ms 7016 KB Output is correct
67 Correct 68 ms 6844 KB Output is correct
68 Correct 73 ms 6808 KB Output is correct
69 Correct 66 ms 6816 KB Output is correct
70 Correct 742 ms 62996 KB Output is correct
71 Correct 81 ms 6832 KB Output is correct
72 Correct 660 ms 63108 KB Output is correct
73 Correct 622 ms 63256 KB Output is correct
74 Correct 1 ms 212 KB Output is correct
75 Correct 1 ms 212 KB Output is correct
76 Correct 1 ms 212 KB Output is correct
77 Correct 1 ms 212 KB Output is correct
78 Correct 1 ms 212 KB Output is correct
79 Correct 7 ms 932 KB Output is correct
80 Correct 681 ms 63268 KB Output is correct
81 Correct 675 ms 63172 KB Output is correct
82 Correct 776 ms 63088 KB Output is correct
83 Correct 739 ms 63100 KB Output is correct
84 Correct 719 ms 63016 KB Output is correct
85 Correct 679 ms 62932 KB Output is correct
86 Correct 103 ms 296 KB Output is correct
87 Correct 1 ms 212 KB Output is correct