Submission #383380

# Submission time Handle Problem Language Result Execution time Memory
383380 2021-03-29T19:11:59 Z Saynaa Strange Device (APIO19_strange_device) C++17
100 / 100
525 ms 29776 KB
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const int MAXN = 1e6 + 10;
const ll ziad = LLONG_MAX/2;
int n;
ll a, b;
vector< pair<ll, ll> >vec;
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin >> n;
	cin >> a >> b;
	ll x = __gcd(a, b + 1);
	x = a/x;
	if( x <= ziad/b) x *= b;
	else x = ziad;
	for(int i = 0; i < n; i ++){
		ll l, r;
		cin >> l >> r;
		if(r - l + 1 >= x){
			cout << x << endl;
			return 0;
		}
		else{
			l %= x, r %= x;
			if( l <= r)
				vec.push_back({l, r});
			else
				vec.push_back({l, x - 1}), vec.push_back({0, r});
		}
	}
	sort(vec.begin(), vec.end());
	ll mx = LLONG_MIN, ans = 0;
	for(int i = 0; i < vec.size(); i ++){
		ll l = vec[i].first, r = vec[i].second;
		if( l > mx) ans += r - l + 1;
		else if( r >= mx) ans += r - mx;
		mx = max(mx, r);
	}
	cout << ans << endl;
	return 0;
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:35:19: 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]
   35 |  for(int i = 0; i < vec.size(); i ++){
      |                 ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 6 ms 1132 KB Output is correct
3 Correct 6 ms 1132 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 512 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 6 ms 1132 KB Output is correct
17 Correct 51 ms 5732 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 334 ms 18896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 456 ms 29776 KB Output is correct
3 Correct 443 ms 17360 KB Output is correct
4 Correct 431 ms 17776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 456 ms 29776 KB Output is correct
3 Correct 443 ms 17360 KB Output is correct
4 Correct 431 ms 17776 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 442 ms 17744 KB Output is correct
7 Correct 447 ms 17744 KB Output is correct
8 Correct 446 ms 28476 KB Output is correct
9 Correct 486 ms 23504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 456 ms 29776 KB Output is correct
3 Correct 443 ms 17360 KB Output is correct
4 Correct 431 ms 17776 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 46 ms 5732 KB Output is correct
7 Correct 49 ms 5732 KB Output is correct
8 Correct 46 ms 5732 KB Output is correct
9 Correct 46 ms 5732 KB Output is correct
10 Correct 45 ms 5732 KB Output is correct
11 Correct 47 ms 5732 KB Output is correct
12 Correct 48 ms 5732 KB Output is correct
13 Correct 48 ms 5732 KB Output is correct
14 Correct 45 ms 5732 KB Output is correct
15 Correct 50 ms 5732 KB Output is correct
16 Correct 61 ms 5732 KB Output is correct
17 Correct 46 ms 5732 KB Output is correct
18 Correct 463 ms 26320 KB Output is correct
19 Correct 446 ms 25976 KB Output is correct
20 Correct 509 ms 25808 KB Output is correct
21 Correct 49 ms 5732 KB Output is correct
22 Correct 44 ms 5732 KB Output is correct
23 Correct 141 ms 17500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 49 ms 5732 KB Output is correct
3 Correct 52 ms 5860 KB Output is correct
4 Correct 525 ms 24784 KB Output is correct
5 Correct 48 ms 5732 KB Output is correct
6 Correct 48 ms 5732 KB Output is correct
7 Correct 48 ms 5732 KB Output is correct
8 Correct 50 ms 5732 KB Output is correct
9 Correct 49 ms 5732 KB Output is correct
10 Correct 49 ms 5732 KB Output is correct
11 Correct 49 ms 5732 KB Output is correct
12 Correct 44 ms 5732 KB Output is correct
13 Correct 49 ms 5752 KB Output is correct
14 Correct 490 ms 23884 KB Output is correct
15 Correct 49 ms 5732 KB Output is correct
16 Correct 448 ms 23888 KB Output is correct
17 Correct 443 ms 23288 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 6 ms 1132 KB Output is correct
3 Correct 6 ms 1132 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 512 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 6 ms 1132 KB Output is correct
17 Correct 51 ms 5732 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 2 ms 364 KB Output is correct
26 Correct 2 ms 364 KB Output is correct
27 Correct 2 ms 364 KB Output is correct
28 Correct 334 ms 18896 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 456 ms 29776 KB Output is correct
31 Correct 443 ms 17360 KB Output is correct
32 Correct 431 ms 17776 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 442 ms 17744 KB Output is correct
35 Correct 447 ms 17744 KB Output is correct
36 Correct 446 ms 28476 KB Output is correct
37 Correct 486 ms 23504 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 46 ms 5732 KB Output is correct
40 Correct 49 ms 5732 KB Output is correct
41 Correct 46 ms 5732 KB Output is correct
42 Correct 46 ms 5732 KB Output is correct
43 Correct 45 ms 5732 KB Output is correct
44 Correct 47 ms 5732 KB Output is correct
45 Correct 48 ms 5732 KB Output is correct
46 Correct 48 ms 5732 KB Output is correct
47 Correct 45 ms 5732 KB Output is correct
48 Correct 50 ms 5732 KB Output is correct
49 Correct 61 ms 5732 KB Output is correct
50 Correct 46 ms 5732 KB Output is correct
51 Correct 463 ms 26320 KB Output is correct
52 Correct 446 ms 25976 KB Output is correct
53 Correct 509 ms 25808 KB Output is correct
54 Correct 49 ms 5732 KB Output is correct
55 Correct 44 ms 5732 KB Output is correct
56 Correct 141 ms 17500 KB Output is correct
57 Correct 1 ms 364 KB Output is correct
58 Correct 49 ms 5732 KB Output is correct
59 Correct 52 ms 5860 KB Output is correct
60 Correct 525 ms 24784 KB Output is correct
61 Correct 48 ms 5732 KB Output is correct
62 Correct 48 ms 5732 KB Output is correct
63 Correct 48 ms 5732 KB Output is correct
64 Correct 50 ms 5732 KB Output is correct
65 Correct 49 ms 5732 KB Output is correct
66 Correct 49 ms 5732 KB Output is correct
67 Correct 49 ms 5732 KB Output is correct
68 Correct 44 ms 5732 KB Output is correct
69 Correct 49 ms 5752 KB Output is correct
70 Correct 490 ms 23884 KB Output is correct
71 Correct 49 ms 5732 KB Output is correct
72 Correct 448 ms 23888 KB Output is correct
73 Correct 443 ms 23288 KB Output is correct
74 Correct 1 ms 364 KB Output is correct
75 Correct 1 ms 364 KB Output is correct
76 Correct 1 ms 364 KB Output is correct
77 Correct 1 ms 364 KB Output is correct
78 Correct 1 ms 364 KB Output is correct
79 Correct 6 ms 1132 KB Output is correct
80 Correct 523 ms 21716 KB Output is correct
81 Correct 522 ms 20440 KB Output is correct
82 Correct 483 ms 18680 KB Output is correct
83 Correct 488 ms 18696 KB Output is correct
84 Correct 495 ms 17360 KB Output is correct
85 Correct 479 ms 19388 KB Output is correct
86 Correct 142 ms 17756 KB Output is correct
87 Correct 1 ms 364 KB Output is correct