답안 #470196

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
470196 2021-09-03T08:41:52 Z keta_tsimakuridze Discharging (NOI20_discharging) C++14
11 / 100
492 ms 16248 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].f)) {
		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 * id + 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] = {inf,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 296 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 332 KB Output is correct
5 Incorrect 1 ms 332 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 492 ms 16148 KB Output is correct
2 Correct 437 ms 16172 KB Output is correct
3 Correct 447 ms 16168 KB Output is correct
4 Correct 469 ms 16248 KB Output is correct
5 Correct 438 ms 16100 KB Output is correct
6 Correct 447 ms 16064 KB Output is correct
7 Correct 435 ms 16128 KB Output is correct
8 Correct 428 ms 16136 KB Output is correct
9 Correct 436 ms 16068 KB Output is correct
10 Correct 435 ms 16196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 296 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 332 KB Output is correct
5 Incorrect 1 ms 332 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 296 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 332 KB Output is correct
5 Incorrect 1 ms 332 KB Output isn't correct
6 Halted 0 ms 0 KB -