Submission #1354618


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int n, a[200010];

const int sz = 262144;
struct Seg{
	int dat[2 * sz];
	void ini(){
		for(int i = sz; i < sz + n; i++) dat[i] = i - sz + 1;
		for(int i = sz - 1; i >= 1; i--){
			if(a[dat[2 * i]] < a[dat[2 * i + 1]]) dat[i] = dat[2 * i];
			else dat[i] = dat[2 * i + 1];
		}
	}
	int get(int s, int e){
		int ret = 0;
		for(s += sz - 1, e += sz - 1; s <= e; s /= 2, e /= 2){
			if(s % 2 == 1){
				if(a[ret] > a[dat[s]]) ret = dat[s];
				s++;
			}
			if(e % 2 == 0){
				if(a[ret] > a[dat[e]]) ret = dat[e];
				e--;
			}
		}
		return ret;
	}
} S;

ll f(int s, int e){
	if(s > e) return 0;
	int mi = S.get(s, e);
	return 1LL * (mi - s + 1) * (e + 1 - mi) * a[mi] + f(s, mi - 1) + f(mi + 1, e);
}

int main(){
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) scanf("%d", a + i);
	a[0] = n + 1;
	S.ini();
	printf("%lld\n", f(1, n));
}

Submission Info

Submission Time
Task B - Minimum Sum
User kdh9949
Language C++14 (GCC 5.4.1)
Score 400
Code Size 944 Byte
Status AC
Exec Time 45 ms
Memory 18432 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:40:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
                 ^
./Main.cpp:41:48: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  for(int i = 1; i <= n; i++) scanf("%d", a + i);
                                                ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 13
Set Name Test Cases
Sample example0, example1, example2
All corner0, corner1, corner2, corner3, example0, example1, example2, maxrand0, maxrand1, maxrand2, rand0, rand1, rand2
Case Name Status Exec Time Memory
corner0 AC 38 ms 2816 KB
corner1 AC 43 ms 18432 KB
corner2 AC 2 ms 1280 KB
corner3 AC 45 ms 10624 KB
example0 AC 2 ms 1280 KB
example1 AC 2 ms 1280 KB
example2 AC 2 ms 1280 KB
maxrand0 AC 29 ms 2816 KB
maxrand1 AC 29 ms 2816 KB
maxrand2 AC 29 ms 2816 KB
rand0 AC 2 ms 1280 KB
rand1 AC 2 ms 1280 KB
rand2 AC 2 ms 1280 KB