Submission #1698022


Source Code Expand

//2017-10-22
//miaomiao
//
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>

using namespace std;

#define LL long long
#define For(i, a, b) for(int i = (a); i <= (int)(b); ++i)
#define Forr(i, a, b) for(int i = (a); i >= (int)(b); --i)

#define N (200000+5)

int n, a[N], bl[N], br[N];
int tp, st[N];

void Init(){
	For(i, 1, n){
		while(tp && a[st[tp]] > a[i]) --tp;
		bl[i] = tp? st[tp]+1: 1; st[++tp] = i;
	}

	tp = 0;
	Forr(i, n, 1){
		while(tp && a[st[tp]] > a[i]) --tp;
		br[i] = tp? st[tp]-1: n; st[++tp] = i;
	}
}

int main(){
	scanf("%d", &n);
	For(i, 1, n) scanf("%d", &a[i]);
	
	Init();

	int ml, mr;
	LL ans = 0;
	For(i, 1, n){
//		printf("bl[%d] = %d br[%d] = %d\n", i, bl[i], i, br[i]);
		ml = i - bl[i] + 1; mr = br[i] - (i-1);
//		printf("ml = %d mr = %d\n", ml, mr);
		
		ans += 1ll * ml * mr * a[i];
	}
	printf("%lld\n", ans);

	return 0;
}

Submission Info

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

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:36:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
                 ^
./Main.cpp:37:33: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  For(i, 1, n) 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 23 ms 3328 KB
corner1 AC 23 ms 3328 KB
corner2 AC 1 ms 256 KB
corner3 AC 25 ms 2944 KB
example0 AC 1 ms 256 KB
example1 AC 1 ms 256 KB
example2 AC 1 ms 256 KB
maxrand0 AC 26 ms 2560 KB
maxrand1 AC 26 ms 2560 KB
maxrand2 AC 27 ms 2560 KB
rand0 AC 1 ms 256 KB
rand1 AC 1 ms 256 KB
rand2 AC 1 ms 256 KB