Submission #1481037
Source Code Expand
#include <bits/stdc++.h>
#define FI(i,a,b) for(int i=(a);i<=(b);i++)
#define FD(i,a,b) for(int i=(a);i>=(b);i--)
#define LL long long
#define Ldouble long double
#define PI 3.14159265358979323846264338327950288419
#define PII pair<int,int>
#define PLL pair<LL,LL>
#define mp make_pair
#define fi first
#define se second
using namespace std;
int n, s[200005], l[200005], r[200005];
LL ans;
int stk[200005], p;
int main(){
scanf("%d", &n);
FI(i, 1, n) scanf("%d", &s[i]);
FI(i, 1, n){
while(p > 0 && s[stk[p]] > s[i]) p--;
if(p == 0) l[i] = i;
else l[i] = i - stk[p];
stk[++p] = i;
}
p = 0;
FD(i, n, 1){
while(p > 0 && s[stk[p]] > s[i]) p--;
if(p == 0) r[i] = n - i + 1;
else r[i] = stk[p] - i;
stk[++p] = i;
}
// FI(i, 1, n) printf("%d: %d %d\n", i, l[i], r[i]);
FI(i, 1, n) ans += 1LL * s[i] * l[i] * r[i];
printf("%lld\n", ans);
return 0;
}
Submission Info
Submission Time |
|
Task |
B - Minimum Sum |
User |
alex20030190 |
Language |
C++14 (GCC 5.4.1) |
Score |
400 |
Code Size |
916 Byte |
Status |
AC |
Exec Time |
26 ms |
Memory |
3328 KB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:24:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
^
./Main.cpp:25:32: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
FI(i, 1, n) scanf("%d", &s[i]);
^
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
400 / 400 |
Status |
|
|
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 |
22 ms |
3328 KB |
corner1 |
AC |
22 ms |
3328 KB |
corner2 |
AC |
1 ms |
256 KB |
corner3 |
AC |
24 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 |
26 ms |
2560 KB |
rand0 |
AC |
1 ms |
256 KB |
rand1 |
AC |
1 ms |
256 KB |
rand2 |
AC |
1 ms |
256 KB |