Submission #50257081


Source Code Expand

// -*- coding:utf-8-unix -*-
/*
このコード、と~おれ!
  ∧_∧ 
(。・ω・。)つ━☆・*。
⊂    ノ       ・゜+.
 しーJ       °。+ *´¨)
                  .· ´¸.·*´¨) ¸.·*¨)
                                      (¸.·´ (¸.·'* ☆
*/

#[allow(unused_imports)]
use ac_library::*;
use itertools::Itertools;
use proconio::input;
use proconio::marker::Chars;
use std::collections::{BinaryHeap, VecDeque};



static INF: usize = 1e18 as usize;

trait Vector<T> {
    fn insertion_sort(&mut self, elem: T);
    fn print_continuous(&self);
    fn print_space_separate(&self);
    fn print_linebreak(&self);
}

impl<T: std::cmp::Ord  + std::fmt::Display> Vector<T> for Vec<T> {
    fn insertion_sort(&mut self, elem: T) { let idx = self.binary_search(&elem).unwrap_or_else(|x| x); self.insert(idx, elem); }
    fn print_continuous(&self) { for i in 0..self.len() { print!("{}", self[i]); } println!() }
    fn print_space_separate(&self) { for i in 0..self.len() { print!("{}", self[i]); if i != self.len()-1 { print!(" ") } } println!() }
    fn print_linebreak(&self) { for i in 0..self.len() { println!("{}", self[i]); } }
}

use num_traits::{FromPrimitive, Num, NumCast};
struct BIT<T> {
    n: usize, // 配列の要素数
    bit: Vec<Vec<T>>, // データを持つ。1-indexedで、初期値は0となる。
}

impl<T> BIT<T> where T: Num + Clone + std::ops::Neg<Output = T> + NumCast + FromPrimitive {
    fn new(size: usize) -> BIT<T>{
        let v = vec![vec![T::zero(); size+1]; 2];
        BIT{ n: size+1, bit: v}
    }

    //[l, r)にxを追加
    fn add(&mut self, l: usize, r: usize, x: T) {
        self._add_sub(0, l, -x.clone() * NumCast::from(l - 1).unwrap());
        self._add_sub(0, r, x.clone() * NumCast::from(r - 1).unwrap());
        self._add_sub(1, l, x.clone());
        self._add_sub(1, r, -x.clone());
    }

    fn _add_sub(&mut self, p: usize, i: usize, x: T) {
        let mut idx = i;
        while idx < self.n {
            self.bit[p][idx] = self.bit[p][idx].clone() + x.clone();

            idx += (idx as isize & (idx as isize * -1)) as usize;
        }
    }

    fn sum(&self, i: usize) -> T { self._sum_sub(0, i) + self._sum_sub(1, i) * NumCast::from(i).unwrap() }

    fn _sum_sub(&self, p: usize, i: usize) -> T{
        let mut s :T = T::zero();
        let mut idx = i;
        while idx > 0 {
            s = s + self.bit[p][idx].clone();
            idx -= (idx as isize & (idx as isize * -1)) as usize;
        }
        s
    }

}

fn solve() {
    input! {
        n: usize,
        m: usize,
        a: [isize; n],
        b: [usize; m]
    }

    let mut bit = BIT::new(n);

    for i in 0..n {
        bit.add(i+1, i+2, a[i]);
    }


    for &x in &b {
        let v = bit.sum(x+1) - bit.sum(x);
        let kubaru = v / n as isize;
        bit.add(x+1, x+2, -v);
        bit.add(1, n+1, kubaru);

        let l = x+2;
        let r = (x + 1 + (v % n as isize) as usize) % n + 1;
        if l <= r {
            bit.add(l, r, 1);
        }else{
            bit.add(l, n+1, 1);
            bit.add(1, r, 1);
        }
    }

    for i in 0..n {
        if i != n-1 {
            print!("{} ", bit.sum(i+1) - bit.sum(i));
        }else{
           println!("{}", bit.sum(i+1) - bit.sum(i));
        }
    }

}

fn main() {
    // input! { i: usize }
    let mut i = 1;
    while i != 0 { solve(); i -= 1; }
}



Submission Info

Submission Time
Task E - Mancala 2
User ardRiriy
Language Rust (rustc 1.70.0)
Score 475
Code Size 3408 Byte
Status AC
Exec Time 85 ms
Memory 12156 KiB

Compile Error

warning: unused import: `itertools::Itertools`
  --> src/main.rs:14:5
   |
14 | use itertools::Itertools;
   |     ^^^^^^^^^^^^^^^^^^^^
   |
   = note: `#[warn(unused_imports)]` on by default

warning: unused import: `proconio::marker::Chars`
  --> src/main.rs:16:5
   |
16 | use proconio::marker::Chars;
   |     ^^^^^^^^^^^^^^^^^^^^^^^

warning: unused imports: `BinaryHeap`, `VecDeque`
  --> src/main.rs:17:24
   |
17 | use std::collections::{BinaryHeap, VecDeque};
   |                        ^^^^^^^^^^  ^^^^^^^^

warning: static `INF` is never used
  --> src/main.rs:21:8
   |
21 | static INF: usize = 1e18 as usize;
   |        ^^^
   |
   = note: `#[warn(dead_code)]` on by default

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 475 / 475
Status
AC × 3
AC × 35
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All 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, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, random_31.txt, random_32.txt, sample_01.txt, sample_02.txt, sample_03.txt
Case Name Status Exec Time Memory
random_01.txt AC 17 ms 3804 KiB
random_02.txt AC 24 ms 3976 KiB
random_03.txt AC 15 ms 3096 KiB
random_04.txt AC 1 ms 2048 KiB
random_05.txt AC 23 ms 4064 KiB
random_06.txt AC 25 ms 4056 KiB
random_07.txt AC 12 ms 3372 KiB
random_08.txt AC 8 ms 2516 KiB
random_09.txt AC 24 ms 3924 KiB
random_10.txt AC 22 ms 3968 KiB
random_11.txt AC 14 ms 3456 KiB
random_12.txt AC 3 ms 2112 KiB
random_13.txt AC 84 ms 11856 KiB
random_14.txt AC 58 ms 7528 KiB
random_15.txt AC 52 ms 10164 KiB
random_16.txt AC 29 ms 4244 KiB
random_17.txt AC 85 ms 11812 KiB
random_18.txt AC 74 ms 9712 KiB
random_19.txt AC 57 ms 10384 KiB
random_20.txt AC 63 ms 8140 KiB
random_21.txt AC 82 ms 11792 KiB
random_22.txt AC 75 ms 10044 KiB
random_23.txt AC 62 ms 10632 KiB
random_24.txt AC 64 ms 10364 KiB
random_25.txt AC 1 ms 1932 KiB
random_26.txt AC 0 ms 1756 KiB
random_27.txt AC 78 ms 12156 KiB
random_28.txt AC 38 ms 5244 KiB
random_29.txt AC 55 ms 7940 KiB
random_30.txt AC 23 ms 4016 KiB
random_31.txt AC 23 ms 4076 KiB
random_32.txt AC 23 ms 3936 KiB
sample_01.txt AC 0 ms 2088 KiB
sample_02.txt AC 0 ms 2100 KiB
sample_03.txt AC 0 ms 1952 KiB