結果
問題 | No.694 square1001 and Permutation 3 |
ユーザー |
|
提出日時 | 2018-06-09 12:41:01 |
言語 | Rust (1.83.0 + proconio) |
結果 |
CE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 10,641 bytes |
コンパイル時間 | 12,563 ms |
コンパイル使用メモリ | 386,948 KB |
最終ジャッジ日時 | 2024-11-14 20:27:27 |
合計ジャッジ時間 | 14,879 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
error: expected one of `:`, `@`, or `|`, found `)` --> src/main.rs:242:29 | 242 | fn lower_bound(&self, &T) -> usize; | ^ expected one of `:`, `@`, or `|` | = note: anonymous parameters are removed in the 2018 edition (see RFC 1685) help: if this is a parameter name, give it a type | 242 | fn lower_bound(&self, T: &TypeName) -> usize; | ~~~~~~~~~~~~ help: if this is a type, explicitly ignore the parameter name | 242 | fn lower_bound(&self, _: &T) -> usize; | ++ error: expected one of `:`, `@`, or `|`, found `)` --> src/main.rs:243:29 | 243 | fn upper_bound(&self, &T) -> usize; | ^ expected one of `:`, `@`, or `|` | = note: anonymous parameters are removed in the 2018 edition (see RFC 1685) help: if this is a parameter name, give it a type | 243 | fn upper_bound(&self, T: &TypeName) -> usize; | ~~~~~~~~~~~~ help: if this is a type, explicitly ignore the parameter name | 243 | fn upper_bound(&self, _: &T) -> usize; | ++ error: could not compile `main` (bin "main") due to 2 previous errors
ソースコード
/*** _ _ __ _ _ _ _ _ _ _* | | | | / / | | (_) | (_) | | (_) | |* | |__ __ _| |_ ___ ___ / /__ ___ _ __ ___ _ __ ___| |_ _| |_ ___ _____ ______ _ __ _ _ ___| |_ ______ ___ _ __ _ _ __ _ __ ___||_ ___* | '_ \ / _` | __/ _ \ / _ \ / / __/ _ \| '_ ` _ \| '_ \ / _ \ __| | __| \ \ / / _ \______| '__| | | / __| __|______/ __| '_ \| | '_ \| '_ \ / _ \__/ __|* | | | | (_| | || (_) | (_) / / (_| (_) | | | | | | |_) | __/ |_| | |_| |\ V / __/ | | | |_| \__ \ |_ \__ \ | | | | |_) | |_) | __/|_\__ \* |_| |_|\__,_|\__\___/ \___/_/ \___\___/|_| |_| |_| .__/ \___|\__|_|\__|_| \_/ \___| |_| \__,_|___/\__| |___/_| |_|_| .__/| .__/\___|\__|___/* | | | | | |* |_| |_| |_|** https://github.com/hatoo/competitive-rust-snippets*/#[allow(unused_imports)]use std::cmp::{max, min, Ordering};#[allow(unused_imports)]use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};#[allow(unused_imports)]use std::io::{stdin, stdout, BufWriter, Write};#[allow(unused_imports)]use std::iter::FromIterator;mod util {use std::fmt::Debug;use std::io::{stdin, stdout, BufWriter, StdoutLock};use std::str::FromStr;#[allow(dead_code)]pub fn line() -> String {let mut line: String = String::new();stdin().read_line(&mut line).unwrap();line.trim().to_string()}#[allow(dead_code)]pub fn chars() -> Vec<char> {line().chars().collect()}#[allow(dead_code)]pub fn gets<T: FromStr>() -> Vec<T>where<T as FromStr>::Err: Debug,{let mut line: String = String::new();stdin().read_line(&mut line).unwrap();line.split_whitespace().map(|t| t.parse().unwrap()).collect()}#[allow(dead_code)]pub fn with_bufwriter<F: FnOnce(BufWriter<StdoutLock>) -> ()>(f: F) {let out = stdout();let writer = BufWriter::new(out.lock());f(writer)}}#[allow(unused_macros)]macro_rules ! get { ( $ t : ty ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . trim () . parse ::<$ t > ( ) . unwrap ( ) } } ; ( $ ( $ t : ty ) ,* ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mutline ) . unwrap ( ) ; let mut iter = line . split_whitespace ( ) ; ( $ ( iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) , ) * ) }} ; ( $ t : ty ; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ ( $ t : ty ) ,*; $ n : expr )=> { ( 0 ..$ n ) . map ( | _ | get ! ( $ ( $ t ) ,* ) ) . collect ::< Vec < _ >> ( ) } ; ( $ t : ty ;; ) => { { let mut line : String = String ::new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . split_whitespace ( ) . map ( | t | t . parse ::<$ t > ( ) . unwrap ( ) ) .collect ::< Vec < _ >> ( ) } } ; ( $ t : ty ;; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ t ;; ) ) . collect ::< Vec < _ >> ( ) } ; }#[allow(unused_macros)]macro_rules ! debug { ( $ ( $ a : expr ) ,* ) => { eprintln ! ( concat ! ( $ ( stringify ! ( $ a ) , " = {:?}, " ) ,* ) , $ ( $ a ) ,* ) ; } }const BIG_STACK_SIZE: bool = true;#[allow(dead_code)]fn main() {use std::thread;if BIG_STACK_SIZE {thread::Builder::new().stack_size(32 * 1024 * 1024).name("solve".into()).spawn(solve).unwrap().join().unwrap();} else {solve();}}#[allow(dead_code)]/// Lazy Segment Treepub struct SEG<T: SEGimpl> {n: usize,buf: Vec<T::Elem>,zero: T::Elem,phantom: std::marker::PhantomData<T>,}impl<T: SEGimpl> SEG<T> {#[allow(dead_code)]pub fn new(n: usize, zero: T::Elem) -> SEG<T> {let n = (1..).map(|i| 1 << i).find(|&x| x >= n).unwrap();SEG {n: n,buf: vec![zero.clone(); 2 * n],zero: zero,phantom: std::marker::PhantomData,}}#[allow(dead_code)]fn eval(&mut self, k: usize, l: usize, r: usize) {if r - l > 1 {let (l, r) = self.buf.split_at_mut(2 * k + 1);let (c1, c2) = r.split_at_mut(1);T::eval(&mut l[k], Some((&mut c1[0], &mut c2[0])));} else {T::eval(&mut self.buf[k], None);}}#[allow(dead_code)]pub fn update(&mut self, i: usize, x: T::Elem) {let mut k = i + self.n - 1;self.buf[k] = x;self.eval(k, i, i + 1);while k > 0 {k = (k - 1) / 2;let (l, r) = self.buf.split_at_mut(2 * k + 1);let (c1, c2) = r.split_at_mut(1);T::reduce(&mut l[k], &c1[0], &c2[0]);}}#[allow(dead_code)]pub fn get(&mut self, i: usize) -> Option<T::R> {self.query(i, i + 1)}#[allow(dead_code)]fn r(&mut self, x: &T::A, a: usize, b: usize, k: usize, l: usize, r: usize) {self.eval(k, l, r);if r <= a || b <= l {return;}if a <= l && r <= b {T::range(x, &mut self.buf[k], l, r);self.eval(k, l, r);return;}self.r(x, a, b, 2 * k + 1, l, (l + r) / 2);self.r(x, a, b, 2 * k + 2, (l + r) / 2, r);let (l, r) = self.buf.split_at_mut(2 * k + 1);let (c1, c2) = r.split_at_mut(1);T::reduce(&mut l[k], &c1[0], &c2[0]);}#[allow(dead_code)]pub fn range_add(&mut self, x: &T::A, a: usize, b: usize) {let n = self.n;self.r(x, a, b, 0, 0, n);}#[allow(dead_code)]pub fn add(&mut self, x: &T::A, i: usize) {self.range_add(x, i, i + 1);}#[allow(dead_code)]fn q(&mut self, a: usize, b: usize, k: usize, l: usize, r: usize) -> Option<T::Elem> {self.eval(k, l, r);if r <= a || b <= l {return None;}if a <= l && r <= b {Some(self.buf[k].clone())} else {let vl = self.q(a, b, k * 2 + 1, l, (l + r) / 2);let vr = self.q(a, b, k * 2 + 2, (l + r) / 2, r);match (vl, vr) {(Some(l), Some(r)) => {let mut res = self.zero.clone();T::reduce(&mut res, &l, &r);Some(res)}(Some(l), None) => Some(l),(None, Some(r)) => Some(r),_ => None,}}}#[allow(dead_code)]pub fn query(&mut self, a: usize, b: usize) -> Option<T::R> {let n = self.n;self.q(a, b, 0, 0, n).map(T::to_result)}}pub trait SEGimpl {type Elem: Clone;type A;type R;fn eval(parent: &mut Self::Elem, children: Option<(&mut Self::Elem, &mut Self::Elem)>);fn range(x: &Self::A, elem: &mut Self::Elem, l: usize, r: usize);fn reduce(parent: &mut Self::Elem, c1: &Self::Elem, c2: &Self::Elem);fn to_result(elem: Self::Elem) -> Self::R;}#[allow(dead_code)]struct RangeAddSum( );impl SEGimpl for RangeAddSum {type Elem = (i64, i64);type A = i64;type R = i64;fn eval(parent: &mut Self::Elem, children: Option<(&mut Self::Elem, &mut Self::Elem)>) {let x = parent.1;parent.0 += x;parent.1 = 0;if let Some((c1, c2)) = children {c1.1 += x / 2;c2.1 += x / 2;}}fn range(x: &Self::A, elem: &mut Self::Elem, l: usize, r: usize) {elem.1 += (r - l) as i64 * x;}fn reduce(parent: &mut Self::Elem, c1: &Self::Elem, c2: &Self::Elem) {parent.0 = c1.0 + c2.0;}fn to_result(elem: Self::Elem) -> Self::R {elem.0}}#[allow(dead_code)]/// Binary Indexed Tree of usizepub struct BIT {buf: Vec<usize>,}#[allow(dead_code)]impl BIT {pub fn new(n: usize) -> BIT {BIT {buf: vec![0; n + 1],}}pub fn sum(&self, i: usize) -> usize {let mut i = i;let mut s = 0;while i > 0 {s += self.buf[i];i &= i - 1;}s}pub fn add(&mut self, i: usize, x: usize) {let mut i = i as i64;while i < self.buf.len() as i64 {self.buf[i as usize] += x;i += i & -i;}}}/// Equivalent to std::lowerbound and std::upperbound in c++pub trait BinarySearch<T> {fn lower_bound(&self, &T) -> usize;fn upper_bound(&self, &T) -> usize;}impl<T: Ord> BinarySearch<T> for [T] {fn lower_bound(&self, x: &T) -> usize {let mut low = 0;let mut high = self.len();while low != high {let mid = (low + high) / 2;match self[mid].cmp(x) {Ordering::Less => {low = mid + 1;}Ordering::Equal | Ordering::Greater => {high = mid;}}}low}fn upper_bound(&self, x: &T) -> usize {let mut low = 0;let mut high = self.len();while low != high {let mid = (low + high) / 2;match self[mid].cmp(x) {Ordering::Less | Ordering::Equal => {low = mid + 1;}Ordering::Greater => {high = mid;}}}low}}fn solve() {let n = get!(usize);let xs = get!(u64; n);let mut cc = xs.clone();cc.sort();cc.dedup();let xs = xs.into_iter().map(|x| cc.binary_search(&x).unwrap()).collect::<Vec<_>>();let mut xss = xs.clone();xss.sort();let mut bit = BIT::new(n);let mut ans = 0;for (i, &x) in xs.iter().enumerate() {ans += i - bit.sum(x + 1);bit.add(x + 1, 1);}util::with_bufwriter(|mut out| {for x in &xs {writeln!(out, "{}", ans).unwrap();ans += n - xss.upper_bound(&x);ans -= xss.lower_bound(&x);}});}