Submission #62542597
Source Code Expand
use ac_library::{Max, Monoid, Segtree};
#[allow(unused_imports)]
use itertools::Itertools;
use proconio::input;
use proconio::marker::Usize1;
struct Sum;
impl Monoid for Sum {
type S = i64;
fn identity() -> Self::S {
0
}
fn binary_operation(a: &Self::S, b: &Self::S) -> Self::S {
*a + b
}
}
fn main() {
input!{
n: usize,
p: [usize; n],
}
let mut seg: Segtree<Sum> = Segtree::new(n);
for i in 0..n {
seg.set(i, 1);
}
let mut ans = vec![0; n];
for (i, pi) in p.iter().enumerate().rev() {
// 初めてsumがpi以上になるところが答え
// 木上の二分探索
let idx = seg.max_right(0, |&sum| sum < *pi as i64);
seg.set(idx, 0);
ans[idx] = i+1;
}
println!("{}", ans.iter().join(" "));
}
pub trait Debuggable {
fn debug_string(&self) -> String;
}
impl<T: std::fmt::Debug + std::fmt::Display> Debuggable for Vec<T> {
fn debug_string(&self) -> String {
use itertools::Itertools;
use std::iter::repeat;
if let Some(max_size) = self.iter()
.enumerate()
.map(|(i, x)| (format!("{:?}", x).len()).max(format!("{:?}", i).len()))
.max() {
let mut idx = String::from("idx |");
let mut val = String::from("val |");
for (i, xi) in self.iter().enumerate() {
idx.push_str(
&format!(" {:>w$} |", i, w=max_size)
);
val.push_str(
&format!(" {:>w$} |", xi, w=max_size)
);
}
format!("{}\n{}\n{}\n", idx, repeat('-').take(idx.len()).join(""), val)
} else {
format!("idx | \nval |\n")
}
}
}
impl<T: std::fmt::Debug + std::fmt::Display> Debuggable for std::collections::BTreeSet<T> {
fn debug_string(&self) -> String {
use itertools::Itertools;
format!("{{ {} }}", self.iter().join(", "))
}
}
impl<T, U> Debuggable for std::collections::BTreeMap<T, U>
where T: std::fmt::Debug + std::fmt::Display, U: std::fmt::Debug + std::fmt::Display
{
fn debug_string(&self) -> String {
use itertools::Itertools;
format!(
"{{\n{}\n }}", self.iter()
.map(|(k, v)| format!("{k} -> {v}, "))
.join("\n")
)
}
}
// lg! マクロの定義
#[macro_export]
macro_rules! lg {
($val:expr) => {
#[cfg(feature = "local")]
{
{
use Debuggable;
let val = &$val;
eprintln!(
"[{}:{}] {} = \n{}",
file!(),
line!(),
stringify!($val),
val.debug_string()
);
val
}
}
}
}
Submission Info
Submission Time
2025-02-08 21:50:54+0900
Task
F - Insert
User
ardRiriy
Language
Rust (rustc 1.70.0)
Score
500
Code Size
2931 Byte
Status
AC
Exec Time
158 ms
Memory
26208 KiB
Compile Error
warning: unused import: `Max`
--> src/main.rs:1:18
|
1 | use ac_library::{Max, Monoid, Segtree};
| ^^^
|
= note: `#[warn(unused_imports)]` on by default
warning: unused import: `proconio::marker::Usize1`
--> src/main.rs:5:5
|
5 | use proconio::marker::Usize1;
| ^^^^^^^^^^^^^^^^^^^^^^^^
warning: the item `Itertools` is imported redundantly
--> src/main.rs:46:13
|
3 | use itertools::Itertools;
| -------------------- the item `Itertools` is already imported here
...
46 | use itertools::Itertools;
| ^^^^^^^^^^^^^^^^^^^^
warning: the item `Itertools` is imported redundantly
--> src/main.rs:72:13
|
3 | use itertools::Itertools;
| -------------------- the item `Itertools` is already imported here
...
72 | use itertools::Itertools;
| ^^^^^^^^^^^^^^^^^^^^
warning: the item `Itertools` is imported redundantly
--> src/main.rs:81:13
|
3 | use itertools::Itertools;
| -------------------- the item `Itertools` is already imported here
...
81 | use itertools::Itertools;
| ^^^^^^^^^^^^^^^^^^^^
Judge Result
Set Name
Sample
All
Score / Max Score
0 / 0
500 / 500
Status
Set Name
Test Cases
Sample
sample_01.txt, sample_02.txt
All
min.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, sample_01.txt, sample_02.txt
Case Name
Status
Exec Time
Memory
min.txt
AC
0 ms
2020 KiB
random_01.txt
AC
158 ms
25976 KiB
random_02.txt
AC
48 ms
10392 KiB
random_03.txt
AC
156 ms
25972 KiB
random_04.txt
AC
22 ms
6172 KiB
random_05.txt
AC
157 ms
25980 KiB
random_06.txt
AC
64 ms
12496 KiB
random_07.txt
AC
157 ms
25988 KiB
random_08.txt
AC
8 ms
3428 KiB
random_09.txt
AC
83 ms
23844 KiB
random_10.txt
AC
83 ms
23840 KiB
random_11.txt
AC
90 ms
26144 KiB
random_12.txt
AC
88 ms
26208 KiB
random_13.txt
AC
89 ms
26072 KiB
random_14.txt
AC
89 ms
26124 KiB
random_15.txt
AC
114 ms
26136 KiB
random_16.txt
AC
116 ms
26048 KiB
sample_01.txt
AC
1 ms
2084 KiB
sample_02.txt
AC
0 ms
2072 KiB