Submission #2379124
Source Code Expand
void main(){ import std.stdio, std.string, std.conv, std.algorithm; int n; rd(n); auto a=readln.split.to!(int[]); auto pos=new int[](n+1); foreach(int i; 0..n) pos[a[i]]=(i+1); import std.container; auto rbt=new RedBlackTree!(int, "a<b"); rbt.insert(0); rbt.insert(n+1); long sum=0; for(int v=1; v<=n; v++){ int i=pos[v]; long l=rbt.lowerBound(i).back, r=rbt.upperBound(i).front; sum+=(i-l).to!(long)*(r-i).to!(long)*v; rbt.insert(i); } writeln(sum); } void rd(T...)(ref T x){ import std.stdio, std.string, std.conv; auto l=readln.split; assert(l.length==x.length); foreach(i, ref e; x){ e=l[i].to!(typeof(e)); } }
Submission Info
Submission Time | |
---|---|
Task | B - Minimum Sum |
User | ikd |
Language | D (DMD64 v2.070.1) |
Score | 400 |
Code Size | 711 Byte |
Status | AC |
Exec Time | 195 ms |
Memory | 19984 KB |
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 | 194 ms | 19984 KB |
corner1 | AC | 195 ms | 18576 KB |
corner2 | AC | 1 ms | 256 KB |
corner3 | AC | 115 ms | 18320 KB |
example0 | AC | 1 ms | 256 KB |
example1 | AC | 1 ms | 256 KB |
example2 | AC | 1 ms | 256 KB |
maxrand0 | AC | 146 ms | 18704 KB |
maxrand1 | AC | 147 ms | 18576 KB |
maxrand2 | AC | 150 ms | 19216 KB |
rand0 | AC | 1 ms | 256 KB |
rand1 | AC | 1 ms | 256 KB |
rand2 | AC | 1 ms | 256 KB |