답안 #470200

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
470200 2021-09-03T08:51:41 Z keta_tsimakuridze Discharging (NOI20_discharging) C++14
100 / 100
606 ms 23768 KB
#include<bits/stdc++.h>
#define f first
#define s second
#define int long long
#define pii pair<int,int>
using namespace std;
const int N = 1e6 + 5, inf = 1e9 + 7; // !
int t,r[N],a[N],n, le_[30 * N], ri_[30*N], cur;
pii tree[30 * N];
int f(int k,int x,int b) {
	return k * x + b;
}
void insert(int u,int l,int r,int k,int b) {
	if(l == r) {
		if(f(tree[u].f,l,tree[u].s) > f(k,l,b))  tree[u] = {k,b};
		return;
	}
	int mid = (l + r)/2;
	if(k < tree[u].f) swap(tree[u].f,k), swap(tree[u].s,b);
	if(f(k,mid,b) <= f(tree[u].f,mid,tree[u].s)) {
		if(!ri_[u]) ri_[u] = ++cur, tree[cur] = tree[u];
		else insert(ri_[u],mid + 1,r, tree[u].f, tree[u].s);
		tree[u] = {k,b};
	}
	else {
		if(!le_[u]) le_[u] = ++cur, tree[cur] = {k,b};
		else insert(le_[u],l,mid,k,b);
	}
}
int get(int u,int l,int r,int id) {
	if(!u || l > id || r < id) return inf * inf;
	if(l == r) return f(tree[u].f, id, tree[u].s);
	int mid = (l + r)/2;
	return min(f(tree[u].f,id,tree[u].s), min(get(le_[u],l,mid,id), get(ri_[u],mid+1,r,id)));
}
main(){
	cin >> n;
	int Mx = 0;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
		Mx = max(Mx,a[i]);
	}
	for(int i = n; i >= 1; i--) {
		int x = i + 1;
		while(x < n + 1 && a[x] <= a[i]) x = r[x];
		r[i] = x;
	}
	int mx = 0;
	cur = 1;
	tree[1] = {0,inf * inf};
	for(int i = 1; i <= n; i++) {
		if(a[i] > mx) {
			int x = min( n * a[i], get(1,1,Mx,a[i]));
			insert(1,1,Mx,n - r[i] + 1, x);
			if(a[i] == Mx) {
				cout << x << endl;
				return 0;
			}
		}
		mx = max(mx,a[i]);
	}
 }

Compilation message

Discharging.cpp:36:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   36 | main(){
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 296 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 300 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 2 ms 332 KB Output is correct
3 Correct 1 ms 308 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 2 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 2 ms 332 KB Output is correct
10 Correct 2 ms 332 KB Output is correct
11 Correct 2 ms 332 KB Output is correct
12 Correct 1 ms 304 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 2 ms 332 KB Output is correct
3 Correct 1 ms 308 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 2 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 2 ms 332 KB Output is correct
10 Correct 2 ms 332 KB Output is correct
11 Correct 2 ms 332 KB Output is correct
12 Correct 1 ms 304 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 448 ms 21956 KB Output is correct
17 Correct 476 ms 22880 KB Output is correct
18 Correct 377 ms 21196 KB Output is correct
19 Correct 507 ms 22740 KB Output is correct
20 Correct 501 ms 22724 KB Output is correct
21 Correct 517 ms 23020 KB Output is correct
22 Correct 461 ms 22524 KB Output is correct
23 Correct 558 ms 23612 KB Output is correct
24 Correct 519 ms 22920 KB Output is correct
25 Correct 547 ms 23344 KB Output is correct
26 Correct 606 ms 23768 KB Output is correct
27 Correct 501 ms 22008 KB Output is correct
28 Correct 495 ms 22912 KB Output is correct
29 Correct 536 ms 23236 KB Output is correct
30 Correct 594 ms 23620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 438 ms 16212 KB Output is correct
2 Correct 428 ms 16196 KB Output is correct
3 Correct 437 ms 16196 KB Output is correct
4 Correct 438 ms 16308 KB Output is correct
5 Correct 460 ms 16224 KB Output is correct
6 Correct 449 ms 16272 KB Output is correct
7 Correct 475 ms 16196 KB Output is correct
8 Correct 444 ms 16288 KB Output is correct
9 Correct 433 ms 16236 KB Output is correct
10 Correct 425 ms 16196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 296 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 300 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 2 ms 332 KB Output is correct
17 Correct 1 ms 308 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 2 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 2 ms 332 KB Output is correct
24 Correct 2 ms 332 KB Output is correct
25 Correct 2 ms 332 KB Output is correct
26 Correct 1 ms 304 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 2 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 1 ms 332 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 1 ms 332 KB Output is correct
41 Correct 1 ms 332 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 1 ms 332 KB Output is correct
45 Correct 1 ms 332 KB Output is correct
46 Correct 1 ms 332 KB Output is correct
47 Correct 1 ms 332 KB Output is correct
48 Correct 1 ms 332 KB Output is correct
49 Correct 1 ms 332 KB Output is correct
50 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 296 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 300 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 2 ms 332 KB Output is correct
17 Correct 1 ms 308 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 2 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 2 ms 332 KB Output is correct
24 Correct 2 ms 332 KB Output is correct
25 Correct 2 ms 332 KB Output is correct
26 Correct 1 ms 304 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 2 ms 332 KB Output is correct
30 Correct 448 ms 21956 KB Output is correct
31 Correct 476 ms 22880 KB Output is correct
32 Correct 377 ms 21196 KB Output is correct
33 Correct 507 ms 22740 KB Output is correct
34 Correct 501 ms 22724 KB Output is correct
35 Correct 517 ms 23020 KB Output is correct
36 Correct 461 ms 22524 KB Output is correct
37 Correct 558 ms 23612 KB Output is correct
38 Correct 519 ms 22920 KB Output is correct
39 Correct 547 ms 23344 KB Output is correct
40 Correct 606 ms 23768 KB Output is correct
41 Correct 501 ms 22008 KB Output is correct
42 Correct 495 ms 22912 KB Output is correct
43 Correct 536 ms 23236 KB Output is correct
44 Correct 594 ms 23620 KB Output is correct
45 Correct 438 ms 16212 KB Output is correct
46 Correct 428 ms 16196 KB Output is correct
47 Correct 437 ms 16196 KB Output is correct
48 Correct 438 ms 16308 KB Output is correct
49 Correct 460 ms 16224 KB Output is correct
50 Correct 449 ms 16272 KB Output is correct
51 Correct 475 ms 16196 KB Output is correct
52 Correct 444 ms 16288 KB Output is correct
53 Correct 433 ms 16236 KB Output is correct
54 Correct 425 ms 16196 KB Output is correct
55 Correct 1 ms 332 KB Output is correct
56 Correct 1 ms 332 KB Output is correct
57 Correct 1 ms 332 KB Output is correct
58 Correct 1 ms 332 KB Output is correct
59 Correct 1 ms 332 KB Output is correct
60 Correct 1 ms 332 KB Output is correct
61 Correct 1 ms 332 KB Output is correct
62 Correct 1 ms 332 KB Output is correct
63 Correct 1 ms 332 KB Output is correct
64 Correct 1 ms 332 KB Output is correct
65 Correct 1 ms 332 KB Output is correct
66 Correct 1 ms 332 KB Output is correct
67 Correct 1 ms 332 KB Output is correct
68 Correct 1 ms 332 KB Output is correct
69 Correct 1 ms 332 KB Output is correct
70 Correct 1 ms 332 KB Output is correct
71 Correct 1 ms 332 KB Output is correct
72 Correct 1 ms 332 KB Output is correct
73 Correct 1 ms 332 KB Output is correct
74 Correct 1 ms 332 KB Output is correct
75 Correct 1 ms 332 KB Output is correct
76 Correct 369 ms 22000 KB Output is correct
77 Correct 334 ms 21956 KB Output is correct
78 Correct 335 ms 21356 KB Output is correct
79 Correct 318 ms 21624 KB Output is correct
80 Correct 346 ms 22228 KB Output is correct
81 Correct 319 ms 21492 KB Output is correct
82 Correct 315 ms 21496 KB Output is correct
83 Correct 326 ms 21868 KB Output is correct
84 Correct 320 ms 21764 KB Output is correct
85 Correct 332 ms 22044 KB Output is correct
86 Correct 308 ms 21360 KB Output is correct
87 Correct 311 ms 21496 KB Output is correct
88 Correct 321 ms 21572 KB Output is correct
89 Correct 323 ms 21444 KB Output is correct
90 Correct 307 ms 21384 KB Output is correct
91 Correct 302 ms 21156 KB Output is correct
92 Correct 533 ms 23544 KB Output is correct
93 Correct 489 ms 23336 KB Output is correct
94 Correct 290 ms 20804 KB Output is correct
95 Correct 341 ms 22296 KB Output is correct
96 Correct 303 ms 21188 KB Output is correct
97 Correct 310 ms 21556 KB Output is correct
98 Correct 320 ms 21804 KB Output is correct
99 Correct 311 ms 21292 KB Output is correct
100 Correct 326 ms 21416 KB Output is correct