Submission #120565

# Submission time Handle Problem Language Result Execution time Memory
120565 2019-06-25T00:52:31 Z nandonathaniel Strange Device (APIO19_strange_device) C++14
100 / 100
687 ms 68936 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL INF=2e18;
const LL MAXN=2e6+5;

LL kali(LL a,LL b){
	if(b==1)return a;
	LL ret=kali(a,b/2);
	ret=min(INF,2LL*ret);
	if(b&1)ret=min(INF,ret+a);
	return ret;
}

LL L[MAXN],R[MAXN];
pair<LL,LL> isi[MAXN];

int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	LL n,A,B;
	cin >> n >> A >> B;
	for(LL i=1;i<=n;i++){
		cin >> L[i] >> R[i];
	}
	LL p=kali(A/__gcd(A,B+1),B);
	LL baru=n+1;
	for(LL i=1;i<=n;i++){
		if(R[i]-L[i]+1>=p){
			cout << p << endl;
			return 0;
		}
		L[i]%=p;
		R[i]%=p;
		if(R[i]<L[i]){
			L[baru]=0;
			R[baru]=R[i];
			R[i]=p-1;
			baru++;
		}
	}
	baru--;
	for(LL i=1;i<=baru;i++)isi[i]={L[i],R[i]};
	sort(isi+1,isi+baru+1);
	LL ans=isi[1].second-isi[1].first+1,last=isi[1].second;
	for(LL i=2;i<=baru;i++){
		ans+=(max(last,isi[i].second)-max(last,isi[i].first-1));
		last=max(last,isi[i].second);
	}
	cout << ans << endl;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 8 ms 632 KB Output is correct
3 Correct 8 ms 632 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 3 ms 348 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
16 Correct 5 ms 692 KB Output is correct
17 Correct 67 ms 3544 KB Output is correct
18 Correct 2 ms 424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 312 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 1 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 504 KB Output is correct
3 Correct 3 ms 380 KB Output is correct
4 Correct 3 ms 504 KB Output is correct
5 Correct 446 ms 31672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 596 ms 31668 KB Output is correct
3 Correct 594 ms 31612 KB Output is correct
4 Correct 622 ms 31864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 596 ms 31668 KB Output is correct
3 Correct 594 ms 31612 KB Output is correct
4 Correct 622 ms 31864 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 594 ms 31724 KB Output is correct
7 Correct 593 ms 31668 KB Output is correct
8 Correct 589 ms 31676 KB Output is correct
9 Correct 650 ms 31628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 596 ms 31668 KB Output is correct
3 Correct 594 ms 31612 KB Output is correct
4 Correct 622 ms 31864 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 63 ms 3440 KB Output is correct
7 Correct 63 ms 3432 KB Output is correct
8 Correct 60 ms 3600 KB Output is correct
9 Correct 62 ms 3496 KB Output is correct
10 Correct 58 ms 3448 KB Output is correct
11 Correct 61 ms 3448 KB Output is correct
12 Correct 60 ms 3576 KB Output is correct
13 Correct 65 ms 3448 KB Output is correct
14 Correct 61 ms 3448 KB Output is correct
15 Correct 65 ms 3564 KB Output is correct
16 Correct 65 ms 3448 KB Output is correct
17 Correct 64 ms 3460 KB Output is correct
18 Correct 608 ms 31624 KB Output is correct
19 Correct 582 ms 31732 KB Output is correct
20 Correct 652 ms 31640 KB Output is correct
21 Correct 65 ms 3448 KB Output is correct
22 Correct 58 ms 3512 KB Output is correct
23 Correct 190 ms 11052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 64 ms 3436 KB Output is correct
3 Correct 65 ms 3420 KB Output is correct
4 Correct 664 ms 31680 KB Output is correct
5 Correct 64 ms 3448 KB Output is correct
6 Correct 65 ms 3500 KB Output is correct
7 Correct 64 ms 3448 KB Output is correct
8 Correct 63 ms 3448 KB Output is correct
9 Correct 67 ms 3420 KB Output is correct
10 Correct 64 ms 3420 KB Output is correct
11 Correct 65 ms 3472 KB Output is correct
12 Correct 58 ms 3448 KB Output is correct
13 Correct 65 ms 3448 KB Output is correct
14 Correct 666 ms 31796 KB Output is correct
15 Correct 73 ms 3628 KB Output is correct
16 Correct 591 ms 31812 KB Output is correct
17 Correct 598 ms 31612 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 8 ms 632 KB Output is correct
3 Correct 8 ms 632 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 3 ms 348 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
16 Correct 5 ms 692 KB Output is correct
17 Correct 67 ms 3544 KB Output is correct
18 Correct 2 ms 424 KB Output is correct
19 Correct 3 ms 312 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 1 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 3 ms 504 KB Output is correct
26 Correct 3 ms 380 KB Output is correct
27 Correct 3 ms 504 KB Output is correct
28 Correct 446 ms 31672 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 596 ms 31668 KB Output is correct
31 Correct 594 ms 31612 KB Output is correct
32 Correct 622 ms 31864 KB Output is correct
33 Correct 2 ms 376 KB Output is correct
34 Correct 594 ms 31724 KB Output is correct
35 Correct 593 ms 31668 KB Output is correct
36 Correct 589 ms 31676 KB Output is correct
37 Correct 650 ms 31628 KB Output is correct
38 Correct 2 ms 376 KB Output is correct
39 Correct 63 ms 3440 KB Output is correct
40 Correct 63 ms 3432 KB Output is correct
41 Correct 60 ms 3600 KB Output is correct
42 Correct 62 ms 3496 KB Output is correct
43 Correct 58 ms 3448 KB Output is correct
44 Correct 61 ms 3448 KB Output is correct
45 Correct 60 ms 3576 KB Output is correct
46 Correct 65 ms 3448 KB Output is correct
47 Correct 61 ms 3448 KB Output is correct
48 Correct 65 ms 3564 KB Output is correct
49 Correct 65 ms 3448 KB Output is correct
50 Correct 64 ms 3460 KB Output is correct
51 Correct 608 ms 31624 KB Output is correct
52 Correct 582 ms 31732 KB Output is correct
53 Correct 652 ms 31640 KB Output is correct
54 Correct 65 ms 3448 KB Output is correct
55 Correct 58 ms 3512 KB Output is correct
56 Correct 190 ms 11052 KB Output is correct
57 Correct 2 ms 376 KB Output is correct
58 Correct 64 ms 3436 KB Output is correct
59 Correct 65 ms 3420 KB Output is correct
60 Correct 664 ms 31680 KB Output is correct
61 Correct 64 ms 3448 KB Output is correct
62 Correct 65 ms 3500 KB Output is correct
63 Correct 64 ms 3448 KB Output is correct
64 Correct 63 ms 3448 KB Output is correct
65 Correct 67 ms 3420 KB Output is correct
66 Correct 64 ms 3420 KB Output is correct
67 Correct 65 ms 3472 KB Output is correct
68 Correct 58 ms 3448 KB Output is correct
69 Correct 65 ms 3448 KB Output is correct
70 Correct 666 ms 31796 KB Output is correct
71 Correct 73 ms 3628 KB Output is correct
72 Correct 591 ms 31812 KB Output is correct
73 Correct 598 ms 31612 KB Output is correct
74 Correct 2 ms 376 KB Output is correct
75 Correct 2 ms 376 KB Output is correct
76 Correct 2 ms 376 KB Output is correct
77 Correct 2 ms 376 KB Output is correct
78 Correct 2 ms 376 KB Output is correct
79 Correct 8 ms 1016 KB Output is correct
80 Correct 674 ms 68936 KB Output is correct
81 Correct 687 ms 68924 KB Output is correct
82 Correct 659 ms 68740 KB Output is correct
83 Correct 660 ms 68744 KB Output is correct
84 Correct 661 ms 68852 KB Output is correct
85 Correct 659 ms 68764 KB Output is correct
86 Correct 189 ms 23544 KB Output is correct
87 Correct 2 ms 376 KB Output is correct