Submission #1675319


Source Code Expand

#![allow(unused_imports, unused_variables, dead_code)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

trait InputValue {
    fn parse(s: &str) -> Self;
}

fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

fn readnc<T: InputValue>() -> Vec<T> {
    let mut vec = vec![];
    let line: String = read();
    for token in line.split_whitespace() {
        vec.push(T::parse(token));
    }
    vec
}

fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

macro_rules! parse_single_value {
    ($($t:ty),*) => {
        $(
            impl InputValue for $t {
                fn parse(s: &str) -> $t { s.parse().unwrap() }
            }
        )*
	}
}
parse_single_value!(i32, i64, f32, f64, usize, String);

macro_rules! parse_tuple {
	($($t:ident),*) => {
		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
			fn parse(s: &str) -> ($($t),*) {
				let mut tokens = s.split_whitespace();
				let t = ($($t::parse(tokens.next().unwrap())),*);
				t
			}
		}
	}
}
parse_tuple!(A, B);
parse_tuple!(A, B, C);

// ===

fn main() {
    let n: usize = read();
    let mut a: Vec<i64> = readnc();

    let mut max = 0;
    let mut inc_set: Vec<(usize, i64)> = vec![];
    inc_set.push((0, 0));

    for i in 0..n {
        if max < a[i] {
            max = a[i];
            inc_set.push((i, a[i]));
        }
    }

    a.sort();
    a.reverse();

    let ln = inc_set.len();
    let mut current = inc_set[ln-1].1;
    let mut head: usize = 0;
    let mut ans = vec![0; n];
    for i in (1..ln).rev() {
        let mut to = inc_set[i-1].1;
        let mut cnt = head as i64 * (inc_set[i].1 - to);
        while head < n && a[head] >= to {
            cnt += a[head] - to;
            head += 1;
        }
        ans[inc_set[i].0] = cnt;
    }

    for i in 0..n {
        println!("{}", ans[i]);
    }
}

Submission Info

Submission Time
Task E - Frequency
User hamadu
Language Rust (1.15.1)
Score 700
Code Size 2118 Byte
Status AC
Exec Time 180 ms
Memory 11512 KB

Compile Error

warning: variable does not need to be mutable, #[warn(unused_mut)] on by default
  --> ./Main.rs:81:9
   |
81 |     let mut current = inc_set[ln-1].1;
   |         ^^^^^^^^^^^

warning: variable does not need to be mutable, #[warn(unused_mut)] on by default
  --> ./Main.rs:85:13
   |
85 |         let mut to = inc_set[i-1].1;
   |             ^^^^^^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 700 / 700
Status
AC × 2
AC × 39
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 AC 2 ms 4352 KB
02.txt AC 13 ms 4352 KB
03.txt AC 2 ms 4352 KB
04.txt AC 3 ms 4352 KB
05.txt AC 2 ms 4352 KB
06.txt AC 2 ms 4352 KB
07.txt AC 2 ms 4352 KB
08.txt AC 2 ms 4352 KB
09.txt AC 17 ms 4352 KB
10.txt AC 2 ms 4352 KB
11.txt AC 176 ms 6524 KB
12.txt AC 174 ms 6524 KB
13.txt AC 174 ms 6524 KB
14.txt AC 175 ms 6524 KB
15.txt AC 176 ms 6524 KB
16.txt AC 174 ms 8444 KB
17.txt AC 177 ms 11512 KB
18.txt AC 172 ms 8444 KB
19.txt AC 165 ms 6524 KB
20.txt AC 174 ms 6524 KB
21.txt AC 2 ms 4352 KB
22.txt AC 2 ms 4352 KB
23.txt AC 2 ms 4352 KB
24.txt AC 13 ms 4352 KB
25.txt AC 2 ms 4352 KB
26.txt AC 3 ms 4352 KB
27.txt AC 2 ms 4352 KB
28.txt AC 175 ms 11512 KB
29.txt AC 175 ms 11512 KB
30.txt AC 173 ms 11512 KB
31.txt AC 177 ms 11512 KB
32.txt AC 180 ms 11512 KB
33.txt AC 175 ms 8444 KB
34.txt AC 174 ms 8444 KB
35.txt AC 173 ms 8444 KB
36.txt AC 171 ms 8444 KB
37.txt AC 171 ms 8444 KB