Add in-progress problems and saved test outputs
excel-sheet, min-effort-path and queue-with-stack (Rust) and set-xor-min, plus expected outputs for and-or-sort, minus-two and moo-language-school. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -0,0 +1,7 @@
|
|||||||
|
0
|
||||||
|
3
|
||||||
|
1
|
||||||
|
2
|
||||||
|
3
|
||||||
|
1
|
||||||
|
|
||||||
@@ -0,0 +1,110 @@
|
|||||||
|
#![allow(dead_code, unused_imports, unused_macros, unused_mut, unused_variables)]
|
||||||
|
use std::cmp::{Ordering, Reverse, max, min};
|
||||||
|
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io::{self, BufWriter, Read, Write};
|
||||||
|
|
||||||
|
// ----- TYPES -----
|
||||||
|
type Ll = i64;
|
||||||
|
type Pii = (i32, i32);
|
||||||
|
|
||||||
|
// ----- FILE IO -----
|
||||||
|
// stdio("excel-sheet") picks the mode from the directory it runs in:
|
||||||
|
// name.in exists -> read name.in, write name.out (USACO + `usaco run/test`)
|
||||||
|
// name.in missing -> read stdin, write stdout (Codeforces submission)
|
||||||
|
// So the same file works locally and when pasted into a judge.
|
||||||
|
fn stdio(name: &str) -> (Scanner, Box<dyn Write>) {
|
||||||
|
let infile = format!("{}.in", name);
|
||||||
|
if std::path::Path::new(&infile).exists() {
|
||||||
|
let src = std::fs::read_to_string(&infile).expect("could not read .in file");
|
||||||
|
let out = File::create(format!("{}.out", name)).expect("could not create .out file");
|
||||||
|
(Scanner::new(&src), Box::new(BufWriter::new(out)))
|
||||||
|
} else {
|
||||||
|
let mut src = String::new();
|
||||||
|
io::stdin()
|
||||||
|
.read_to_string(&mut src)
|
||||||
|
.expect("could not read stdin");
|
||||||
|
(Scanner::new(&src), Box::new(BufWriter::new(io::stdout())))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----- INPUT -----
|
||||||
|
// Slurps the whole input, then hands out whitespace-separated tokens.
|
||||||
|
// let n: usize = sc.next(); one token
|
||||||
|
// let (a, b) = (sc.next::<i64>(), sc.next::<i64>());
|
||||||
|
// let v: Vec<i64> = sc.vec(n); n tokens
|
||||||
|
// let s: Vec<u8> = sc.bytes(); a word as bytes (s[i] - b'a')
|
||||||
|
struct Scanner {
|
||||||
|
toks: std::str::SplitAsciiWhitespace<'static>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Scanner {
|
||||||
|
fn new(src: &str) -> Scanner {
|
||||||
|
let leaked: &'static str = Box::leak(src.to_owned().into_boxed_str());
|
||||||
|
Scanner {
|
||||||
|
toks: leaked.split_ascii_whitespace(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn next<T: std::str::FromStr>(&mut self) -> T {
|
||||||
|
let tok = self.toks.next().expect("ran out of input");
|
||||||
|
tok.parse().ok().expect("could not parse token")
|
||||||
|
}
|
||||||
|
fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
|
||||||
|
(0..n).map(|_| self.next()).collect()
|
||||||
|
}
|
||||||
|
fn pair<T: std::str::FromStr, U: std::str::FromStr>(&mut self) -> (T, U) {
|
||||||
|
(self.next(), self.next())
|
||||||
|
}
|
||||||
|
fn pairs<T: std::str::FromStr, U: std::str::FromStr>(&mut self, n: usize) -> Vec<(T, U)> {
|
||||||
|
(0..n).map(|_| self.pair()).collect()
|
||||||
|
}
|
||||||
|
fn bytes(&mut self) -> Vec<u8> {
|
||||||
|
self.next::<String>().into_bytes()
|
||||||
|
}
|
||||||
|
fn chars(&mut self) -> Vec<char> {
|
||||||
|
self.next::<String>().chars().collect()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----- OUTPUT -----
|
||||||
|
// Write with writeln!(out, "{}", x). These help with the common shapes:
|
||||||
|
fn yesno(b: bool) -> &'static str {
|
||||||
|
if b { "YES" } else { "NO" }
|
||||||
|
}
|
||||||
|
// join(&v, " ") -> "1 2 3"
|
||||||
|
fn join<T: std::fmt::Display>(v: &[T], sep: &str) -> String {
|
||||||
|
v.iter()
|
||||||
|
.map(|x| x.to_string())
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.join(sep)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----- DEBUG -----
|
||||||
|
// dbg!(x) is built in and goes to stderr, so it never pollutes the .out file.
|
||||||
|
|
||||||
|
// ----- MAX MIN -----
|
||||||
|
fn remax<T: PartialOrd>(a: &mut T, b: T) -> bool {
|
||||||
|
if b > *a {
|
||||||
|
*a = b;
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn remin<T: PartialOrd>(a: &mut T, b: T) -> bool {
|
||||||
|
if b < *a {
|
||||||
|
*a = b;
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let (mut sc, mut out) = stdio("excel-sheet");
|
||||||
|
let t: usize = sc.next();
|
||||||
|
for _ in 0..t {
|
||||||
|
let x: i32 = sc.next();
|
||||||
|
while (x > 0) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,136 @@
|
|||||||
|
#![allow(dead_code, unused_imports, unused_macros, unused_mut, unused_variables)]
|
||||||
|
use std::cmp::{max, min, Ordering, Reverse};
|
||||||
|
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io::{self, BufWriter, Read, Write};
|
||||||
|
|
||||||
|
// ----- TYPES -----
|
||||||
|
type Ll = i64;
|
||||||
|
type Pii = (i32, i32);
|
||||||
|
|
||||||
|
// ----- FILE IO -----
|
||||||
|
// stdio("name") picks the mode from the directory it runs in:
|
||||||
|
// name.in exists -> read name.in, write name.out (USACO + `usaco run/test`)
|
||||||
|
// name.in missing -> read stdin, write stdout (Codeforces submission)
|
||||||
|
// So the same file works locally and when pasted into a judge.
|
||||||
|
fn stdio(name: &str) -> (Scanner, Box<dyn Write>) {
|
||||||
|
let infile = format!("{name}.in");
|
||||||
|
if std::path::Path::new(&infile).exists() {
|
||||||
|
let src = std::fs::read_to_string(&infile).expect("could not read .in file");
|
||||||
|
let out = File::create(format!("{name}.out")).expect("could not create .out file");
|
||||||
|
(Scanner::new(&src), Box::new(BufWriter::new(out)))
|
||||||
|
} else {
|
||||||
|
let mut src = String::new();
|
||||||
|
io::stdin()
|
||||||
|
.read_to_string(&mut src)
|
||||||
|
.expect("could not read stdin");
|
||||||
|
(Scanner::new(&src), Box::new(BufWriter::new(io::stdout())))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----- INPUT -----
|
||||||
|
// Slurps the whole input, then hands out whitespace-separated tokens.
|
||||||
|
// let n: usize = sc.next(); one token
|
||||||
|
// let (a, b) = (sc.next::<i64>(), sc.next::<i64>());
|
||||||
|
// let v: Vec<i64> = sc.vec(n); n tokens
|
||||||
|
// let s: Vec<u8> = sc.bytes(); a word as bytes (s[i] - b'a')
|
||||||
|
struct Scanner {
|
||||||
|
toks: std::str::SplitAsciiWhitespace<'static>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Scanner {
|
||||||
|
fn new(src: &str) -> Scanner {
|
||||||
|
let leaked: &'static str = Box::leak(src.to_owned().into_boxed_str());
|
||||||
|
Scanner {
|
||||||
|
toks: leaked.split_ascii_whitespace(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn next<T: std::str::FromStr>(&mut self) -> T {
|
||||||
|
let tok = self.toks.next().expect("ran out of input");
|
||||||
|
tok.parse().ok().expect("could not parse token")
|
||||||
|
}
|
||||||
|
fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
|
||||||
|
(0..n).map(|_| self.next()).collect()
|
||||||
|
}
|
||||||
|
fn pair<T: std::str::FromStr, U: std::str::FromStr>(&mut self) -> (T, U) {
|
||||||
|
(self.next(), self.next())
|
||||||
|
}
|
||||||
|
fn pairs<T: std::str::FromStr, U: std::str::FromStr>(&mut self, n: usize) -> Vec<(T, U)> {
|
||||||
|
(0..n).map(|_| self.pair()).collect()
|
||||||
|
}
|
||||||
|
fn bytes(&mut self) -> Vec<u8> {
|
||||||
|
self.next::<String>().into_bytes()
|
||||||
|
}
|
||||||
|
fn chars(&mut self) -> Vec<char> {
|
||||||
|
self.next::<String>().chars().collect()
|
||||||
|
}
|
||||||
|
fn leet_vec<T: std::str::FromStr>(&mut self) -> Vec<T> {
|
||||||
|
let s: String = self.next();
|
||||||
|
s.trim_matches(|c| c == '[' || c == ']')
|
||||||
|
.split(',')
|
||||||
|
.filter(|s| !s.is_empty())
|
||||||
|
.map(|s| s.parse().ok().expect("leet vec parse err"))
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
fn leet_grid<T: std::str::FromStr>(&mut self) -> Vec<Vec<T>> {
|
||||||
|
let s: String = self.next();
|
||||||
|
let s = s.trim_start_matches('[').trim_end_matches(']');
|
||||||
|
let mut res = Vec::new();
|
||||||
|
for row in s.split("],[") {
|
||||||
|
let cur = row
|
||||||
|
.split(',')
|
||||||
|
.filter(|c| !c.is_empty())
|
||||||
|
.map(|c| c.parse().ok().expect("leet grid error"))
|
||||||
|
.collect();
|
||||||
|
res.push(cur);
|
||||||
|
}
|
||||||
|
res
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----- OUTPUT -----
|
||||||
|
// Write with writeln!(out, "{}", x). These help with the common shapes:
|
||||||
|
fn yesno(b: bool) -> &'static str {
|
||||||
|
if b {
|
||||||
|
"YES"
|
||||||
|
} else {
|
||||||
|
"NO"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// join(&v, " ") -> "1 2 3"
|
||||||
|
fn join<T: std::fmt::Display>(v: &[T], sep: &str) -> String {
|
||||||
|
v.iter()
|
||||||
|
.map(|x| x.to_string())
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.join(sep)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----- DEBUG -----
|
||||||
|
// dbg!(x) is built in and goes to stderr, so it never pollutes the .out file.
|
||||||
|
|
||||||
|
// ----- MAX MIN -----
|
||||||
|
fn remax<T: PartialOrd>(a: &mut T, b: T) -> bool {
|
||||||
|
if b > *a {
|
||||||
|
*a = b;
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn remin<T: PartialOrd>(a: &mut T, b: T) -> bool {
|
||||||
|
if b < *a {
|
||||||
|
*a = b;
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let (mut sc, mut out) = stdio("min-effort-path");
|
||||||
|
let t: usize = sc.next();
|
||||||
|
for _ in 0..t {
|
||||||
|
let grid: Vec<Vec<i32>> = sc.leet_grid();
|
||||||
|
println!("{grid:?}");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
[[1,2,3],[2,3,4]]
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
[[1,2,3],[2,3,4]]
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
2
|
||||||
|
3
|
||||||
|
1
|
||||||
|
4
|
||||||
|
3
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
1
|
||||||
|
5
|
||||||
|
0
|
||||||
|
2
|
||||||
|
0
|
||||||
|
1
|
||||||
|
|
||||||
@@ -0,0 +1,172 @@
|
|||||||
|
#![allow(dead_code, unused_imports, unused_macros, unused_mut, unused_variables)]
|
||||||
|
use std::cmp::{max, min, Ordering, Reverse};
|
||||||
|
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io::{self, BufWriter, Read, Write};
|
||||||
|
|
||||||
|
// ----- TYPES -----
|
||||||
|
type Ll = i64;
|
||||||
|
type Pii = (i32, i32);
|
||||||
|
|
||||||
|
// ----- FILE IO -----
|
||||||
|
// stdio("queue-with-stack") picks the mode from the directory it runs in:
|
||||||
|
// name.in exists -> read name.in, write name.out (USACO + `usaco run/test`)
|
||||||
|
// name.in missing -> read stdin, write stdout (Codeforces submission)
|
||||||
|
// So the same file works locally and when pasted into a judge.
|
||||||
|
fn stdio(name: &str) -> (Scanner, Box<dyn Write>) {
|
||||||
|
let infile = format!("{name}.in");
|
||||||
|
if std::path::Path::new(&infile).exists() {
|
||||||
|
let src = std::fs::read_to_string(&infile).expect("could not read .in file");
|
||||||
|
let out = File::create(format!("{name}.out")).expect("could not create .out file");
|
||||||
|
(Scanner::new(&src), Box::new(BufWriter::new(out)))
|
||||||
|
} else {
|
||||||
|
let mut src = String::new();
|
||||||
|
io::stdin()
|
||||||
|
.read_to_string(&mut src)
|
||||||
|
.expect("could not read stdin");
|
||||||
|
(Scanner::new(&src), Box::new(BufWriter::new(io::stdout())))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----- INPUT -----
|
||||||
|
// Slurps the whole input, then hands out whitespace-separated tokens.
|
||||||
|
// let n: usize = sc.next(); one token
|
||||||
|
// let (a, b) = (sc.next::<i64>(), sc.next::<i64>());
|
||||||
|
// let v: Vec<i64> = sc.vec(n); n tokens
|
||||||
|
// let s: Vec<u8> = sc.bytes(); a word as bytes (s[i] - b'a')
|
||||||
|
struct Scanner {
|
||||||
|
toks: std::str::SplitAsciiWhitespace<'static>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Scanner {
|
||||||
|
fn new(src: &str) -> Scanner {
|
||||||
|
let leaked: &'static str = Box::leak(src.to_owned().into_boxed_str());
|
||||||
|
Scanner {
|
||||||
|
toks: leaked.split_ascii_whitespace(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn next<T: std::str::FromStr>(&mut self) -> T {
|
||||||
|
let tok = self.toks.next().expect("ran out of input");
|
||||||
|
tok.parse().ok().expect("could not parse token")
|
||||||
|
}
|
||||||
|
fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
|
||||||
|
(0..n).map(|_| self.next()).collect()
|
||||||
|
}
|
||||||
|
fn pair<T: std::str::FromStr, U: std::str::FromStr>(&mut self) -> (T, U) {
|
||||||
|
(self.next(), self.next())
|
||||||
|
}
|
||||||
|
fn pairs<T: std::str::FromStr, U: std::str::FromStr>(&mut self, n: usize) -> Vec<(T, U)> {
|
||||||
|
(0..n).map(|_| self.pair()).collect()
|
||||||
|
}
|
||||||
|
fn bytes(&mut self) -> Vec<u8> {
|
||||||
|
self.next::<String>().into_bytes()
|
||||||
|
}
|
||||||
|
fn chars(&mut self) -> Vec<char> {
|
||||||
|
self.next::<String>().chars().collect()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----- OUTPUT -----
|
||||||
|
// Write with writeln!(out, "{}", x). These help with the common shapes:
|
||||||
|
fn yesno(b: bool) -> &'static str {
|
||||||
|
if b {
|
||||||
|
"YES"
|
||||||
|
} else {
|
||||||
|
"NO"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// join(&v, " ") -> "1 2 3"
|
||||||
|
fn join<T: std::fmt::Display>(v: &[T], sep: &str) -> String {
|
||||||
|
v.iter()
|
||||||
|
.map(|x| x.to_string())
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.join(sep)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----- DEBUG -----
|
||||||
|
// dbg!(x) is built in and goes to stderr, so it never pollutes the .out file.
|
||||||
|
|
||||||
|
// ----- MAX MIN -----
|
||||||
|
fn remax<T: PartialOrd>(a: &mut T, b: T) -> bool {
|
||||||
|
if b > *a {
|
||||||
|
*a = b;
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn remin<T: PartialOrd>(a: &mut T, b: T) -> bool {
|
||||||
|
if b < *a {
|
||||||
|
*a = b;
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct MyQueue {
|
||||||
|
in_stk: VecDeque<i32>,
|
||||||
|
out_stk: VecDeque<i32>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl MyQueue {
|
||||||
|
fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
in_stk: VecDeque::new(),
|
||||||
|
out_stk: VecDeque::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn push(&mut self, x: i32) {
|
||||||
|
self.in_stk.push_back(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn pop(&mut self) -> i32 {
|
||||||
|
let val = self.peek();
|
||||||
|
self.out_stk.pop_back();
|
||||||
|
val
|
||||||
|
}
|
||||||
|
|
||||||
|
fn peek(&mut self) -> i32 {
|
||||||
|
if self.out_stk.is_empty() {
|
||||||
|
while let Some(x) = self.in_stk.pop_back() {
|
||||||
|
self.out_stk.push_back(x);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self.out_stk.back().copied().unwrap_or(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn empty(&self) -> bool {
|
||||||
|
self.in_stk.is_empty() && self.out_stk.is_empty()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let (mut sc, mut out) = stdio("queue-with-stack");
|
||||||
|
let t: usize = sc.next();
|
||||||
|
let mut queue: MyQueue = MyQueue::new();
|
||||||
|
for _ in 0..t {
|
||||||
|
let command: String = sc.next();
|
||||||
|
match command.as_str() {
|
||||||
|
"MyQueue" => {
|
||||||
|
queue = MyQueue::new();
|
||||||
|
}
|
||||||
|
"push" => {
|
||||||
|
let x = sc.next();
|
||||||
|
queue.push(x);
|
||||||
|
}
|
||||||
|
"peek" => {
|
||||||
|
writeln!(out, "{}", queue.peek()).unwrap();
|
||||||
|
}
|
||||||
|
"pop" => {
|
||||||
|
writeln!(out, "{}", queue.pop()).unwrap();
|
||||||
|
}
|
||||||
|
"empty" => {
|
||||||
|
writeln!(out, "{}", queue.empty()).unwrap();
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
writeln!(out, "?").unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
6
|
||||||
|
MyQueue
|
||||||
|
push 1
|
||||||
|
push 2
|
||||||
|
peek
|
||||||
|
pop
|
||||||
|
empty
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
6
|
||||||
|
MyQueue
|
||||||
|
push 1
|
||||||
|
push 2
|
||||||
|
peek
|
||||||
|
pop
|
||||||
|
empty
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
1
|
||||||
|
1
|
||||||
|
false
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
9
|
||||||
|
MyQueue
|
||||||
|
push 1
|
||||||
|
push 2
|
||||||
|
peek
|
||||||
|
push 3
|
||||||
|
pop
|
||||||
|
pop
|
||||||
|
pop
|
||||||
|
empty
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
1
|
||||||
|
1
|
||||||
|
2
|
||||||
|
3
|
||||||
|
true
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
12
|
||||||
|
MyQueue
|
||||||
|
empty
|
||||||
|
push 5
|
||||||
|
empty
|
||||||
|
pop
|
||||||
|
empty
|
||||||
|
push 7
|
||||||
|
push 8
|
||||||
|
pop
|
||||||
|
empty
|
||||||
|
pop
|
||||||
|
empty
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
true
|
||||||
|
false
|
||||||
|
5
|
||||||
|
true
|
||||||
|
7
|
||||||
|
false
|
||||||
|
8
|
||||||
|
true
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
11
|
||||||
|
MyQueue
|
||||||
|
push 10
|
||||||
|
push 20
|
||||||
|
peek
|
||||||
|
peek
|
||||||
|
peek
|
||||||
|
pop
|
||||||
|
peek
|
||||||
|
peek
|
||||||
|
pop
|
||||||
|
empty
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
10
|
||||||
|
10
|
||||||
|
10
|
||||||
|
10
|
||||||
|
20
|
||||||
|
20
|
||||||
|
20
|
||||||
|
true
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
21
|
||||||
|
MyQueue
|
||||||
|
push 1
|
||||||
|
peek
|
||||||
|
pop
|
||||||
|
empty
|
||||||
|
push 2
|
||||||
|
peek
|
||||||
|
pop
|
||||||
|
empty
|
||||||
|
push 3
|
||||||
|
peek
|
||||||
|
pop
|
||||||
|
empty
|
||||||
|
push 4
|
||||||
|
peek
|
||||||
|
pop
|
||||||
|
empty
|
||||||
|
push 5
|
||||||
|
peek
|
||||||
|
pop
|
||||||
|
empty
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
1
|
||||||
|
1
|
||||||
|
true
|
||||||
|
2
|
||||||
|
2
|
||||||
|
true
|
||||||
|
3
|
||||||
|
3
|
||||||
|
true
|
||||||
|
4
|
||||||
|
4
|
||||||
|
true
|
||||||
|
5
|
||||||
|
5
|
||||||
|
true
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
11
|
||||||
|
MyQueue
|
||||||
|
push -2147483648
|
||||||
|
push 0
|
||||||
|
push 2147483647
|
||||||
|
peek
|
||||||
|
pop
|
||||||
|
peek
|
||||||
|
pop
|
||||||
|
peek
|
||||||
|
pop
|
||||||
|
empty
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
-2147483648
|
||||||
|
-2147483648
|
||||||
|
0
|
||||||
|
0
|
||||||
|
2147483647
|
||||||
|
2147483647
|
||||||
|
true
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,502 @@
|
|||||||
|
1
|
||||||
|
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
|
||||||
|
101
|
||||||
|
102
|
||||||
|
103
|
||||||
|
104
|
||||||
|
105
|
||||||
|
106
|
||||||
|
107
|
||||||
|
108
|
||||||
|
109
|
||||||
|
110
|
||||||
|
111
|
||||||
|
112
|
||||||
|
113
|
||||||
|
114
|
||||||
|
115
|
||||||
|
116
|
||||||
|
117
|
||||||
|
118
|
||||||
|
119
|
||||||
|
120
|
||||||
|
121
|
||||||
|
122
|
||||||
|
123
|
||||||
|
124
|
||||||
|
125
|
||||||
|
126
|
||||||
|
127
|
||||||
|
128
|
||||||
|
129
|
||||||
|
130
|
||||||
|
131
|
||||||
|
132
|
||||||
|
133
|
||||||
|
134
|
||||||
|
135
|
||||||
|
136
|
||||||
|
137
|
||||||
|
138
|
||||||
|
139
|
||||||
|
140
|
||||||
|
141
|
||||||
|
142
|
||||||
|
143
|
||||||
|
144
|
||||||
|
145
|
||||||
|
146
|
||||||
|
147
|
||||||
|
148
|
||||||
|
149
|
||||||
|
150
|
||||||
|
151
|
||||||
|
152
|
||||||
|
153
|
||||||
|
154
|
||||||
|
155
|
||||||
|
156
|
||||||
|
157
|
||||||
|
158
|
||||||
|
159
|
||||||
|
160
|
||||||
|
161
|
||||||
|
162
|
||||||
|
163
|
||||||
|
164
|
||||||
|
165
|
||||||
|
166
|
||||||
|
167
|
||||||
|
168
|
||||||
|
169
|
||||||
|
170
|
||||||
|
171
|
||||||
|
172
|
||||||
|
173
|
||||||
|
174
|
||||||
|
175
|
||||||
|
176
|
||||||
|
177
|
||||||
|
178
|
||||||
|
179
|
||||||
|
180
|
||||||
|
181
|
||||||
|
182
|
||||||
|
183
|
||||||
|
184
|
||||||
|
185
|
||||||
|
186
|
||||||
|
187
|
||||||
|
188
|
||||||
|
189
|
||||||
|
190
|
||||||
|
191
|
||||||
|
192
|
||||||
|
193
|
||||||
|
194
|
||||||
|
195
|
||||||
|
196
|
||||||
|
197
|
||||||
|
198
|
||||||
|
199
|
||||||
|
200
|
||||||
|
201
|
||||||
|
202
|
||||||
|
203
|
||||||
|
204
|
||||||
|
205
|
||||||
|
206
|
||||||
|
207
|
||||||
|
208
|
||||||
|
209
|
||||||
|
210
|
||||||
|
211
|
||||||
|
212
|
||||||
|
213
|
||||||
|
214
|
||||||
|
215
|
||||||
|
216
|
||||||
|
217
|
||||||
|
218
|
||||||
|
219
|
||||||
|
220
|
||||||
|
221
|
||||||
|
222
|
||||||
|
223
|
||||||
|
224
|
||||||
|
225
|
||||||
|
226
|
||||||
|
227
|
||||||
|
228
|
||||||
|
229
|
||||||
|
230
|
||||||
|
231
|
||||||
|
232
|
||||||
|
233
|
||||||
|
234
|
||||||
|
235
|
||||||
|
236
|
||||||
|
237
|
||||||
|
238
|
||||||
|
239
|
||||||
|
240
|
||||||
|
241
|
||||||
|
242
|
||||||
|
243
|
||||||
|
244
|
||||||
|
245
|
||||||
|
246
|
||||||
|
247
|
||||||
|
248
|
||||||
|
249
|
||||||
|
250
|
||||||
|
251
|
||||||
|
252
|
||||||
|
253
|
||||||
|
254
|
||||||
|
255
|
||||||
|
256
|
||||||
|
257
|
||||||
|
258
|
||||||
|
259
|
||||||
|
260
|
||||||
|
261
|
||||||
|
262
|
||||||
|
263
|
||||||
|
264
|
||||||
|
265
|
||||||
|
266
|
||||||
|
267
|
||||||
|
268
|
||||||
|
269
|
||||||
|
270
|
||||||
|
271
|
||||||
|
272
|
||||||
|
273
|
||||||
|
274
|
||||||
|
275
|
||||||
|
276
|
||||||
|
277
|
||||||
|
278
|
||||||
|
279
|
||||||
|
280
|
||||||
|
281
|
||||||
|
282
|
||||||
|
283
|
||||||
|
284
|
||||||
|
285
|
||||||
|
286
|
||||||
|
287
|
||||||
|
288
|
||||||
|
289
|
||||||
|
290
|
||||||
|
291
|
||||||
|
292
|
||||||
|
293
|
||||||
|
294
|
||||||
|
295
|
||||||
|
296
|
||||||
|
297
|
||||||
|
298
|
||||||
|
299
|
||||||
|
300
|
||||||
|
301
|
||||||
|
302
|
||||||
|
303
|
||||||
|
304
|
||||||
|
305
|
||||||
|
306
|
||||||
|
307
|
||||||
|
308
|
||||||
|
309
|
||||||
|
310
|
||||||
|
311
|
||||||
|
312
|
||||||
|
313
|
||||||
|
314
|
||||||
|
315
|
||||||
|
316
|
||||||
|
317
|
||||||
|
318
|
||||||
|
319
|
||||||
|
320
|
||||||
|
321
|
||||||
|
322
|
||||||
|
323
|
||||||
|
324
|
||||||
|
325
|
||||||
|
326
|
||||||
|
327
|
||||||
|
328
|
||||||
|
329
|
||||||
|
330
|
||||||
|
331
|
||||||
|
332
|
||||||
|
333
|
||||||
|
334
|
||||||
|
335
|
||||||
|
336
|
||||||
|
337
|
||||||
|
338
|
||||||
|
339
|
||||||
|
340
|
||||||
|
341
|
||||||
|
342
|
||||||
|
343
|
||||||
|
344
|
||||||
|
345
|
||||||
|
346
|
||||||
|
347
|
||||||
|
348
|
||||||
|
349
|
||||||
|
350
|
||||||
|
351
|
||||||
|
352
|
||||||
|
353
|
||||||
|
354
|
||||||
|
355
|
||||||
|
356
|
||||||
|
357
|
||||||
|
358
|
||||||
|
359
|
||||||
|
360
|
||||||
|
361
|
||||||
|
362
|
||||||
|
363
|
||||||
|
364
|
||||||
|
365
|
||||||
|
366
|
||||||
|
367
|
||||||
|
368
|
||||||
|
369
|
||||||
|
370
|
||||||
|
371
|
||||||
|
372
|
||||||
|
373
|
||||||
|
374
|
||||||
|
375
|
||||||
|
376
|
||||||
|
377
|
||||||
|
378
|
||||||
|
379
|
||||||
|
380
|
||||||
|
381
|
||||||
|
382
|
||||||
|
383
|
||||||
|
384
|
||||||
|
385
|
||||||
|
386
|
||||||
|
387
|
||||||
|
388
|
||||||
|
389
|
||||||
|
390
|
||||||
|
391
|
||||||
|
392
|
||||||
|
393
|
||||||
|
394
|
||||||
|
395
|
||||||
|
396
|
||||||
|
397
|
||||||
|
398
|
||||||
|
399
|
||||||
|
400
|
||||||
|
401
|
||||||
|
402
|
||||||
|
403
|
||||||
|
404
|
||||||
|
405
|
||||||
|
406
|
||||||
|
407
|
||||||
|
408
|
||||||
|
409
|
||||||
|
410
|
||||||
|
411
|
||||||
|
412
|
||||||
|
413
|
||||||
|
414
|
||||||
|
415
|
||||||
|
416
|
||||||
|
417
|
||||||
|
418
|
||||||
|
419
|
||||||
|
420
|
||||||
|
421
|
||||||
|
422
|
||||||
|
423
|
||||||
|
424
|
||||||
|
425
|
||||||
|
426
|
||||||
|
427
|
||||||
|
428
|
||||||
|
429
|
||||||
|
430
|
||||||
|
431
|
||||||
|
432
|
||||||
|
433
|
||||||
|
434
|
||||||
|
435
|
||||||
|
436
|
||||||
|
437
|
||||||
|
438
|
||||||
|
439
|
||||||
|
440
|
||||||
|
441
|
||||||
|
442
|
||||||
|
443
|
||||||
|
444
|
||||||
|
445
|
||||||
|
446
|
||||||
|
447
|
||||||
|
448
|
||||||
|
449
|
||||||
|
450
|
||||||
|
451
|
||||||
|
452
|
||||||
|
453
|
||||||
|
454
|
||||||
|
455
|
||||||
|
456
|
||||||
|
457
|
||||||
|
458
|
||||||
|
459
|
||||||
|
460
|
||||||
|
461
|
||||||
|
462
|
||||||
|
463
|
||||||
|
464
|
||||||
|
465
|
||||||
|
466
|
||||||
|
467
|
||||||
|
468
|
||||||
|
469
|
||||||
|
470
|
||||||
|
471
|
||||||
|
472
|
||||||
|
473
|
||||||
|
474
|
||||||
|
475
|
||||||
|
476
|
||||||
|
477
|
||||||
|
478
|
||||||
|
479
|
||||||
|
480
|
||||||
|
481
|
||||||
|
482
|
||||||
|
483
|
||||||
|
484
|
||||||
|
485
|
||||||
|
486
|
||||||
|
487
|
||||||
|
488
|
||||||
|
489
|
||||||
|
490
|
||||||
|
491
|
||||||
|
492
|
||||||
|
493
|
||||||
|
494
|
||||||
|
495
|
||||||
|
496
|
||||||
|
497
|
||||||
|
498
|
||||||
|
499
|
||||||
|
500
|
||||||
|
true
|
||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1 @@
|
|||||||
|
https://judge.yosupo.jp/problem/set_xor_min
|
||||||
@@ -0,0 +1,209 @@
|
|||||||
|
#include <bits/stdc++.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
|
||||||
|
// ----- TYPES -----
|
||||||
|
typedef long long ll;
|
||||||
|
typedef pair<int, int> pii;
|
||||||
|
typedef vector<int> vi;
|
||||||
|
|
||||||
|
// ----- FILE IO -----
|
||||||
|
#define STDIN(filename) freopen(filename, "r", stdin)
|
||||||
|
#define STDOUT(filename) freopen(filename, "w", stdout)
|
||||||
|
#define FASTIO cin.tie(0)->sync_with_stdio(0)
|
||||||
|
#define STDIO(filename) \
|
||||||
|
FASTIO; \
|
||||||
|
string filenamee(filename); \
|
||||||
|
STDIN((filenamee + ".in").c_str()); \
|
||||||
|
STDOUT((filenamee + ".out").c_str())
|
||||||
|
#define NL '\n'
|
||||||
|
#define CM ", "
|
||||||
|
#define SP " "
|
||||||
|
|
||||||
|
// ----- FOR LOOPS -----
|
||||||
|
#define F(i, L, R) for (int i = L; i < R; i++)
|
||||||
|
#define FE(i, L, R) for (int i = L; i <= R; i++)
|
||||||
|
#define FD(i, L, R) for (int i = L; i > R; i--)
|
||||||
|
#define FDE(i, L, R) for (int i = L; i >= R; i--)
|
||||||
|
|
||||||
|
// ----- WEZ -----
|
||||||
|
#define takeI(n) \
|
||||||
|
int n; \
|
||||||
|
cin >> n
|
||||||
|
#define takeII(n, m) \
|
||||||
|
int n, m; \
|
||||||
|
cin >> n >> m
|
||||||
|
#define takeIII(n, m, k) \
|
||||||
|
int n, m, k; \
|
||||||
|
cin >> n >> m >> k
|
||||||
|
#define takeL(n) \
|
||||||
|
ll n; \
|
||||||
|
cin >> n
|
||||||
|
#define takeS(s) \
|
||||||
|
string s; \
|
||||||
|
cin >> s
|
||||||
|
#define takeV(v, n) \
|
||||||
|
vi v(n); \
|
||||||
|
for (auto &x : v) \
|
||||||
|
cin >> x
|
||||||
|
#define takeVL(v, n) \
|
||||||
|
vector<ll> v(n); \
|
||||||
|
for (auto &x : v) \
|
||||||
|
cin >> x
|
||||||
|
#define whileZ \
|
||||||
|
takeI(T); \
|
||||||
|
while (T--)
|
||||||
|
//
|
||||||
|
// ----- MAX MIN -----
|
||||||
|
#define REMAX(a, b) (a) = max((a), (b))
|
||||||
|
#define REMIN(a, b) (a) = min((a), (b))
|
||||||
|
|
||||||
|
// ----- PAIRS -----
|
||||||
|
#define fi first
|
||||||
|
#define se second
|
||||||
|
|
||||||
|
// ----- OUTPUT -----
|
||||||
|
#define YESNO(b) cout << ((b) ? "YES" : "NO") << NL
|
||||||
|
|
||||||
|
// ----- DEBUG -----
|
||||||
|
#define DBG(vari) cerr << #vari << " = " << (vari) << endl
|
||||||
|
#define DBG2(a, b) cerr << #a "=" << (a) << CM << #b "=" << (b) << endl
|
||||||
|
#define printA(a, L, R) FE(i, L, R) cerr << a[i] << (i == R ? '\n' : ' ')
|
||||||
|
#define printV(a) printA(a, 0, SZ(a) - 1)
|
||||||
|
|
||||||
|
// ----- STL DS
|
||||||
|
#define ALL(c) (c).begin(), (c).end()
|
||||||
|
#define SZ(c) ((int)(c).size())
|
||||||
|
#define SORT(c) sort(ALL(c))
|
||||||
|
#define RSORT(c) sort(ALL(c), greater<>())
|
||||||
|
#define UNIQ(c) SORT(c), (c).erase(unique(ALL(c)), (c).end())
|
||||||
|
#define pb push_back
|
||||||
|
|
||||||
|
// struct TrieNode {
|
||||||
|
// bool end = false;
|
||||||
|
// TrieNode* children[2];
|
||||||
|
// };
|
||||||
|
//
|
||||||
|
// void insert_into_trie(TrieNode* node, uint x) {
|
||||||
|
// // If we have exhausted x, this current node must be finished
|
||||||
|
// // For example if we have 0
|
||||||
|
// if (!x) {
|
||||||
|
// node->end = true;
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // Get last digit of x
|
||||||
|
// bool last_digit = x & 1;
|
||||||
|
//
|
||||||
|
// // Ensure child of this type exists
|
||||||
|
// if (!node->children[last_digit]) {
|
||||||
|
// node->children[last_digit] = new TrieNode;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// insert_into_trie(node->children[last_digit], x >> 1);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// bool remove_from_trie(TrieNode* node, uint x) {
|
||||||
|
// if (!x) {
|
||||||
|
// node->end = false;
|
||||||
|
// } else {
|
||||||
|
// bool last_digit = x & 1;
|
||||||
|
// if (node->children[last_digit] && remove_from_trie(node->children[last_digit], x >> 1)) {
|
||||||
|
// node->children[last_digit] = nullptr;
|
||||||
|
// };
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// if (!node->children[0] && !node->children[1] && !node->end) {
|
||||||
|
// delete node;
|
||||||
|
// return true;
|
||||||
|
// }
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// int find_min_from_trie(TrieNode* node, uint x) {
|
||||||
|
// if (!x) {
|
||||||
|
// return 0;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// bool last_digit = x & 1;
|
||||||
|
//
|
||||||
|
// if (node->children[last_digit]) {
|
||||||
|
// return (find_min_from_trie(node->children[last_digit], x >> 1)) ^ (last_digit << 1);
|
||||||
|
// } else if (node->children[!last_digit]) {
|
||||||
|
// return (find_min_from_trie(node->children[!last_digit], x >> 1)) ^ (!last_digit << 1);
|
||||||
|
// } else {
|
||||||
|
// return 0;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
struct Trie {
|
||||||
|
int cnt = 0;
|
||||||
|
Trie* ch[2] = {};
|
||||||
|
};
|
||||||
|
|
||||||
|
void insert(Trie* root, int x) {
|
||||||
|
Trie* cur = root;
|
||||||
|
for (int i = 30; i >= 0; i--) {
|
||||||
|
bool digit = x & (1 << i);
|
||||||
|
if (!cur->ch[digit]) {
|
||||||
|
cur->ch[digit] = new Trie;
|
||||||
|
}
|
||||||
|
cur->ch[digit]->cnt++;
|
||||||
|
cur = cur->ch[digit];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void remove(Trie* root, int x) {
|
||||||
|
Trie* cur = root;
|
||||||
|
for (int i = 30; i >= 0; i--) {
|
||||||
|
bool digit = x & (1 << i);
|
||||||
|
cur->ch[digit]->cnt--;
|
||||||
|
cur = cur->ch[digit];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int query(Trie* root, int x) {
|
||||||
|
Trie* cur = root;
|
||||||
|
int res = 0;
|
||||||
|
for (int i = 30; i >= 0; i--) {
|
||||||
|
bool digit = x & (1 << i);
|
||||||
|
if (cur->ch[digit] && cur->ch[digit]->cnt > 0) {
|
||||||
|
cur = cur->ch[digit];
|
||||||
|
} else {
|
||||||
|
cur = cur->ch[!digit];
|
||||||
|
res += 1 << i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
FASTIO;
|
||||||
|
takeI(t);
|
||||||
|
Trie* root = new Trie;
|
||||||
|
unordered_set<int> s;
|
||||||
|
while (t--) {
|
||||||
|
takeI(op);
|
||||||
|
uint x; cin >> x;
|
||||||
|
|
||||||
|
if (op == 0) {
|
||||||
|
// Insert into trie
|
||||||
|
if (!s.count(x)) {
|
||||||
|
s.insert(x);
|
||||||
|
insert(root, x);
|
||||||
|
}
|
||||||
|
} else if (op == 1) {
|
||||||
|
// Remove from trie
|
||||||
|
if (s.count(x)) {
|
||||||
|
s.erase(x);
|
||||||
|
remove(root, x);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Query trie
|
||||||
|
cout << query(root, x) << NL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user