Submission #66730207


Source Code Expand

#![allow(unused_imports)]
#![allow(dead_code)]

use ac_library::{Dsu, LazySegtree, MapMonoid, ModInt998244353, Monoid, Segtree};
use amplify::confinement::Collection;
use ascii::AsciiChar::B;
use itertools::Itertools;
use petgraph::graph::Node;
use rand::Rng;
use std::cell::RefCell;
use std::cmp::{Ordering, Reverse};
use std::collections::btree_map::Entry as BTreeMapEntry;
use std::collections::hash_map::{Entry as HashMapEntry, Entry};
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use std::convert::identity;
use std::fmt::{Debug, Display, Formatter, Write};
use std::hash::Hash;
use std::io::{stdin, BufRead, BufWriter, Write as _};
use std::ops::{Bound, ControlFlow, Range, RangeBounds, RangeInclusive};
use std::rc::Rc;
use std::str::FromStr;
use std::sync::atomic::AtomicUsize;
use std::sync::{atomic, OnceLock};
use std::thread::LocalKey;
use std::time::{Duration, Instant};
use std::{array, convert, fmt, io, iter, mem, ptr};

pub fn solve(InputObject { cin }: InputObject) {
    let n: usize = cin.next();
    let q: usize = cin.next();
    let mut array = (1..=n).collect::<Vec<_>>();
    let mut offset = 0;
    let mut out = String::new();
    for _ in 0..q {
        let ty: usize = cin.next();
        match ty {
            1 => {
                let p: usize = cin.next();
                let x: usize = cin.next();
                let p = p - 1;
                array[(offset + p) % n] = x;
            }
            2 => {
                let p: usize = cin.next();
                let p = p - 1;
                writeln!(out, "{}", array[(offset + p) % n]).unwrap();
            }
            3 => {
                let k: usize = cin.next();
                offset += k;
            }
            _ => unreachable!(),
        }
    }
    print!("{out}");
}

pub struct InputObject<'a> {
    cin: &'a mut ConsoleInput,
}

fn input(cin: &mut ConsoleInput) -> InputObject {
    InputObject { cin }
}

pub fn main() {
    let mut cin = ConsoleInput::new();
    let input = input(&mut cin);
    solve(input);
}

// libraries below
pub struct ConsoleInput {
    queue: VecDeque<String>,
}

pub trait Input {
    fn next<T: FromStr>(&mut self) -> T;
    fn next_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.next()).collect()
    }
}

pub trait Output {
    fn write(&self);
}

impl Output for () {
    fn write(&self) {}
}

impl Input for ConsoleInput {
    fn next<T: FromStr>(&mut self) -> T {
        match self.read().parse() {
            Ok(value) => value,
            _ => panic!("parse error"),
        }
    }
}

impl ConsoleInput {
    fn new() -> Self {
        Self {
            queue: VecDeque::new(),
        }
    }

    fn read(&mut self) -> String {
        loop {
            if let Some(s) = self.queue.pop_front() {
                return s;
            }
            let mut s = String::new();
            stdin().read_line(&mut s).expect("failed to read");
            for s in s.split_ascii_whitespace() {
                self.queue.push_back(String::from(s));
            }
        }
    }
}

fn binary_search(range: Range<usize>, f: impl Fn(usize) -> Ordering) -> Result<usize, usize> {
    let mut start = range.start;
    let mut len = range.len();
    if len == 0 {
        return Err(0);
    }
    while len > 1 {
        let half = len / 2;
        let mid = start + half;
        if f(mid) != Ordering::Greater {
            start = mid;
        }
        len -= half;
    }
    match f(start) {
        Ordering::Equal => Ok(start),
        Ordering::Less => Err(start + 1),
        Ordering::Greater => Err(start),
    }
}

fn all_bits() -> impl Iterator<Item = impl Iterator<Item = (usize, bool)>> {
    (0usize..).map(|i| (0usize..).map(move |j| (j, (i >> j) & 1 != 0)))
}

#[cfg(test)]
mod tests;

Submission Info

Submission Time
Task C - Rotatable Array
User White_Green
Language Rust (rustc 1.70.0)
Score 300
Code Size 3969 Byte
Status AC
Exec Time 48 ms
Memory 12332 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 2
AC × 46
Set Name Test Cases
Sample sample_01.txt, sample_02.txt
All sample_01.txt, sample_02.txt, test_01.txt, test_02.txt, test_03.txt, test_04.txt, test_05.txt, test_06.txt, test_07.txt, test_08.txt, test_09.txt, test_10.txt, test_11.txt, test_12.txt, test_13.txt, test_14.txt, test_15.txt, test_16.txt, test_17.txt, test_18.txt, test_19.txt, test_20.txt, test_21.txt, test_22.txt, test_23.txt, test_24.txt, test_25.txt, test_26.txt, test_27.txt, test_28.txt, test_29.txt, test_30.txt, test_31.txt, test_32.txt, test_33.txt, test_34.txt, test_35.txt, test_36.txt, test_37.txt, test_38.txt, test_39.txt, test_40.txt, test_41.txt, test_42.txt, test_43.txt, test_44.txt
Case Name Status Exec Time Memory
sample_01.txt AC 1 ms 1904 KiB
sample_02.txt AC 3 ms 9496 KiB
test_01.txt AC 0 ms 1936 KiB
test_02.txt AC 1 ms 2108 KiB
test_03.txt AC 0 ms 1988 KiB
test_04.txt AC 41 ms 10300 KiB
test_05.txt AC 41 ms 10384 KiB
test_06.txt AC 41 ms 10256 KiB
test_07.txt AC 43 ms 10192 KiB
test_08.txt AC 44 ms 10304 KiB
test_09.txt AC 41 ms 10404 KiB
test_10.txt AC 29 ms 2100 KiB
test_11.txt AC 27 ms 2196 KiB
test_12.txt AC 30 ms 2120 KiB
test_13.txt AC 32 ms 4624 KiB
test_14.txt AC 44 ms 10184 KiB
test_15.txt AC 30 ms 2596 KiB
test_16.txt AC 31 ms 2724 KiB
test_17.txt AC 35 ms 3532 KiB
test_18.txt AC 32 ms 6516 KiB
test_19.txt AC 42 ms 9504 KiB
test_20.txt AC 26 ms 2456 KiB
test_21.txt AC 31 ms 2524 KiB
test_22.txt AC 33 ms 2624 KiB
test_23.txt AC 31 ms 2324 KiB
test_24.txt AC 48 ms 10592 KiB
test_25.txt AC 27 ms 2376 KiB
test_26.txt AC 26 ms 1952 KiB
test_27.txt AC 30 ms 3228 KiB
test_28.txt AC 38 ms 5588 KiB
test_29.txt AC 42 ms 10340 KiB
test_30.txt AC 30 ms 2112 KiB
test_31.txt AC 33 ms 2672 KiB
test_32.txt AC 31 ms 3396 KiB
test_33.txt AC 31 ms 6092 KiB
test_34.txt AC 46 ms 12332 KiB
test_35.txt AC 30 ms 2408 KiB
test_36.txt AC 31 ms 2524 KiB
test_37.txt AC 28 ms 2332 KiB
test_38.txt AC 32 ms 4304 KiB
test_39.txt AC 34 ms 10308 KiB
test_40.txt AC 24 ms 2024 KiB
test_41.txt AC 30 ms 2808 KiB
test_42.txt AC 33 ms 2740 KiB
test_43.txt AC 44 ms 9868 KiB
test_44.txt AC 42 ms 10264 KiB