Submission #230059

# Submission time Handle Problem Language Result Execution time Memory
230059 2020-05-07T23:40:59 Z AMO5 Strange Device (APIO19_strange_device) C++
100 / 100
599 ms 37460 KB
// READ & UNDERSTAND
// ll, int overflow, array bounds, memset(0)
// special cases (n=1?), n+1 (1-index)
// do smth instead of nothing & stay organized
// WRITE STUFF DOWN

#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

ll INF=LLONG_MAX;

int const mxn=1e6+5;
ll const MAX=1e18+10;

ll l[mxn],r[mxn];

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	ll n,a,b;
	cin >> n >> a >> b;
	ll gcd = __gcd(a,b+1); 
	ll maxi = a/gcd;
	if(__lg(a)+__lg(b)>60){
		maxi = MAX;
	}else{
		maxi = min(maxi*b,MAX);
	}
	bool all=0;
	vector<pll>seg;
	for(int i=0; i<n; i++){
		cin >> l[i] >> r[i];
		if(r[i]-l[i]+1>=maxi)all=1;
		l[i]%=maxi; r[i]%=maxi;
		if(r[i]>=l[i]){
			seg.emplace_back(pll(l[i],r[i]));
		}else{
			seg.emplace_back(pll((ll)0,r[i]));
			seg.emplace_back(pll(l[i],ll(maxi-1)));
		}
	}
	if(all){
		cout << maxi << endl;
		return 0;
	}
	sort(all(seg));
	ll ans = 0;
	ll cur = 0;
	for(int i=0; i<(int)seg.size(); i++){
		ans += max(ll(0),seg[i].se+1-max(seg[i].fi,cur));
		cur = max(seg[i].se+1,cur);
	}
	cout << ans << endl;
}	
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 10 ms 1280 KB Output is correct
3 Correct 10 ms 1280 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 304 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 10 ms 1280 KB Output is correct
17 Correct 60 ms 4076 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 392 ms 32196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 526 ms 32344 KB Output is correct
3 Correct 517 ms 32320 KB Output is correct
4 Correct 497 ms 32192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 526 ms 32344 KB Output is correct
3 Correct 517 ms 32320 KB Output is correct
4 Correct 497 ms 32192 KB Output is correct
5 Correct 5 ms 512 KB Output is correct
6 Correct 523 ms 32192 KB Output is correct
7 Correct 519 ms 32196 KB Output is correct
8 Correct 511 ms 32196 KB Output is correct
9 Correct 557 ms 32192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 526 ms 32344 KB Output is correct
3 Correct 517 ms 32320 KB Output is correct
4 Correct 497 ms 32192 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 56 ms 4072 KB Output is correct
7 Correct 66 ms 4204 KB Output is correct
8 Correct 54 ms 3952 KB Output is correct
9 Correct 55 ms 4076 KB Output is correct
10 Correct 54 ms 3960 KB Output is correct
11 Correct 56 ms 3952 KB Output is correct
12 Correct 54 ms 4076 KB Output is correct
13 Correct 68 ms 3996 KB Output is correct
14 Correct 54 ms 4076 KB Output is correct
15 Correct 60 ms 4084 KB Output is correct
16 Correct 58 ms 3952 KB Output is correct
17 Correct 55 ms 3952 KB Output is correct
18 Correct 526 ms 32320 KB Output is correct
19 Correct 499 ms 32192 KB Output is correct
20 Correct 569 ms 32196 KB Output is correct
21 Correct 58 ms 3952 KB Output is correct
22 Correct 55 ms 3948 KB Output is correct
23 Correct 163 ms 13284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 60 ms 4072 KB Output is correct
3 Correct 59 ms 4128 KB Output is correct
4 Correct 595 ms 32280 KB Output is correct
5 Correct 57 ms 3952 KB Output is correct
6 Correct 57 ms 3952 KB Output is correct
7 Correct 58 ms 3952 KB Output is correct
8 Correct 60 ms 4072 KB Output is correct
9 Correct 58 ms 3952 KB Output is correct
10 Correct 59 ms 3960 KB Output is correct
11 Correct 58 ms 3824 KB Output is correct
12 Correct 54 ms 3828 KB Output is correct
13 Correct 58 ms 3824 KB Output is correct
14 Correct 561 ms 32196 KB Output is correct
15 Correct 59 ms 3824 KB Output is correct
16 Correct 519 ms 32168 KB Output is correct
17 Correct 500 ms 32192 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 10 ms 1280 KB Output is correct
3 Correct 10 ms 1280 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 304 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 10 ms 1280 KB Output is correct
17 Correct 60 ms 4076 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 4 ms 384 KB Output is correct
22 Correct 4 ms 384 KB Output is correct
23 Correct 4 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 392 ms 32196 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 526 ms 32344 KB Output is correct
31 Correct 517 ms 32320 KB Output is correct
32 Correct 497 ms 32192 KB Output is correct
33 Correct 5 ms 512 KB Output is correct
34 Correct 523 ms 32192 KB Output is correct
35 Correct 519 ms 32196 KB Output is correct
36 Correct 511 ms 32196 KB Output is correct
37 Correct 557 ms 32192 KB Output is correct
38 Correct 5 ms 384 KB Output is correct
39 Correct 56 ms 4072 KB Output is correct
40 Correct 66 ms 4204 KB Output is correct
41 Correct 54 ms 3952 KB Output is correct
42 Correct 55 ms 4076 KB Output is correct
43 Correct 54 ms 3960 KB Output is correct
44 Correct 56 ms 3952 KB Output is correct
45 Correct 54 ms 4076 KB Output is correct
46 Correct 68 ms 3996 KB Output is correct
47 Correct 54 ms 4076 KB Output is correct
48 Correct 60 ms 4084 KB Output is correct
49 Correct 58 ms 3952 KB Output is correct
50 Correct 55 ms 3952 KB Output is correct
51 Correct 526 ms 32320 KB Output is correct
52 Correct 499 ms 32192 KB Output is correct
53 Correct 569 ms 32196 KB Output is correct
54 Correct 58 ms 3952 KB Output is correct
55 Correct 55 ms 3948 KB Output is correct
56 Correct 163 ms 13284 KB Output is correct
57 Correct 5 ms 384 KB Output is correct
58 Correct 60 ms 4072 KB Output is correct
59 Correct 59 ms 4128 KB Output is correct
60 Correct 595 ms 32280 KB Output is correct
61 Correct 57 ms 3952 KB Output is correct
62 Correct 57 ms 3952 KB Output is correct
63 Correct 58 ms 3952 KB Output is correct
64 Correct 60 ms 4072 KB Output is correct
65 Correct 58 ms 3952 KB Output is correct
66 Correct 59 ms 3960 KB Output is correct
67 Correct 58 ms 3824 KB Output is correct
68 Correct 54 ms 3828 KB Output is correct
69 Correct 58 ms 3824 KB Output is correct
70 Correct 561 ms 32196 KB Output is correct
71 Correct 59 ms 3824 KB Output is correct
72 Correct 519 ms 32168 KB Output is correct
73 Correct 500 ms 32192 KB Output is correct
74 Correct 5 ms 384 KB Output is correct
75 Correct 4 ms 384 KB Output is correct
76 Correct 5 ms 384 KB Output is correct
77 Correct 5 ms 384 KB Output is correct
78 Correct 5 ms 384 KB Output is correct
79 Correct 9 ms 1280 KB Output is correct
80 Correct 596 ms 37260 KB Output is correct
81 Correct 599 ms 37312 KB Output is correct
82 Correct 570 ms 37184 KB Output is correct
83 Correct 552 ms 37460 KB Output is correct
84 Correct 553 ms 37184 KB Output is correct
85 Correct 573 ms 37188 KB Output is correct
86 Correct 172 ms 23768 KB Output is correct
87 Correct 5 ms 384 KB Output is correct