Submission #1680988


Source Code Expand

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll n, a[200100];
ll pos[200100];

int main() {
	cin >> n;
	rep(i, n) {
		cin >> a[i];
		pos[a[i] - 1] = i;
	}
	ll ans = 0;
	set<ll> sl;
	sl.insert(-1);
	sl.insert(n);
	rep(i, n) {
		set<ll>::iterator it = sl.upper_bound(pos[i]);
		it--;
		set<ll>::iterator it2 = it;
		it++;
		ans += (i + 1)*(pos[i] - *it2)*(*it - pos[i]);
		sl.insert(pos[i]);
	}
	cout << ans << endl;
}

Submission Info

Submission Time
Task B - Minimum Sum
User jimmy
Language C++14 (GCC 5.4.1)
Score 400
Code Size 1302 Byte
Status AC
Exec Time 160 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 143 ms 12800 KB
corner1 AC 151 ms 12800 KB
corner2 AC 1 ms 256 KB
corner3 AC 118 ms 12800 KB
example0 AC 1 ms 256 KB
example1 AC 1 ms 256 KB
example2 AC 1 ms 256 KB
maxrand0 AC 159 ms 12800 KB
maxrand1 AC 160 ms 12800 KB
maxrand2 AC 159 ms 12800 KB
rand0 AC 2 ms 256 KB
rand1 AC 1 ms 256 KB
rand2 AC 1 ms 256 KB