Submission #1498828
Source Code Expand
#include <cstdio> #include <algorithm> using namespace std; int st[200010], dr[200010], v[200010], eg[200010]; int main () { int n; scanf ("%d", &n); int lst = 0, ldr = 0; for (int i = 1; i <= n; ++i) { scanf ("%d", &v[i]); for (; lst > 0 && v[i] < v[st[lst]]; --lst); st[++lst] = i; eg[i] = st[lst - 1]; } dr[0] = n + 1; long long rez = 0LL; for (int i = n; i; --i) { for (; ldr > 0 && v[i] < v[dr[ldr]]; --ldr); dr[++ldr] = i; int g = dr[ldr - 1]; eg[i] = i - eg[i]; g = g - i; rez += 1LL * eg[i] * g * v[i]; } printf ("%lld\n", rez); return 0; }
Submission Info
Submission Time | |
---|---|
Task | B - Minimum Sum |
User | Theodor1000 |
Language | C++14 (GCC 5.4.1) |
Score | 400 |
Code Size | 737 Byte |
Status | AC |
Exec Time | 24 ms |
Memory | 2560 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:11:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf ("%d", &n); ^ ./Main.cpp:16:28: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf ("%d", &v[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 | 21 ms | 2560 KB |
corner1 | AC | 20 ms | 2560 KB |
corner2 | AC | 0 ms | 128 KB |
corner3 | AC | 23 ms | 2560 KB |
example0 | AC | 0 ms | 128 KB |
example1 | AC | 0 ms | 128 KB |
example2 | AC | 0 ms | 128 KB |
maxrand0 | AC | 24 ms | 1664 KB |
maxrand1 | AC | 24 ms | 1664 KB |
maxrand2 | AC | 24 ms | 1664 KB |
rand0 | AC | 1 ms | 128 KB |
rand1 | AC | 0 ms | 128 KB |
rand2 | AC | 0 ms | 128 KB |