Submission #1475168


Source Code Expand

#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N; cin >> N;
	vector<int> pos(N);
	vector<int> a(N); rep(i, 0, N) {
		cin >> a[i]; a[i]--;
		pos[a[i]] = i;
	}
	set<int> st;
	st.insert(-1); st.insert(N);
	int ans = 0;
	rep(k, 0, N) {
		auto res = st.insert(pos[k]);
		set<int>::iterator l, r;
		l = r = res.first;
		l--; r++;
		ans += (k + 1)*(pos[k] - *l)*(*r - pos[k]);
	}
	cout << ans << endl;
	return 0;
}

Submission Info

Submission Time
Task B - Minimum Sum
User minaminao
Language C++14 (GCC 5.4.1)
Score 400
Code Size 1038 Byte
Status AC
Exec Time 91 ms
Memory 12800 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 65 ms 12800 KB
corner1 AC 66 ms 12800 KB
corner2 AC 1 ms 256 KB
corner3 AC 56 ms 12800 KB
example0 AC 1 ms 256 KB
example1 AC 1 ms 256 KB
example2 AC 1 ms 256 KB
maxrand0 AC 91 ms 12800 KB
maxrand1 AC 91 ms 12800 KB
maxrand2 AC 91 ms 12800 KB
rand0 AC 1 ms 256 KB
rand1 AC 1 ms 256 KB
rand2 AC 1 ms 256 KB