Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
#include
using namespace std; const int mxN = 1e5; typedef long long ll; ll st[mxN+1], l[mxN+1], r[mxN+1], v[mxN+1]; int main() { ll sol = 0, n, top = 0 ; cin>>n; for(int i = 1;i<=n;i++) { cin>>v[i]; while(top > 0 && v[st[top]] < v[i]) r[st[top]] = i, top--; st[++top] = i; } while(top>0) r[st[top]] = n+1, top--; for(int i = n;i>0;i--) { while(top > 0 && v[st[top]] < v[i]) l[st[top]] = i, top--; st[++top] = i; } for(int i = 1;i<=n;i++) { ll A = i - l[i]; ll B = r[i] - i; sol+= v[i] * A*B; } cout<
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)