Submission #1662761
Source Code Expand
use std::io::{stdin, Read, StdinLock}; use std::str::FromStr; fn main(){ let cin = stdin(); let cin = cin.lock(); let mut sc = Scanner::new(cin); while let Some(n) = sc.read1() { let mut xs = vec![]; for _ in 0..n { let x: i64 = sc.read(); xs.push(x); } let xs = xs; // calculate ascending subsequence let mut ascending = vec![(0, std::usize::MAX)]; for (i, &x) in xs.iter().enumerate() { if x > ascending.last().unwrap().0 { ascending.push((x, i)); } } let k = ascending.len(); let mut res = vec![0; n]; let mut partial_sum = vec![0; k]; for x in xs { // binary search... let mut lo = 0; let mut hi = k; while hi - lo > 1 { let mid = (lo + hi) / 2; if x < ascending[mid].0 { hi = mid; } else { lo = mid; } } assert!(ascending[lo].0 <= x); assert!(hi == k || x < ascending[hi].0); res[ascending[lo].1] += x - ascending[lo].0; if lo > 0 { partial_sum[lo - 1] += 1; } } for j in (1..k).rev() { partial_sum[j - 1] += partial_sum[j]; } for j in 1..k { let gain = partial_sum[j - 1] * (ascending[j].0 - ascending[j - 1].0); res[ascending[j].1] += gain; } for r in res { println!("{}", r); } } } //============================================================================= struct Scanner<'a> { cin: StdinLock<'a>, } impl<'a> Scanner<'a> { fn new(cin: StdinLock<'a>) -> Scanner<'a> { Scanner { cin: cin } } fn read1<T: FromStr>(&mut self) -> Option<T> { let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char) .skip_while(|c| c.is_whitespace()) .take_while(|c| !c.is_whitespace()) .collect::<String>(); token.parse::<T>().ok() } fn read<T: FromStr>(&mut self) -> T { self.read1().unwrap() } }
Submission Info
Submission Time | |
---|---|
Task | E - Frequency |
User | ir5 |
Language | Rust (1.15.1) |
Score | 0 |
Code Size | 2320 Byte |
Status | RE |
Exec Time | 215 ms |
Memory | 11004 KB |
Judge Result
Set Name | Sample | All | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 700 | ||||||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | 00_example_01.txt, 00_example_02.txt |
All | 00_example_01.txt, 00_example_02.txt, 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
00_example_01.txt | AC | 2 ms | 4352 KB |
00_example_02.txt | AC | 2 ms | 4352 KB |
01.txt | RE | 2 ms | 4352 KB |
02.txt | RE | 3 ms | 4352 KB |
03.txt | RE | 2 ms | 4352 KB |
04.txt | RE | 2 ms | 4352 KB |
05.txt | RE | 2 ms | 4352 KB |
06.txt | RE | 2 ms | 4352 KB |
07.txt | RE | 2 ms | 4352 KB |
08.txt | RE | 2 ms | 4352 KB |
09.txt | RE | 4 ms | 4352 KB |
10.txt | RE | 2 ms | 4352 KB |
11.txt | RE | 22 ms | 6396 KB |
12.txt | RE | 23 ms | 6396 KB |
13.txt | RE | 22 ms | 6396 KB |
14.txt | RE | 22 ms | 6396 KB |
15.txt | WA | 183 ms | 6524 KB |
16.txt | AC | 199 ms | 6524 KB |
17.txt | AC | 215 ms | 11004 KB |
18.txt | RE | 34 ms | 6396 KB |
19.txt | AC | 169 ms | 6524 KB |
20.txt | RE | 19 ms | 6396 KB |
21.txt | AC | 2 ms | 4352 KB |
22.txt | AC | 2 ms | 4352 KB |
23.txt | WA | 2 ms | 4352 KB |
24.txt | WA | 14 ms | 4352 KB |
25.txt | WA | 2 ms | 4352 KB |
26.txt | WA | 3 ms | 4352 KB |
27.txt | WA | 2 ms | 4352 KB |
28.txt | WA | 198 ms | 9212 KB |
29.txt | WA | 201 ms | 9212 KB |
30.txt | WA | 196 ms | 9212 KB |
31.txt | WA | 195 ms | 9212 KB |
32.txt | WA | 198 ms | 9212 KB |
33.txt | RE | 28 ms | 6396 KB |
34.txt | RE | 29 ms | 6396 KB |
35.txt | RE | 28 ms | 6396 KB |
36.txt | RE | 29 ms | 6396 KB |
37.txt | RE | 28 ms | 6396 KB |