Submission #579498

# Submission time Handle Problem Language Result Execution time Memory
579498 2022-06-19T09:30:36 Z gun_gan Strange Device (APIO19_strange_device) C++17
100 / 100
808 ms 128516 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main()
{
	cin.tie(0) -> ios_base::sync_with_stdio(0);
 
	ll n, a, b;
	cin >> n >> a >> b;
 
	if(a > 1e18 / b)
	{
		ll sum = 0;
		for(int i = 0; i < n; i++)
		{
			ll l, r;
			cin >> l >> r;
			sum += r - l + 1;
		}

		cout << sum;
	}
	else
	{
		ll g = a * b / gcd(a, b + 1);

		map<ll, vector<ll>> M;
		for(int i = 0; i < n; i++)
		{
			ll l, r;
			cin >> l >> r;

			if(r - l + 1 >= g)
			{
				cout << g << '\n';
				return 0;
			}
			l %= g, r %= g;
			if(r < l)
			{
				M[0].push_back(r);
				M[l].push_back(g - 1);
			}
			else
			{
				M[l].push_back(r);
			}
		}
	 
		multiset<ll> S;
		vector<pair<ll,ll>> intervals;
	 
		ll begin = 2e18, last = 0;
		for(auto &[st, v] : M)
		{	
			
			while(!S.empty() && *S.begin() < st)
			{
				S.erase(S.begin());
			}
	 
			if(S.empty() && begin != 2e18)
			{
				intervals.push_back({begin, last});
				begin = 2e18;
				last = 0;
			}
	 
			begin = min(begin, st);
	 
			for(auto i : v)
			{
				S.insert(i);
				last = max(last, i);
			}
	 
		}
	 
		if(!S.empty() && begin != 2e18)
		{
			while(!S.empty())
			{
				last = max(last, *S.begin());
				S.erase(S.begin());
			}
	 
			intervals.push_back({begin, last});
		}
	 
		long long ans = 0;
		for(auto [l, r] : intervals) 
		{
			ans += r - l + 1;
		}
		cout << ans;
	}
 
	
 
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 8 ms 2004 KB Output is correct
3 Correct 8 ms 1984 KB Output is correct
4 Correct 1 ms 320 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 316 KB Output is correct
8 Correct 1 ms 316 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 316 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 8 ms 2036 KB Output is correct
17 Correct 74 ms 13768 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 0 ms 212 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 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 560 ms 55372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 721 ms 126756 KB Output is correct
3 Correct 704 ms 126776 KB Output is correct
4 Correct 726 ms 126752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 721 ms 126756 KB Output is correct
3 Correct 704 ms 126776 KB Output is correct
4 Correct 726 ms 126752 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 710 ms 126792 KB Output is correct
7 Correct 710 ms 126780 KB Output is correct
8 Correct 680 ms 126800 KB Output is correct
9 Correct 744 ms 126784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 721 ms 126756 KB Output is correct
3 Correct 704 ms 126776 KB Output is correct
4 Correct 726 ms 126752 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 86 ms 13748 KB Output is correct
7 Correct 72 ms 13804 KB Output is correct
8 Correct 71 ms 13856 KB Output is correct
9 Correct 67 ms 13780 KB Output is correct
10 Correct 62 ms 13840 KB Output is correct
11 Correct 72 ms 13732 KB Output is correct
12 Correct 81 ms 13788 KB Output is correct
13 Correct 68 ms 13796 KB Output is correct
14 Correct 66 ms 13804 KB Output is correct
15 Correct 77 ms 13752 KB Output is correct
16 Correct 87 ms 13720 KB Output is correct
17 Correct 87 ms 13820 KB Output is correct
18 Correct 661 ms 126828 KB Output is correct
19 Correct 709 ms 126936 KB Output is correct
20 Correct 774 ms 126972 KB Output is correct
21 Correct 82 ms 13896 KB Output is correct
22 Correct 93 ms 13764 KB Output is correct
23 Correct 188 ms 19448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 94 ms 13804 KB Output is correct
3 Correct 76 ms 13840 KB Output is correct
4 Correct 695 ms 126852 KB Output is correct
5 Correct 83 ms 13932 KB Output is correct
6 Correct 75 ms 13804 KB Output is correct
7 Correct 69 ms 13880 KB Output is correct
8 Correct 70 ms 13728 KB Output is correct
9 Correct 78 ms 13760 KB Output is correct
10 Correct 68 ms 13824 KB Output is correct
11 Correct 69 ms 13812 KB Output is correct
12 Correct 70 ms 13744 KB Output is correct
13 Correct 85 ms 13836 KB Output is correct
14 Correct 773 ms 126788 KB Output is correct
15 Correct 70 ms 13832 KB Output is correct
16 Correct 664 ms 126740 KB Output is correct
17 Correct 701 ms 126816 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 2004 KB Output is correct
3 Correct 8 ms 1984 KB Output is correct
4 Correct 1 ms 320 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 316 KB Output is correct
8 Correct 1 ms 316 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 316 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 8 ms 2036 KB Output is correct
17 Correct 74 ms 13768 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 320 KB Output is correct
20 Correct 0 ms 212 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 468 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 560 ms 55372 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 721 ms 126756 KB Output is correct
31 Correct 704 ms 126776 KB Output is correct
32 Correct 726 ms 126752 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 710 ms 126792 KB Output is correct
35 Correct 710 ms 126780 KB Output is correct
36 Correct 680 ms 126800 KB Output is correct
37 Correct 744 ms 126784 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 86 ms 13748 KB Output is correct
40 Correct 72 ms 13804 KB Output is correct
41 Correct 71 ms 13856 KB Output is correct
42 Correct 67 ms 13780 KB Output is correct
43 Correct 62 ms 13840 KB Output is correct
44 Correct 72 ms 13732 KB Output is correct
45 Correct 81 ms 13788 KB Output is correct
46 Correct 68 ms 13796 KB Output is correct
47 Correct 66 ms 13804 KB Output is correct
48 Correct 77 ms 13752 KB Output is correct
49 Correct 87 ms 13720 KB Output is correct
50 Correct 87 ms 13820 KB Output is correct
51 Correct 661 ms 126828 KB Output is correct
52 Correct 709 ms 126936 KB Output is correct
53 Correct 774 ms 126972 KB Output is correct
54 Correct 82 ms 13896 KB Output is correct
55 Correct 93 ms 13764 KB Output is correct
56 Correct 188 ms 19448 KB Output is correct
57 Correct 1 ms 340 KB Output is correct
58 Correct 94 ms 13804 KB Output is correct
59 Correct 76 ms 13840 KB Output is correct
60 Correct 695 ms 126852 KB Output is correct
61 Correct 83 ms 13932 KB Output is correct
62 Correct 75 ms 13804 KB Output is correct
63 Correct 69 ms 13880 KB Output is correct
64 Correct 70 ms 13728 KB Output is correct
65 Correct 78 ms 13760 KB Output is correct
66 Correct 68 ms 13824 KB Output is correct
67 Correct 69 ms 13812 KB Output is correct
68 Correct 70 ms 13744 KB Output is correct
69 Correct 85 ms 13836 KB Output is correct
70 Correct 773 ms 126788 KB Output is correct
71 Correct 70 ms 13832 KB Output is correct
72 Correct 664 ms 126740 KB Output is correct
73 Correct 701 ms 126816 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 324 KB Output is correct
78 Correct 1 ms 320 KB Output is correct
79 Correct 8 ms 2132 KB Output is correct
80 Correct 793 ms 128488 KB Output is correct
81 Correct 761 ms 128516 KB Output is correct
82 Correct 778 ms 128440 KB Output is correct
83 Correct 801 ms 128396 KB Output is correct
84 Correct 808 ms 128020 KB Output is correct
85 Correct 738 ms 127636 KB Output is correct
86 Correct 205 ms 19256 KB Output is correct
87 Correct 1 ms 212 KB Output is correct