Submission #316851

# Submission time Handle Problem Language Result Execution time Memory
316851 2020-10-28T10:59:59 Z sofapuden Strange Device (APIO19_strange_device) C++14
100 / 100
766 ms 36932 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	ll n, a, b; cin >> n >> a >> b;
	ll mod = __gcd(a,b+1);
	ll ans = 0;
	if((a/mod) <= LONG_LONG_MAX/b)mod=(a/mod)*b;
	else mod = (ll)2e18;
	vector<array<ll,2>> inter;
	for(int i = 0; i < n; ++i){
		ll l, r; cin >> l >> r;
		if(r-l+1 >= mod){
			cout << mod << "\n";
			return 0;
		}
		l %= mod, r %= mod;
		if(l<=r)inter.push_back({l,0ll}), inter.push_back({r,1ll});
		else inter.push_back({l,0ll}), inter.push_back({0ll,0ll}), inter.push_back({mod-1,1ll}), inter.push_back({r,1ll});
	}
	sort(inter.begin(),inter.end());
	ll cn = 0;
	for(int i = 0; i < (int)inter.size(); ++i){
		if(inter[i][1] == 0){
			cn++;
			if(cn == 1){
				if(i)ans+=inter[i][0]-inter[i-1][0]-1ll;
				else ans+=inter[i][0];
			}
		}
		else cn--;	
	}
	ans = 1+inter[(inter.size()-1)][0]-ans;
	cout << ans << "\n";
}
	
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 6 ms 1024 KB Output is correct
3 Correct 7 ms 1024 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 512 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 7 ms 1408 KB Output is correct
17 Correct 73 ms 7272 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 508 ms 33348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 643 ms 33280 KB Output is correct
3 Correct 654 ms 33512 KB Output is correct
4 Correct 622 ms 36928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 643 ms 33280 KB Output is correct
3 Correct 654 ms 33512 KB Output is correct
4 Correct 622 ms 36928 KB Output is correct
5 Correct 1 ms 288 KB Output is correct
6 Correct 655 ms 36928 KB Output is correct
7 Correct 627 ms 36928 KB Output is correct
8 Correct 640 ms 36884 KB Output is correct
9 Correct 734 ms 35672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 643 ms 33280 KB Output is correct
3 Correct 654 ms 33512 KB Output is correct
4 Correct 622 ms 36928 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 62 ms 7148 KB Output is correct
7 Correct 65 ms 7284 KB Output is correct
8 Correct 61 ms 7276 KB Output is correct
9 Correct 63 ms 7276 KB Output is correct
10 Correct 59 ms 7276 KB Output is correct
11 Correct 72 ms 7280 KB Output is correct
12 Correct 61 ms 7276 KB Output is correct
13 Correct 69 ms 7280 KB Output is correct
14 Correct 63 ms 7276 KB Output is correct
15 Correct 71 ms 7276 KB Output is correct
16 Correct 69 ms 7284 KB Output is correct
17 Correct 62 ms 7284 KB Output is correct
18 Correct 649 ms 36132 KB Output is correct
19 Correct 619 ms 35904 KB Output is correct
20 Correct 766 ms 35936 KB Output is correct
21 Correct 71 ms 7276 KB Output is correct
22 Correct 59 ms 7276 KB Output is correct
23 Correct 213 ms 19588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 67 ms 4844 KB Output is correct
3 Correct 68 ms 4860 KB Output is correct
4 Correct 754 ms 33728 KB Output is correct
5 Correct 68 ms 4968 KB Output is correct
6 Correct 67 ms 4852 KB Output is correct
7 Correct 67 ms 4844 KB Output is correct
8 Correct 69 ms 4872 KB Output is correct
9 Correct 66 ms 4980 KB Output is correct
10 Correct 69 ms 4844 KB Output is correct
11 Correct 65 ms 4840 KB Output is correct
12 Correct 60 ms 4840 KB Output is correct
13 Correct 68 ms 4844 KB Output is correct
14 Correct 720 ms 34016 KB Output is correct
15 Correct 70 ms 4844 KB Output is correct
16 Correct 601 ms 33600 KB Output is correct
17 Correct 629 ms 36932 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 6 ms 1024 KB Output is correct
3 Correct 7 ms 1024 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 512 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 7 ms 1408 KB Output is correct
17 Correct 73 ms 7272 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 1 ms 256 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 0 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 508 ms 33348 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 643 ms 33280 KB Output is correct
31 Correct 654 ms 33512 KB Output is correct
32 Correct 622 ms 36928 KB Output is correct
33 Correct 1 ms 288 KB Output is correct
34 Correct 655 ms 36928 KB Output is correct
35 Correct 627 ms 36928 KB Output is correct
36 Correct 640 ms 36884 KB Output is correct
37 Correct 734 ms 35672 KB Output is correct
38 Correct 0 ms 384 KB Output is correct
39 Correct 62 ms 7148 KB Output is correct
40 Correct 65 ms 7284 KB Output is correct
41 Correct 61 ms 7276 KB Output is correct
42 Correct 63 ms 7276 KB Output is correct
43 Correct 59 ms 7276 KB Output is correct
44 Correct 72 ms 7280 KB Output is correct
45 Correct 61 ms 7276 KB Output is correct
46 Correct 69 ms 7280 KB Output is correct
47 Correct 63 ms 7276 KB Output is correct
48 Correct 71 ms 7276 KB Output is correct
49 Correct 69 ms 7284 KB Output is correct
50 Correct 62 ms 7284 KB Output is correct
51 Correct 649 ms 36132 KB Output is correct
52 Correct 619 ms 35904 KB Output is correct
53 Correct 766 ms 35936 KB Output is correct
54 Correct 71 ms 7276 KB Output is correct
55 Correct 59 ms 7276 KB Output is correct
56 Correct 213 ms 19588 KB Output is correct
57 Correct 1 ms 256 KB Output is correct
58 Correct 67 ms 4844 KB Output is correct
59 Correct 68 ms 4860 KB Output is correct
60 Correct 754 ms 33728 KB Output is correct
61 Correct 68 ms 4968 KB Output is correct
62 Correct 67 ms 4852 KB Output is correct
63 Correct 67 ms 4844 KB Output is correct
64 Correct 69 ms 4872 KB Output is correct
65 Correct 66 ms 4980 KB Output is correct
66 Correct 69 ms 4844 KB Output is correct
67 Correct 65 ms 4840 KB Output is correct
68 Correct 60 ms 4840 KB Output is correct
69 Correct 68 ms 4844 KB Output is correct
70 Correct 720 ms 34016 KB Output is correct
71 Correct 70 ms 4844 KB Output is correct
72 Correct 601 ms 33600 KB Output is correct
73 Correct 629 ms 36932 KB Output is correct
74 Correct 1 ms 384 KB Output is correct
75 Correct 1 ms 384 KB Output is correct
76 Correct 1 ms 384 KB Output is correct
77 Correct 1 ms 384 KB Output is correct
78 Correct 1 ms 384 KB Output is correct
79 Correct 6 ms 1408 KB Output is correct
80 Correct 755 ms 35776 KB Output is correct
81 Correct 760 ms 35908 KB Output is correct
82 Correct 719 ms 33600 KB Output is correct
83 Correct 721 ms 36672 KB Output is correct
84 Correct 723 ms 35652 KB Output is correct
85 Correct 723 ms 35524 KB Output is correct
86 Correct 200 ms 19412 KB Output is correct
87 Correct 1 ms 384 KB Output is correct