Submission #1295323


Source Code Expand

#include <iostream>
#include <set>
#include <vector>
#include <algorithm>
#define int long long
using namespace std;

typedef pair<int,int> P;

signed main(){
	int n,a[200000],right[200000],num[200000];
	cin >> n;
	vector<P> vec;
	for(int i = 0;i < n;i++) {
		cin >> a[i];
		num[i] = 1;
		vec.push_back(P(a[i],i));
	}
	sort(vec.begin(),vec.end());
	set<int> st;
	st.insert(n);
	for(int i = 0;i < n;i++){
		int pos = vec[i].second;
		right[pos] = *(st.lower_bound(pos)) - pos;
		st.insert(pos);
	}
	int sum = 0;
	for(int i = 0;i < n;i++){
		sum += a[i] * right[i] * num[i];
		num[i + right[i]] += num[i];
	}
	cout << sum << endl;
	return 0;
}

Submission Info

Submission Time
Task B - Minimum Sum
User hoget157
Language C++14 (GCC 5.4.1)
Score 400
Code Size 674 Byte
Status AC
Exec Time 164 ms
Memory 18156 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 142 ms 17388 KB
corner1 AC 138 ms 17388 KB
corner2 AC 2 ms 4352 KB
corner3 AC 131 ms 17644 KB
example0 AC 2 ms 2304 KB
example1 AC 2 ms 4352 KB
example2 AC 2 ms 2304 KB
maxrand0 AC 163 ms 17388 KB
maxrand1 AC 164 ms 18156 KB
maxrand2 AC 163 ms 17388 KB
rand0 AC 2 ms 2304 KB
rand1 AC 2 ms 2304 KB
rand2 AC 2 ms 2304 KB