Last active
May 16, 2025 11:14
-
-
Save keyansheng/6cebfddf51a2300e88f4d98da6309c8e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BasedOnStyle: Google | |
IndentWidth: 8 | |
UseTab: Always |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://codeforces.com/blog/entry/62393 | |
struct custom_hash { | |
static uint64_t splitmix64(uint64_t x) { | |
// http://xorshift.di.unimi.it/splitmix64.c | |
x += 0x9e3779b97f4a7c15; | |
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; | |
x = (x ^ (x >> 27)) * 0x94d049bb133111eb; | |
return x ^ (x >> 31); | |
} | |
size_t operator()(uint64_t x) const { | |
static const uint64_t FIXED_RANDOM = | |
chrono::steady_clock::now().time_since_epoch().count(); | |
return splitmix64(x + FIXED_RANDOM); | |
} | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
int main() { | |
std::ios::sync_with_stdio(false); | |
std::cin.tie(nullptr); | |
int n; | |
std::cin >> n; | |
std::cout << n << '\n'; | |
while (n--) { | |
int x; | |
std::cin >> x; | |
std::cout << x << '\n'; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bufio" | |
"fmt" | |
"os" | |
"strconv" | |
) | |
func main() { | |
scanner := bufio.NewScanner(os.Stdin) | |
writer := bufio.NewWriter(os.Stdout) | |
// scanner.Split(bufio.ScanWords) // slower | |
defer writer.Flush() | |
scanInt := func() int { | |
scanner.Scan() | |
n, _ := strconv.Atoi(scanner.Text()) | |
return n | |
} | |
n := scanInt() | |
fmt.Fprintln(writer, n) | |
for range n { | |
x := scanInt() | |
fmt.Fprintln(writer, x) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.BufferedReader; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
import java.io.PrintWriter; | |
import java.util.StringTokenizer; | |
class Main { | |
public static void main(String[] args) throws IOException { | |
var reader = | |
new BufferedReader(new InputStreamReader(System.in)) { | |
StringTokenizer tokenizer = new StringTokenizer(""); | |
String readToken() throws IOException { | |
while (!tokenizer.hasMoreTokens()) | |
tokenizer = new StringTokenizer(readLine()); | |
return tokenizer.nextToken(); | |
} | |
int readInt() throws IOException { | |
return Integer.parseInt(readLine()); | |
// return Integer.parseInt(readToken()); // slower | |
} | |
}; | |
var writer = new PrintWriter(System.out); | |
var n = reader.readInt(); | |
writer.println(n); | |
while (n-- > 0) { | |
var x = reader.readInt(); | |
writer.println(x); | |
} | |
writer.close(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import sys | |
def main(): | |
readline = sys.stdin.readline | |
write = sys.stdout.write | |
n = int(readline()) | |
write(f"{n}\n") | |
for _ in range(n): | |
x = int(readline()) | |
write(f"{x}\n") | |
if __name__ == "__main__": | |
main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::io; | |
use std::io::Write; | |
fn main() -> Result<(), Box<dyn std::error::Error>> { | |
let buffer = io::read_to_string(io::stdin().lock())?; | |
let mut reader = buffer.split_ascii_whitespace(); | |
// let mut reader = buffer.lines(); //slower | |
let mut writer = io::BufWriter::new(io::stdout().lock()); | |
macro_rules! parse { | |
($t:ty) => { | |
reader.next().unwrap().parse::<$t>().unwrap() | |
}; | |
} | |
let n = parse![i32]; | |
writeln!(writer, "{n}")?; | |
for _ in 0..n { | |
let x = parse![i32]; | |
writeln!(writer, "{x}")?; | |
} | |
Ok(()) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SHELL := /bin/zsh | |
all: py java cpp go rs | |
py: Main.py | |
for i in {1..10}; diff -q in <( time < in ./Main.py ) | |
java: Main.class | |
for i in {1..10}; diff -q in <( time < in java Main ) | |
cpp: Main-cpp | |
for i in {1..10}; diff -q in <( time < in ./Main-cpp ) | |
go: Main-go | |
for i in {1..10}; diff -q in <( time < in ./Main-go) | |
rs: Main-rs | |
for i in {1..10}; diff -q in <( time < in ./Main-rs ) | |
Main.py: fast_io.py | |
black fast_io.py | |
cp -ac fast_io.py Main.py | |
Main.class: fast_io.java | |
./google-java-format -a -i fast_io.java | |
javac fast_io.java | |
Main-cpp: fast_io.cpp | |
clang-format -i fast_io.cpp | |
g++-14 -O2 -o Main-cpp fast_io.cpp | |
Main-go: fast_io.go | |
goimports -w fast_io.go | |
go build -o Main-go fast_io.go | |
Main-rs: fast_io.rs | |
rustfmt fast_io.rs | |
rustc -O -o Main-rs fast_io.rs | |
clean: | |
rm -f Main* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://codeforces.com/blog/entry/10124 | |
template <typename T> | |
struct number_iterator : std::iterator<random_access_iterator_tag, T> { | |
T v; | |
number_iterator(T _v) : v(_v) {} | |
operator T&() { return v; } | |
T operator*() const { return v; } | |
}; | |
template <typename T> | |
struct number_range { | |
T b, e; | |
number_range(T b, T e) : b(b), e(e) {} | |
number_iterator<T> begin() { return b; } | |
number_iterator<T> end() { return e; } | |
}; | |
/* make_pair like functions for our range type */ | |
template <typename T> | |
number_range<T> range(T e) { | |
return number_range<T>(0, e); | |
} | |
// inclusive range | |
template <typename T> | |
number_range<T> range(T b, T e) { | |
return number_range<T>(b, e); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
println!( | |
"Hello, my vector is {}!", | |
vec![1, 2, 3, 4, 5, 6, 7, 8] | |
.iter() | |
.map(|x| x + 3) | |
.fold(0, |acc, x| acc + x) | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment