QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#659366 | #9482. Count Pseudo-Palindromes | ucup-team296# | AC ✓ | 997ms | 327784kb | Rust | 28.7kb | 2024-10-19 19:50:20 | 2024-10-19 19:50:21 |
Judging History
answer
//
pub mod solution {
//{"name":"g","group":"Manual","url":"","interactive":false,"timeLimit":2000,"tests":[{"input":"","output":""},{"input":"","output":""},{"input":"","output":""},{"input":"","output":""}],"testType":"single","input":{"type":"stdin","fileName":null,"pattern":null},"output":{"type":"stdout","fileName":null,"pattern":null},"languages":{"java":{"taskClass":"g"}}}
use std::collections::BTreeSet;
use std::collections::HashMap;
#[allow(unused)]
use crate::dbg;
use crate::algo_lib::io::input::Input;
use crate::algo_lib::io::output::Output;
use crate::algo_lib::misc::binary_search::binary_search_first_true;
use crate::algo_lib::misc::rand::Random;
use crate::algo_lib::misc::vec_apply_delta::ApplyDelta;
use crate::algo_lib::seg_trees::fenwick::Fenwick;
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
struct Event {
left: usize,
start: bool,
value: usize,
}
fn solve_case(a: &[usize]) -> Vec<i64> {
let n = a.len() / 2;
let mut singles = BTreeSet::new();
let mut positions = vec![vec![]; n];
for i in 0..a.len() {
positions[a[i]].push(i);
}
let mut events = vec![vec![]; a.len() + 1];
for left in (0..a.len()).rev() {
let x = a[left];
if positions[x][0] == left {
let second = positions[x][1];
singles.remove(&second);
} else {
singles.insert(left);
}
let mut iter = singles.iter();
if let Some(&first) = iter.next() {
let mut second = a.len();
if let Some(&second_) = iter.next() {
second = second_;
}
events[first].push(Event {
left,
start: true,
value: first,
});
events[second].push(Event {
left,
start: false,
value: first,
});
}
}
let mut rnd = Random::new(123123);
let mut hashes = vec![0; n];
for i in 0..n {
hashes[i] = rnd.gen_u64();
}
let mut by_hash = HashMap::<u64, Vec<usize>>::new();
let mut res = vec![0; a.len()];
assert!(singles.is_empty());
let mut who = vec![None; a.len()];
let mut cur_hash = 0;
let mut pref_hashes = vec![0; a.len() + 1];
by_hash.entry(0).or_default().push(0);
let mut fenw = Fenwick::<i64>::new(a.len() + 1);
for right in 0..a.len() {
let x = a[right];
cur_hash ^= hashes[x];
if positions[x][0] == right {
singles.insert(right);
} else {
singles.remove(&positions[x][0]);
}
for ev in events[right].iter() {
if ev.start {
assert!(who[ev.left].is_none());
who[ev.left] = Some(ev.value);
res[ev.value] -= fenw.get_sum(ev.left);
} else {
who[ev.left] = None;
res[ev.value] += fenw.get_sum(ev.left);
}
}
let mut iter = singles.iter();
let first = iter.next_back();
let start_from = if let Some(&first) = first {
first + 1
} else {
0
};
fenw.add(start_from, 1);
fenw.add(right + 1, -1);
// for left in start_from..=right {
// if let Some(who) = who[left] {
// res[who] += 1;
// }
// }
if let Some(&first) = first {
let mut cur_start_from = 0;
if let Some(second) = iter.next_back() {
cur_start_from = second + 1;
}
let need_hash = cur_hash ^ hashes[a[first]];
if let Some(vec) = by_hash.get(&need_hash) {
let first_ok = binary_search_first_true(0..vec.len(), |i| vec[i] >= cur_start_from);
res[first] += (vec.len() - first_ok) as i64;
// for &left in vec.iter() {
// if left >= cur_start_from {
// res[first] += 1;
// }
// }
}
// for left in cur_start_from..=first {
// if pref_hashes[left] == need_hash {
// res[first] += 1;
// }
// }
}
by_hash.entry(cur_hash).or_default().push(right + 1);
pref_hashes[right + 1] = cur_hash;
}
for ev in events[a.len()].iter() {
if ev.start {
assert!(who[ev.left].is_none());
who[ev.left] = Some(ev.value);
res[ev.value] -= fenw.get_sum(ev.left);
} else {
who[ev.left] = None;
res[ev.value] += fenw.get_sum(ev.left);
}
}
res
}
fn solve_slow(a: &[usize]) -> Vec<i64> {
let mut res = vec![0; a.len()];
let mut rnd = Random::new(345345);
let mut hashes = vec![0; a.len()];
for i in 0..a.len() {
hashes[i] = rnd.gen_u64();
}
for mid in 0..a.len() {
for left in 0..=mid {
for right in mid + 1..=a.len() {
let mut cur_hash = 0;
for i in left..right {
cur_hash ^= hashes[a[i]];
}
if cur_hash == hashes[a[mid]] {
res[mid] += 1;
}
}
}
}
res
}
fn stress() {
for it in 1.. {
dbg!(it);
let mut rnd = Random::new(it);
let n = rnd.gen(1..100000);
let mut a = vec![0; n * 2];
for i in 0..n {
a[i] = i;
a[i + n] = i;
}
rnd.shuffle(&mut a);
let my = solve_case(&a);
// let slow = solve_slow(&a);
// // dbg!(my);
// if my != slow {
// dbg!(a);
// dbg!(my);
// dbg!(slow);
// assert_eq!(my, slow);
// }
}
}
fn solve(input: &mut Input, out: &mut Output, _test_case: usize) {
let n = input.usize();
let a = input.vec::<usize>(n * 2).sub_from_all(1);
let res = solve_case(&a);
out.println(res);
}
pub(crate) fn run(mut input: Input, mut output: Output) -> bool {
solve(&mut input, &mut output, 1);
output.flush();
true
}
}
pub mod algo_lib {
pub mod io {
pub mod input {
use std::fmt::Debug;
use std::io::Read;
use std::marker::PhantomData;
use std::path::Path;
use std::str::FromStr;
pub struct Input {
input: Box<dyn Read>,
buf: Vec<u8>,
at: usize,
buf_read: usize,
}
macro_rules! read_integer_fun {
($t:ident) => {
#[allow(unused)]
pub fn $t(&mut self) -> $t {
self.read_integer()
}
};
}
impl Input {
const DEFAULT_BUF_SIZE: usize = 4096;
///
/// Using with stdin:
/// ```no_run
/// use algo_lib::io::input::Input;
/// let stdin = std::io::stdin();
/// let input = Input::new(Box::new(stdin));
/// ```
///
/// For read files use ``new_file`` instead.
///
///
pub fn new(input: Box<dyn Read>) -> Self {
Self {
input,
buf: vec![0; Self::DEFAULT_BUF_SIZE],
at: 0,
buf_read: 0,
}
}
pub fn new_stdin() -> Self {
let stdin = std::io::stdin();
Self::new(Box::new(stdin))
}
pub fn new_file<P: AsRef<Path>>(path: P) -> Self {
let file = std::fs::File::open(&path)
.unwrap_or_else(|_| panic!("Can't open file: {:?}", path.as_ref().as_os_str()));
Self::new(Box::new(file))
}
pub fn new_with_size(input: Box<dyn Read>, buf_size: usize) -> Self {
Self {
input,
buf: vec![0; buf_size],
at: 0,
buf_read: 0,
}
}
pub fn new_file_with_size<P: AsRef<Path>>(path: P, buf_size: usize) -> Self {
let file = std::fs::File::open(&path)
.unwrap_or_else(|_| panic!("Can't open file: {:?}", path.as_ref().as_os_str()));
Self::new_with_size(Box::new(file), buf_size)
}
pub fn get(&mut self) -> Option<u8> {
if self.refill_buffer() {
let res = self.buf[self.at];
self.at += 1;
Some(res)
} else {
None
}
}
pub fn peek(&mut self) -> Option<u8> {
if self.refill_buffer() {
Some(self.buf[self.at])
} else {
None
}
}
pub fn skip_whitespace(&mut self) {
while let Some(b) = self.peek() {
if !char::from(b).is_whitespace() {
return;
}
self.get();
}
}
pub fn next_token(&mut self) -> Option<Vec<u8>> {
self.skip_whitespace();
let mut res = Vec::new();
while let Some(c) = self.get() {
if char::from(c).is_whitespace() {
break;
}
res.push(c);
}
if res.is_empty() {
None
} else {
Some(res)
}
}
//noinspection RsSelfConvention
pub fn is_exhausted(&mut self) -> bool {
self.peek().is_none()
}
pub fn has_more_elements(&mut self) -> bool {
!self.is_exhausted()
}
pub fn read<T: Readable>(&mut self) -> T {
T::read(self)
}
pub fn vec<T: Readable>(&mut self, size: usize) -> Vec<T> {
let mut res = Vec::with_capacity(size);
for _ in 0usize..size {
res.push(self.read());
}
res
}
pub fn string_vec(&mut self, size: usize) -> Vec<Vec<u8>> {
let mut res = Vec::with_capacity(size);
for _ in 0usize..size {
res.push(self.string());
}
res
}
pub fn read_line(&mut self) -> String {
let mut res = String::new();
while let Some(c) = self.get() {
if c == b'\n' {
break;
}
if c == b'\r' {
if self.peek() == Some(b'\n') {
self.get();
}
break;
}
res.push(c.into());
}
res
}
#[allow(clippy::should_implement_trait)]
pub fn into_iter<T: Readable>(self) -> InputIterator<T> {
InputIterator {
input: self,
phantom: Default::default(),
}
}
fn read_integer<T: FromStr + Debug>(&mut self) -> T
where
<T as FromStr>::Err: Debug,
{
let res = self.read_string();
res.parse::<T>().unwrap()
}
fn read_string(&mut self) -> String {
match self.next_token() {
None => {
panic!("Input exhausted");
}
Some(res) => unsafe { String::from_utf8_unchecked(res) },
}
}
pub fn string_as_string(&mut self) -> String {
self.read_string()
}
pub fn string(&mut self) -> Vec<u8> {
self.read_string().into_bytes()
}
fn read_char(&mut self) -> char {
self.skip_whitespace();
self.get().unwrap().into()
}
fn read_float(&mut self) -> f64 {
self.read_string().parse().unwrap()
}
pub fn f64(&mut self) -> f64 {
self.read_float()
}
fn refill_buffer(&mut self) -> bool {
if self.at == self.buf_read {
self.at = 0;
self.buf_read = self.input.read(&mut self.buf).unwrap();
self.buf_read != 0
} else {
true
}
}
read_integer_fun!(i32);
read_integer_fun!(i64);
read_integer_fun!(i128);
read_integer_fun!(u32);
read_integer_fun!(u64);
read_integer_fun!(usize);
}
pub trait Readable {
fn read(input: &mut Input) -> Self;
}
impl Readable for String {
fn read(input: &mut Input) -> Self {
input.read_string()
}
}
impl Readable for char {
fn read(input: &mut Input) -> Self {
input.read_char()
}
}
impl Readable for f64 {
fn read(input: &mut Input) -> Self {
input.read_string().parse().unwrap()
}
}
impl Readable for f32 {
fn read(input: &mut Input) -> Self {
input.read_string().parse().unwrap()
}
}
impl<T: Readable> Readable for Vec<T> {
fn read(input: &mut Input) -> Self {
let size = input.read();
input.vec(size)
}
}
pub struct InputIterator<T: Readable> {
input: Input,
phantom: PhantomData<T>,
}
impl<T: Readable> Iterator for InputIterator<T> {
type Item = T;
fn next(&mut self) -> Option<Self::Item> {
self.input.skip_whitespace();
self.input.peek().map(|_| self.input.read())
}
}
macro_rules! read_integer {
($t:ident) => {
impl Readable for $t {
fn read(input: &mut Input) -> Self {
input.read_integer()
}
}
};
}
read_integer!(i8);
read_integer!(i16);
read_integer!(i32);
read_integer!(i64);
read_integer!(i128);
read_integer!(isize);
read_integer!(u8);
read_integer!(u16);
read_integer!(u32);
read_integer!(u64);
read_integer!(u128);
read_integer!(usize);
}
pub mod output {
use std::io::Write;
pub struct Output {
output: Box<dyn Write>,
buf: Vec<u8>,
at: usize,
auto_flush: bool,
}
impl Output {
const DEFAULT_BUF_SIZE: usize = 4096;
pub fn new(output: Box<dyn Write>) -> Self {
Self {
output,
buf: vec![0; Self::DEFAULT_BUF_SIZE],
at: 0,
auto_flush: false,
}
}
pub fn new_stdout() -> Self {
let stdout = std::io::stdout();
Self::new(Box::new(stdout))
}
pub fn new_file(path: impl AsRef<std::path::Path>) -> Self {
let file = std::fs::File::create(path).unwrap();
Self::new(Box::new(file))
}
pub fn new_with_auto_flush(output: Box<dyn Write>) -> Self {
Self {
output,
buf: vec![0; Self::DEFAULT_BUF_SIZE],
at: 0,
auto_flush: true,
}
}
pub fn flush(&mut self) {
if self.at != 0 {
self.output.write_all(&self.buf[..self.at]).unwrap();
self.at = 0;
self.output.flush().expect("Couldn't flush output");
}
}
pub fn print<T: Writable>(&mut self, s: T) {
s.write(self);
}
pub fn println<T: Writable>(&mut self, s: T) {
s.write(self);
self.put(b'\n');
}
pub fn put(&mut self, b: u8) {
self.buf[self.at] = b;
self.at += 1;
if self.at == self.buf.len() {
self.flush();
}
}
pub fn maybe_flush(&mut self) {
if self.auto_flush {
self.flush();
}
}
pub fn print_per_line<T: Writable>(&mut self, arg: &[T]) {
for i in arg {
i.write(self);
self.put(b'\n');
}
}
pub fn print_iter<T: Writable, I: Iterator<Item = T>>(&mut self, iter: I) {
let mut first = true;
for e in iter {
if first {
first = false;
} else {
self.put(b' ');
}
e.write(self);
}
}
pub fn print_iter_ref<'a, T: 'a + Writable, I: Iterator<Item = &'a T>>(&mut self, iter: I) {
let mut first = true;
for e in iter {
if first {
first = false;
} else {
self.put(b' ');
}
e.write(self);
}
}
}
impl Write for Output {
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
let mut start = 0usize;
let mut rem = buf.len();
while rem > 0 {
let len = (self.buf.len() - self.at).min(rem);
self.buf[self.at..self.at + len].copy_from_slice(&buf[start..start + len]);
self.at += len;
if self.at == self.buf.len() {
self.flush();
}
start += len;
rem -= len;
}
if self.auto_flush {
self.flush();
}
Ok(buf.len())
}
fn flush(&mut self) -> std::io::Result<()> {
self.flush();
Ok(())
}
}
pub trait Writable {
fn write(&self, output: &mut Output);
}
impl Writable for &str {
fn write(&self, output: &mut Output) {
output.write_all(self.as_bytes()).unwrap();
}
}
impl Writable for String {
fn write(&self, output: &mut Output) {
output.write_all(self.as_bytes()).unwrap();
}
}
impl Writable for char {
fn write(&self, output: &mut Output) {
output.put(*self as u8);
}
}
impl<T: Writable> Writable for [T] {
fn write(&self, output: &mut Output) {
output.print_iter_ref(self.iter());
}
}
impl<T: Writable> Writable for Vec<T> {
fn write(&self, output: &mut Output) {
self[..].write(output);
}
}
macro_rules! write_to_string {
($t:ident) => {
impl Writable for $t {
fn write(&self, output: &mut Output) {
self.to_string().write(output);
}
}
};
}
write_to_string!(u8);
write_to_string!(u16);
write_to_string!(u32);
write_to_string!(u64);
write_to_string!(u128);
write_to_string!(usize);
write_to_string!(i8);
write_to_string!(i16);
write_to_string!(i32);
write_to_string!(i64);
write_to_string!(i128);
write_to_string!(isize);
write_to_string!(f32);
write_to_string!(f64);
impl<T: Writable, U: Writable> Writable for (T, U) {
fn write(&self, output: &mut Output) {
self.0.write(output);
output.put(b' ');
self.1.write(output);
}
}
impl<T: Writable, U: Writable, V: Writable> Writable for (T, U, V) {
fn write(&self, output: &mut Output) {
self.0.write(output);
output.put(b' ');
self.1.write(output);
output.put(b' ');
self.2.write(output);
}
}
}
}
pub mod misc {
pub mod binary_search {
use crate::algo_lib::misc::num_traits::Number;
use std::ops::Range;
pub fn binary_search_first_true<T>(range: Range<T>, mut f: impl FnMut(T) -> bool) -> T
where
T: Number,
{
// we can't store [range.start - 1] into [left], because it could overflow
let mut left_plus_one = range.start;
let mut right = range.end;
while right > left_plus_one {
let mid = left_plus_one + (right - left_plus_one) / T::TWO;
if f(mid) {
right = mid;
} else {
left_plus_one = mid + T::ONE;
}
}
right
}
pub fn binary_search_last_true<T>(range: Range<T>, mut f: impl FnMut(T) -> bool) -> Option<T>
where
T: Number,
{
let first_false = binary_search_first_true(range.clone(), |x| !f(x));
if first_false == range.start {
None
} else {
Some(first_false - T::ONE)
}
}
#[test]
fn simple_stress() {
const N: usize = 50;
for n in 1..N {
for cnt_false in 0..=n {
let mut a = vec![false; cnt_false];
a.resize(n, true);
let mut max_f_calls = ((n + 1) as f64).log2().ceil() as i32;
let f_is_true = |id: usize| -> bool {
max_f_calls -= 1;
assert!(max_f_calls >= 0);
a[id]
};
let result = binary_search_first_true(0..n, f_is_true);
assert_eq!(result, cnt_false);
}
}
}
}
pub mod dbg_macro {
#[macro_export]
#[allow(unused_macros)]
macro_rules! dbg {
($first_val:expr, $($val:expr),+ $(,)?) => {
eprint!("[{}:{}] {} = {:?}",
file!(), line!(), stringify!($first_val), &$first_val);
($(eprint!(", {} = {:?}", stringify!($val), &$val)),+,);
eprintln!();
};
($first_val:expr) => {
eprintln!("[{}:{}] {} = {:?}",
file!(), line!(), stringify!($first_val), &$first_val)
};
}
}
pub mod gen_vector {
pub fn gen_vec<T>(n: usize, f: impl FnMut(usize) -> T) -> Vec<T> {
(0..n).map(f).collect()
}
}
pub mod num_traits {
use std::cmp::Ordering;
use std::fmt::Debug;
use std::ops::Add;
use std::ops::AddAssign;
use std::ops::Div;
use std::ops::DivAssign;
use std::ops::Mul;
use std::ops::MulAssign;
use std::ops::Sub;
use std::ops::SubAssign;
pub trait HasConstants<T> {
const MAX: T;
const MIN: T;
const ZERO: T;
const ONE: T;
const TWO: T;
}
pub trait ConvSimple<T> {
fn from_i32(val: i32) -> T;
fn to_i32(self) -> i32;
fn to_f64(self) -> f64;
}
pub trait Signum {
fn signum(&self) -> i32;
}
pub trait Number:
Copy
+ Add<Output = Self>
+ AddAssign
+ Sub<Output = Self>
+ SubAssign
+ Mul<Output = Self>
+ MulAssign
+ Div<Output = Self>
+ DivAssign
+ PartialOrd
+ PartialEq
+ HasConstants<Self>
+ Default
+ Debug
+ Sized
+ ConvSimple<Self>
{
}
impl<
T: Copy
+ Add<Output = Self>
+ AddAssign
+ Sub<Output = Self>
+ SubAssign
+ Mul<Output = Self>
+ MulAssign
+ Div<Output = Self>
+ DivAssign
+ PartialOrd
+ PartialEq
+ HasConstants<Self>
+ Default
+ Debug
+ Sized
+ ConvSimple<Self>,
> Number for T
{
}
macro_rules! has_constants_impl {
($t: ident) => {
impl HasConstants<$t> for $t {
// TODO: remove `std` for new rust version..
const MAX: $t = std::$t::MAX;
const MIN: $t = std::$t::MIN;
const ZERO: $t = 0;
const ONE: $t = 1;
const TWO: $t = 2;
}
impl ConvSimple<$t> for $t {
fn from_i32(val: i32) -> $t {
val as $t
}
fn to_i32(self) -> i32 {
self as i32
}
fn to_f64(self) -> f64 {
self as f64
}
}
};
}
has_constants_impl!(i32);
has_constants_impl!(i64);
has_constants_impl!(i128);
has_constants_impl!(u32);
has_constants_impl!(u64);
has_constants_impl!(u128);
has_constants_impl!(usize);
has_constants_impl!(u8);
impl ConvSimple<Self> for f64 {
fn from_i32(val: i32) -> Self {
val as f64
}
fn to_i32(self) -> i32 {
self as i32
}
fn to_f64(self) -> f64 {
self
}
}
impl HasConstants<Self> for f64 {
const MAX: Self = Self::MAX;
const MIN: Self = -Self::MAX;
const ZERO: Self = 0.0;
const ONE: Self = 1.0;
const TWO: Self = 2.0;
}
impl<T: Number + Ord> Signum for T {
fn signum(&self) -> i32 {
match self.cmp(&T::ZERO) {
Ordering::Greater => 1,
Ordering::Less => -1,
Ordering::Equal => 0,
}
}
}
}
pub mod rand {
use crate::algo_lib::misc::gen_vector::gen_vec;
use crate::algo_lib::misc::num_traits::Number;
use std::ops::Range;
use std::time::SystemTime;
use std::time::UNIX_EPOCH;
#[allow(dead_code)]
pub struct Random {
state: u64,
}
impl Random {
pub fn gen_u64(&mut self) -> u64 {
let mut x = self.state;
x ^= x << 13;
x ^= x >> 7;
x ^= x << 17;
self.state = x;
x
}
#[allow(dead_code)]
pub fn next_in_range(&mut self, from: usize, to: usize) -> usize {
assert!(from < to);
(from as u64 + self.gen_u64() % ((to - from) as u64)) as usize
}
pub fn gen_index<T>(&mut self, a: &[T]) -> usize {
self.gen(0..a.len())
}
#[allow(dead_code)]
#[inline(always)]
pub fn gen_double(&mut self) -> f64 {
(self.gen_u64() as f64) / (std::usize::MAX as f64)
}
#[allow(dead_code)]
pub fn new(seed: u64) -> Self {
let state = if seed == 0 { 787788 } else { seed };
Self { state }
}
pub fn new_time_seed() -> Self {
let time = SystemTime::now();
let seed = (time.duration_since(UNIX_EPOCH).unwrap().as_nanos() % 1_000_000_000) as u64;
if seed == 0 {
Self::new(787788)
} else {
Self::new(seed)
}
}
#[allow(dead_code)]
pub fn gen_permutation(&mut self, n: usize) -> Vec<usize> {
let mut result: Vec<_> = (0..n).collect();
for i in 0..n {
let idx = self.next_in_range(0, i + 1);
result.swap(i, idx);
}
result
}
pub fn shuffle<T>(&mut self, a: &mut [T]) {
for i in 1..a.len() {
a.swap(i, self.gen(0..i + 1));
}
}
pub fn gen<T>(&mut self, range: Range<T>) -> T
where
T: Number,
{
let from = T::to_i32(range.start);
let to = T::to_i32(range.end);
assert!(from < to);
let len = (to - from) as usize;
T::from_i32(self.next_in_range(0, len) as i32 + from)
}
pub fn gen_vec<T>(&mut self, n: usize, range: Range<T>) -> Vec<T>
where
T: Number,
{
gen_vec(n, |_| self.gen(range.clone()))
}
pub fn gen_nonempty_range(&mut self, n: usize) -> Range<usize> {
let x = self.gen(0..n);
let y = self.gen(0..n);
if x <= y {
x..y + 1
} else {
y..x + 1
}
}
pub fn gen_bool(&mut self) -> bool {
self.gen(0..2) == 0
}
}
}
pub mod vec_apply_delta {
use crate::algo_lib::misc::num_traits::Number;
pub trait ApplyDelta<T> {
fn add_to_all(self, delta: T) -> Self;
fn sub_from_all(self, sub: T) -> Self;
}
impl<T> ApplyDelta<T> for Vec<T>
where
T: Number,
{
fn add_to_all(mut self, delta: T) -> Self {
self.iter_mut().for_each(|val| *val += delta);
self
}
fn sub_from_all(mut self, sub: T) -> Self {
self.iter_mut().for_each(|val| *val -= sub);
self
}
}
impl<T> ApplyDelta<T> for Vec<(T, T)>
where
T: Number,
{
fn add_to_all(mut self, delta: T) -> Self {
self.iter_mut().for_each(|(val1, val2)| {
*val1 += delta;
*val2 += delta
});
self
}
fn sub_from_all(mut self, sub: T) -> Self {
self.iter_mut().for_each(|(val1, val2)| {
*val1 -= sub;
*val2 -= sub;
});
self
}
}
pub trait ApplyDelta2<T> {
fn add_to_all(&mut self, delta: T);
fn sub_from_all(&mut self, sub: T);
}
impl<T> ApplyDelta2<T> for [T]
where
T: Number,
T: Sized,
{
fn add_to_all(self: &mut [T], delta: T) {
self.iter_mut().for_each(|x| *x += delta);
}
fn sub_from_all(&mut self, sub: T) {
self.iter_mut().for_each(|x| *x -= sub);
}
}
}
}
pub mod seg_trees {
pub mod fenwick {
use std::ops::Range;
use crate::algo_lib::misc::num_traits::Number;
#[allow(dead_code)]
#[derive(Clone)]
pub struct Fenwick<T: Number> {
values: Vec<T>,
}
impl<T: Number> Fenwick<T> {
#[allow(dead_code)]
pub fn get_sum(&self, mut pos: usize) -> T {
let mut res = T::ZERO;
loop {
res += self.values[pos];
pos = pos & (pos + 1);
if pos == 0 {
return res;
}
pos -= 1;
}
}
pub fn get_range_sum(&self, range: Range<usize>) -> T {
if range.end == 0 {
return T::ZERO;
}
let res = self.get_sum(range.end - 1);
if range.start == 0 {
res
} else {
res - self.get_sum(range.start - 1)
}
}
pub fn get_suffix_sum(&self, pos: usize) -> T {
let total = self.get_sum(self.values.len() - 1);
let before = if pos == 0 {
T::ZERO
} else {
self.get_sum(pos - 1)
};
total - before
}
#[allow(dead_code)]
pub fn add(&mut self, mut pos: usize, change: T) {
while pos < self.values.len() {
self.values[pos] += change;
pos |= pos + 1;
}
}
#[allow(dead_code)]
pub fn new(n: usize) -> Self {
let values = vec![T::ZERO; n];
Fenwick { values }
}
pub fn new_pow2(n: usize) -> Self {
Self::new(n.next_power_of_two())
}
pub fn clear(&mut self) {
for x in self.values.iter_mut() {
*x = T::ZERO;
}
}
pub fn len(&self) -> usize {
self.values.len()
}
}
}
}
}
fn main() {
let input = algo_lib::io::input::Input::new_stdin();
let mut output = algo_lib::io::output::Output::new_stdout();
crate::solution::run(input, output);
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 2308kb
input:
2 1 1 2 2
output:
1 2 2 1
result:
ok 4 tokens
Test #2:
score: 0
Accepted
time: 0ms
memory: 2312kb
input:
3 2 1 2 3 1 3
output:
1 2 2 2 2 1
result:
ok 6 tokens
Test #3:
score: 0
Accepted
time: 0ms
memory: 2104kb
input:
4 1 2 4 3 4 1 3 2
output:
1 2 1 2 1 3 1 1
result:
ok 8 tokens
Test #4:
score: 0
Accepted
time: 0ms
memory: 2132kb
input:
1 1 1
output:
1 1
result:
ok 2 tokens
Test #5:
score: 0
Accepted
time: 984ms
memory: 325724kb
input:
500000 233733 151347 468353 495903 234861 297169 312993 2734 287872 359375 79017 285205 219439 37290 409190 194953 306816 472906 123794 121028 66509 62235 385879 300188 485875 72413 167304 333428 33910 220100 151575 22575 206653 82054 111518 34032 48702 198940 6262 222529 170641 1735 38943 235003 11...
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
result:
ok 1000000 tokens
Test #6:
score: 0
Accepted
time: 997ms
memory: 325572kb
input:
499999 20175 421667 477513 164648 153952 133902 58509 432946 498621 54699 294105 304055 93092 259617 486830 464621 6039 242867 382241 360345 10071 252829 103706 252083 473217 323326 33901 422497 383693 356571 238499 427265 431925 199533 488748 223250 479343 214815 342665 7527 397982 388425 441947 22...
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
result:
ok 999998 tokens
Test #7:
score: 0
Accepted
time: 940ms
memory: 325720kb
input:
499997 45410 344491 448636 181028 373083 59862 259850 450733 79631 85900 495425 239044 136232 298896 153214 415427 38484 109664 137285 119717 218023 298593 471654 176162 70510 350483 399376 389216 216264 101701 215546 228021 276411 466038 129279 195937 428850 265629 401774 256885 390764 413922 17303...
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
result:
ok 999994 tokens
Test #8:
score: 0
Accepted
time: 993ms
memory: 326028kb
input:
499997 37608 326519 54760 248123 204348 346642 61147 436793 69778 214333 218891 483667 384161 403360 356390 248198 29856 493073 233598 389736 369609 270007 220631 136593 466701 181463 411612 427328 118151 122803 284544 460648 272586 195734 336665 122951 379375 367270 245020 25504 383525 41863 81696 ...
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
result:
ok 999994 tokens
Test #9:
score: 0
Accepted
time: 985ms
memory: 325520kb
input:
500000 135935 181205 141645 138625 249427 195506 123419 458633 63023 374714 401464 251761 277589 411743 487913 258512 492432 128739 193919 223871 363101 432296 482273 312836 246225 444114 374199 486518 186449 150064 106819 451666 347007 343676 417429 283175 281930 230703 379421 67177 249744 37489 14...
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
result:
ok 1000000 tokens
Test #10:
score: 0
Accepted
time: 9ms
memory: 7844kb
input:
10363 10142 10142 2131 2738 2131 2738 680 5820 5820 680 5427 5427 5351 5351 5858 2523 2523 5858 441 7894 441 7894 1030 1030 719 719 9367 6333 1473 9367 6333 1473 7794 5563 2057 7794 2057 5563 4537 6187 7424 6187 4537 7424 4036 6607 9275 6607 9275 4036 4467 6358 1636 1636 4467 6358 4832 9601 7151 715...
output:
1 3591 2 3 3591 3590 6 1 1 7178 4 3588 5 3587 12 1 1 7172 7 8 3586 3585 8 3584 9 3583 10 1 11 3583 1 3582 11 12 1 3583 1 3581 12 1 14 1 3581 3580 26 1 2 2 1 7158 14 16 1 1 3580 3578 30 2 1 1 2 7154 16 17 3577 17 3577 3576 17 35 3577 1 1 7150 18 19 3575 3574 19 3573 40 1 1 22 7145 3572 63 1 2 2 1 107...
result:
ok 20726 tokens
Test #11:
score: 0
Accepted
time: 508ms
memory: 250644kb
input:
499999 395932 97222 230492 15912 230492 255343 255343 97222 15912 395932 5114 483045 466140 64914 153803 327261 213658 466140 153803 64914 2964 487362 283821 280934 487362 483045 5114 283821 50697 327261 280934 50697 2964 213658 375562 126491 470816 375562 126491 470816 450983 67957 450983 67957 183...
output:
2 1 1 4 2 1 1 3 1 140044 2 1 1 1 1 1 3 1 1 1 1 1 1 1 1 1 70022 1 1 1 1 1 1 70021 3 1 4 70021 1 70020 4 5 70020 70019 5 1 1 1 1 1 1 1 1 1 1 6 1 1 1 1 1 1 1 70019 1 1 1 70018 6 1 1 1 1 1 2 1 7 1 1 1 1 1 1 1 2 1 1 70018 1 1 1 70017 7 1 1 1 1 1 1 1 8 1 1 70017 1 70016 8 1 1 10 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
result:
ok 999998 tokens
Test #12:
score: 0
Accepted
time: 516ms
memory: 250820kb
input:
499999 142538 184126 163213 171647 240285 423903 240285 163213 184126 142538 171647 423903 218419 444722 307848 309220 417492 309220 218419 444722 253423 253423 246403 246403 417492 307848 1546 256611 460533 179666 460533 33542 256611 33542 1546 182312 182312 179666 494891 494891 297200 342578 57556...
output:
1 1 1 1 1 3 1 1 1 69951 1 69950 2 1 3 1 2 1 69950 3 1 2 2 1 3 69949 3 1 1 9 1 1 2 1 69950 1 1 139896 4 69947 5 7 1 1 2 69949 1 6 69947 69946 6 7 3 1 2 2 1 69949 1 1 3 1 1 2 1 69945 7 1 8 1 69945 1 1 69944 8 69943 9 69942 20 1 1 3 1 1 2 1 1 3 1 2 1 1 1 139882 11 69940 12 14 1 2 2 1 69941 13 69940 13 ...
result:
ok 999998 tokens
Test #13:
score: 0
Accepted
time: 648ms
memory: 324376kb
input:
499619 50264 179484 186976 224852 311651 162550 298810 487114 157179 227092 71434 374658 258250 58425 151903 171647 152564 397068 65816 380053 379146 374209 49014 170493 320934 135306 124892 357150 167207 455736 160104 486395 95762 449875 118277 418781 218907 89314 337856 30989 310703 53341 419427 3...
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
result:
ok 999238 tokens
Test #14:
score: 0
Accepted
time: 641ms
memory: 323944kb
input:
499606 369879 341625 175849 314032 132747 52381 305513 243923 372249 362042 423054 83571 249322 93226 313191 243365 450797 427667 235086 349991 180477 435583 207087 489095 363133 186894 63517 125104 238559 439605 439605 406039 176030 141309 211195 363491 441590 274803 457716 289474 230268 258356 541...
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 479 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
result:
ok 999212 tokens
Test #15:
score: 0
Accepted
time: 303ms
memory: 244104kb
input:
500000 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50 51 51 52 52...
output:
1 500000 2 499999 3 499998 4 499997 5 499996 6 499995 7 499994 8 499993 9 499992 10 499991 11 499990 12 499989 13 499988 14 499987 15 499986 16 499985 17 499984 18 499983 19 499982 20 499981 21 499980 22 499979 23 499978 24 499977 25 499976 26 499975 27 499974 28 499973 29 499972 30 499971 31 499970...
result:
ok 1000000 tokens
Test #16:
score: 0
Accepted
time: 524ms
memory: 327784kb
input:
500000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 1...
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
result:
ok 1000000 tokens
Test #17:
score: 0
Accepted
time: 458ms
memory: 226696kb
input:
500000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 1...
output:
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ...
result:
ok 1000000 tokens
Test #18:
score: 0
Accepted
time: 552ms
memory: 302600kb
input:
500000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 1...
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
result:
ok 1000000 tokens
Test #19:
score: 0
Accepted
time: 304ms
memory: 241296kb
input:
500000 1 2 1 2 3 4 3 4 5 6 5 6 7 8 7 8 9 10 9 10 11 12 11 12 13 14 13 14 15 16 15 16 17 18 17 18 19 20 19 20 21 22 21 22 23 24 23 24 25 26 25 26 27 28 27 28 29 30 29 30 31 32 31 32 33 34 33 34 35 36 35 36 37 38 37 38 39 40 39 40 41 42 41 42 43 44 43 44 45 46 45 46 47 48 47 48 49 50 49 50 51 52 51 52...
output:
1 2 250001 250000 2 3 250000 249999 3 4 249999 249998 4 5 249998 249997 5 6 249997 249996 6 7 249996 249995 7 8 249995 249994 8 9 249994 249993 9 10 249993 249992 10 11 249992 249991 11 12 249991 249990 12 13 249990 249989 13 14 249989 249988 14 15 249988 249987 15 16 249987 249986 16 17 249986 2499...
result:
ok 1000000 tokens
Test #20:
score: 0
Accepted
time: 500ms
memory: 257260kb
input:
500000 11 4 8 2 14 15 26 26 23 30 23 25 103 115 112 116 109 122 115 125 117 122 113 112 108 34473 34474 34475 34472 34474 34472 34471 61922 61915 61922 61918 61917 164274 164267 164265 164272 164265 164271 167825 167812 192706 192704 192707 192705 192705 192702 192704 307675 307671 307670 307679 307...
output:
1 1 1 3 1 3 1 2 2 3 2 2 2 1 1 1 1 1 2 1 1 1 1 1 2 1 1 2 1 2 1 4 1 2 2 1 5 1 1 1 2 1 2 1 2 2 1 3 1 1 2 5 1 1 1 1 1 2 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 2 2 1 1 1 1 1 1 1 2 1 1 1 2 1 1 1 1 1 1 3 1 2 1 1 1 1 2 1 1 2 2 1 1 2 2 1 3 3 1 2 1 1 1 1 1 1 1 1 2 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
result:
ok 1000000 tokens
Test #21:
score: 0
Accepted
time: 511ms
memory: 257348kb
input:
500000 2 7 9 8 44 40 46 31 33 34 61 58 55 109 105 104 112 106 113 105 108 14336 14339 14335 14340 29421 141122 141129 141129 141122 141121 141118 141124 141121 141120 141125 141123 141130 141119 141126 141128 141127 141125 141126 141128 141127 186887 186877 186881 186884 186879 186883 186876 186877 ...
output:
6 1 4 2 1 1 1 1 1 2 1 1 2 1 1 1 1 1 1 1 2 1 1 1 2 3 2 1 1 4 2 1 3 2 1 1 1 1 1 1 1 1 4 1 1 2 1 1 3 1 1 1 1 3 1 1 1 1 1 2 1 1 1 1 1 3 1 1 2 1 2 1 2 1 1 3 1 1 4 1 1 2 2 1 3 2 1 1 2 1 1 1 2 1 2 2 1 1 1 1 6 1 1 2 4 1 1 2 5 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 2 1 2 1 1 1 1 2 1 2 1 1 1 1 1 1 ...
result:
ok 1000000 tokens
Test #22:
score: 0
Accepted
time: 547ms
memory: 324508kb
input:
500000 134 57 24 426 60 186 174 300 291 549 324 9 455 202 517 83 261 87 259 86 151 444 79 360 142 280 538 213 335 123 200 184 67 313 287 177 30 95 483 84 323 436 5 1 330 199 516 338 540 115 206 205 2 131 448 397 216 395 101 215 298 339 296 15 265 385 315 330 46 370 329 175 607 112 230 486 323 30 68 ...
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 ...
result:
ok 1000000 tokens
Test #23:
score: 0
Accepted
time: 575ms
memory: 324100kb
input:
500000 46 94 74 141 1 10 132 16 107 116 8 2 78 5 123 146 85 55 26 105 119 147 144 104 24 39 25 9 90 33 58 23 144 149 82 27 136 115 329 194 319 300 310 205 330 212 305 199 808 545 408 421 847 738 485 447 766 448 554 823 637 858 806 829 575 706 726 446 644 804 550 460 1291 1477 1443 1413 1671 1216 140...
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
result:
ok 1000000 tokens
Extra Test:
score: 0
Extra Test Passed