Submission #1163142


Source Code Expand

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

const int N = 202020;
int a[N], pr[N], ne[N], pos[N];

int main()
{
	int n;
	cin >> n;
	for (int i = 1; i <= n; ++i){
		cin >> a[i];
		pos[a[i]] = i;
	}

	for (int i = 0; i <= n + 1; ++i){
		pr[i] = i - 1;
		ne[i] = i + 1;
	}

	long long ans = 0;
	for (int i = n; i >= 1; i--){
		int j = pos[i];
		ans += i * 1ll * (j - pr[j]) * (ne[j] - j);
		pr[ne[j]] = pr[j];
		ne[pr[j]] = ne[j];
	}

	cout << ans << endl;
}

Submission Info

Submission Time
Task B - Minimum Sum
User Luzhiled
Language C++14 (GCC 5.4.1)
Score 400
Code Size 489 Byte
Status AC
Exec Time 79 ms
Memory 3328 KB

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 77 ms 3328 KB
corner1 AC 78 ms 3328 KB
corner2 AC 1 ms 256 KB
corner3 AC 77 ms 3328 KB
example0 AC 1 ms 256 KB
example1 AC 1 ms 256 KB
example2 AC 1 ms 256 KB
maxrand0 AC 79 ms 3328 KB
maxrand1 AC 78 ms 3328 KB
maxrand2 AC 79 ms 3328 KB
rand0 AC 1 ms 256 KB
rand1 AC 1 ms 256 KB
rand2 AC 1 ms 256 KB