Submission #527157

# Submission time Handle Problem Language Result Execution time Memory
527157 2022-02-17T02:54:09 Z Leonardo_Paes Strange Device (APIO19_strange_device) C++17
100 / 100
685 ms 79588 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
#define f first
#define s second
// number x and x + (a / gcd(a, b+1) * b) are equal

ll gcd(ll a, ll b){
	if(b == 0) return a;
	return gcd(b, a%b);
}


const ll inf = 1e18;

int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	int n;
	ll a, b;
	cin >> n >> a >> b;
	ll aux = a / (gcd(a, b+1));
	bool ok = (log2(aux) + log2(b) <= log2(inf));
	ll m = (ok ? aux * b : inf + 3);
	vector<pii> v;
	bool mx = 0;
	for(int i=0; i<n; i++){
		ll l, r;
		cin >> l >> r;
		if(r-l+1 > m) mx = 1;
		l = l % m, r = r % m;
		if(l <= r){
			v.push_back({l, r});
			v.push_back({r, inf + 5});
		}
		else{
			v.push_back({l, m-1});
			v.push_back({m-1, inf + 5});
			v.push_back({0, r});
			v.push_back({r, inf + 5});
		}
	}
	if(mx){
		cout << m << "\n";
		return 0;
	}
	multiset<ll> s;
	ll ans = 0;
	sort(v.begin(), v.end());
	for(pii x : v){
		ll l = x.f, r = x.s;
		//cout << l << " " << r << "\n";
		if(r == inf + 5){ // out
			s.erase(s.find(-l));
		}
		else{ // in
			if(s.empty()) ans += r-l+1;
			else{
				ll mxx = -(*s.begin());
				ans += max(0LL, r-mxx);
			}
			s.insert(-r);
		}
	}
	cout << ans << "\n";
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 304 KB Output is correct
2 Correct 6 ms 1220 KB Output is correct
3 Correct 6 ms 1256 KB Output is correct
4 Correct 0 ms 308 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 312 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 308 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 8 ms 1320 KB Output is correct
17 Correct 62 ms 7216 KB Output is correct
18 Correct 1 ms 312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
5 Correct 666 ms 79588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 586 ms 35004 KB Output is correct
3 Correct 588 ms 35008 KB Output is correct
4 Correct 587 ms 35164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 586 ms 35004 KB Output is correct
3 Correct 588 ms 35008 KB Output is correct
4 Correct 587 ms 35164 KB Output is correct
5 Correct 0 ms 316 KB Output is correct
6 Correct 582 ms 35172 KB Output is correct
7 Correct 539 ms 35200 KB Output is correct
8 Correct 581 ms 35204 KB Output is correct
9 Correct 597 ms 35136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 586 ms 35004 KB Output is correct
3 Correct 588 ms 35008 KB Output is correct
4 Correct 587 ms 35164 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 55 ms 7192 KB Output is correct
7 Correct 77 ms 7272 KB Output is correct
8 Correct 55 ms 7208 KB Output is correct
9 Correct 54 ms 7220 KB Output is correct
10 Correct 51 ms 7220 KB Output is correct
11 Correct 67 ms 7168 KB Output is correct
12 Correct 53 ms 7232 KB Output is correct
13 Correct 63 ms 7256 KB Output is correct
14 Correct 51 ms 7252 KB Output is correct
15 Correct 59 ms 7212 KB Output is correct
16 Correct 58 ms 7236 KB Output is correct
17 Correct 63 ms 7256 KB Output is correct
18 Correct 561 ms 37768 KB Output is correct
19 Correct 550 ms 37776 KB Output is correct
20 Correct 622 ms 37856 KB Output is correct
21 Correct 71 ms 7264 KB Output is correct
22 Correct 54 ms 7280 KB Output is correct
23 Correct 248 ms 39372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 58 ms 7252 KB Output is correct
3 Correct 64 ms 7224 KB Output is correct
4 Correct 630 ms 34776 KB Output is correct
5 Correct 67 ms 7224 KB Output is correct
6 Correct 58 ms 7220 KB Output is correct
7 Correct 59 ms 7216 KB Output is correct
8 Correct 58 ms 7268 KB Output is correct
9 Correct 61 ms 7400 KB Output is correct
10 Correct 64 ms 7232 KB Output is correct
11 Correct 64 ms 7228 KB Output is correct
12 Correct 50 ms 7224 KB Output is correct
13 Correct 59 ms 7224 KB Output is correct
14 Correct 659 ms 35292 KB Output is correct
15 Correct 73 ms 7216 KB Output is correct
16 Correct 510 ms 36700 KB Output is correct
17 Correct 532 ms 36352 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 304 KB Output is correct
2 Correct 6 ms 1220 KB Output is correct
3 Correct 6 ms 1256 KB Output is correct
4 Correct 0 ms 308 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 312 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 308 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 8 ms 1320 KB Output is correct
17 Correct 62 ms 7216 KB Output is correct
18 Correct 1 ms 312 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 324 KB Output is correct
27 Correct 2 ms 332 KB Output is correct
28 Correct 666 ms 79588 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 586 ms 35004 KB Output is correct
31 Correct 588 ms 35008 KB Output is correct
32 Correct 587 ms 35164 KB Output is correct
33 Correct 0 ms 316 KB Output is correct
34 Correct 582 ms 35172 KB Output is correct
35 Correct 539 ms 35200 KB Output is correct
36 Correct 581 ms 35204 KB Output is correct
37 Correct 597 ms 35136 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 55 ms 7192 KB Output is correct
40 Correct 77 ms 7272 KB Output is correct
41 Correct 55 ms 7208 KB Output is correct
42 Correct 54 ms 7220 KB Output is correct
43 Correct 51 ms 7220 KB Output is correct
44 Correct 67 ms 7168 KB Output is correct
45 Correct 53 ms 7232 KB Output is correct
46 Correct 63 ms 7256 KB Output is correct
47 Correct 51 ms 7252 KB Output is correct
48 Correct 59 ms 7212 KB Output is correct
49 Correct 58 ms 7236 KB Output is correct
50 Correct 63 ms 7256 KB Output is correct
51 Correct 561 ms 37768 KB Output is correct
52 Correct 550 ms 37776 KB Output is correct
53 Correct 622 ms 37856 KB Output is correct
54 Correct 71 ms 7264 KB Output is correct
55 Correct 54 ms 7280 KB Output is correct
56 Correct 248 ms 39372 KB Output is correct
57 Correct 1 ms 204 KB Output is correct
58 Correct 58 ms 7252 KB Output is correct
59 Correct 64 ms 7224 KB Output is correct
60 Correct 630 ms 34776 KB Output is correct
61 Correct 67 ms 7224 KB Output is correct
62 Correct 58 ms 7220 KB Output is correct
63 Correct 59 ms 7216 KB Output is correct
64 Correct 58 ms 7268 KB Output is correct
65 Correct 61 ms 7400 KB Output is correct
66 Correct 64 ms 7232 KB Output is correct
67 Correct 64 ms 7228 KB Output is correct
68 Correct 50 ms 7224 KB Output is correct
69 Correct 59 ms 7224 KB Output is correct
70 Correct 659 ms 35292 KB Output is correct
71 Correct 73 ms 7216 KB Output is correct
72 Correct 510 ms 36700 KB Output is correct
73 Correct 532 ms 36352 KB Output is correct
74 Correct 1 ms 204 KB Output is correct
75 Correct 1 ms 204 KB Output is correct
76 Correct 0 ms 204 KB Output is correct
77 Correct 0 ms 204 KB Output is correct
78 Correct 1 ms 204 KB Output is correct
79 Correct 7 ms 1280 KB Output is correct
80 Correct 685 ms 36756 KB Output is correct
81 Correct 638 ms 38364 KB Output is correct
82 Correct 597 ms 38300 KB Output is correct
83 Correct 626 ms 38288 KB Output is correct
84 Correct 618 ms 38316 KB Output is correct
85 Correct 609 ms 38268 KB Output is correct
86 Correct 251 ms 39392 KB Output is correct
87 Correct 1 ms 204 KB Output is correct