Skip to content

Instantly share code, notes, and snippets.

class SelfLoveRecoveryProgram:
def __init__(self):
self.self_love_level = 50
def increase_self_love(self, amount):
self.self_love_level += amount
def decrease_self_love(self, amount):
self.self_love_level -= amount
@MikuroXina
MikuroXina / co_co.rs
Created August 13, 2023 02:06
Coordinate Compression utility with Rust.
use std::collections::BTreeMap;
#[derive(Debug)]
pub struct CoCo<K: Ord> {
forward: BTreeMap<K, usize>,
backward: Vec<K>,
}
impl<K: Ord> CoCo<K> {
pub const fn new() -> Self {
import json
import itertools
from typing import Any, Dict, List, Set, Tuple
from tqdm import tqdm
from functools import reduce
import operator
import math
def product_of_positive_factorials(multi_index):
@MikuroXina
MikuroXina / btree_multi_set.rs
Created June 17, 2023 17:59
A set structure which contains multiple same items with count of them, implemented for competitive programming in Rust.
use std::{borrow::Borrow, collections::BTreeMap, num::NonZeroUsize};
#[derive(Debug, Clone)]
pub struct BTreeMultiSet<T> {
counts: BTreeMap<T, NonZeroUsize>,
len: usize,
}
impl<T> BTreeMultiSet<T> {
pub const fn new() -> Self {
@MikuroXina
MikuroXina / setup-canvas.js
Last active June 7, 2023 06:17
Make `<canvas>` prepared for more pixel density display.
/**
* Make `<canvas>` prepared for more pixel density display and returns a 2D rendering context.
*
* @param canvas {HTMLCanvasElement} - To be preapared.
* @param devicePixelRatio {number} - The pixel ratio by device.
* @returns {Canvas2DRenderingContext} - The scaled 2D rendering context.
*/
export function setupCanvas(canvas, devicePixelRatio) {
const { width, height } = canvas;
canvas.width *= devicePixelRatio;
@MikuroXina
MikuroXina / fenwick.hpp
Created May 23, 2023 04:56
The implementation of Fenwick tree.
#pragma once
#include <vector>
class Fenwick {
std::vector<size_t> data;
size_t parent(size_t i) const {
return i - (i & (-i));
}
#pragma once
template<class T>
inline void insert_sort(vector<T> &vec, size_t g) {
for (size_t i = g; i < vec.size(); ++i) {
int v = vec[i];
int j = i - g;
while (0 <= j && v < vec[j]) {
vec[j + g] = vec[j];
j -= g;
#pragma once
#include <algorithm>
#include <optional>
enum class Direction {
North,
West,
East,
South,
#pragma once
#include <cmath>
#include <ostream>
const double PI = 3.141592653589793;
struct Quaternion {
double a, b, c, d;
@MikuroXina
MikuroXina / delim-space.cpp
Created May 21, 2023 02:59
Outputting numbers with delimitting spaces in C++ for competitive programming.
#include <algorithm>
#include <iostream>
#include <numeric>
using namespace std;
int main() {
int nums[3];
for (auto &num: nums) {
cin >> num;