Skip to content

Instantly share code, notes, and snippets.

@hjroh0315
hjroh0315 / ringbuffer.cpp
Created March 8, 2024 17:30
fixed capacity ring buffer implementation (shit turned out long af)
#include<bits/stdc++.h>
using namespace std;
template<class T,ll sz>
struct buffer
{
array<T,sz>data;
ll L=0,R=0,Lm=0,Rm=0;
buffer():L(0),R(0),Lm(0),Rm(0){}
T& operator[](int i){ll t=Lm+i;if(t>=sz)t-=sz;return data[t];}
@hjroh0315
hjroh0315 / baseline_yatteru.rb
Last active August 9, 2023 00:12
baseline code for stupid 2048 ai
class Array
def rot
self.transpose.map(&:reverse)
end
end
def left a
ar=a.dup
tmp=(1..4).map{[]}
merged=(1..4).map{[]}
(0..3).each do|i|
@hjroh0315
hjroh0315 / sf_dynamic.cpp
Created April 21, 2023 15:39
dynamic sort-fenwick using PBDS
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll=long long;
template<class T,class U>
using ord_map=tree<T,U,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
template<class T,class U>
using ord_multimap=tree<T,U,less_equal<T>,rb_tree_tag,tree_order_statistics_node_update>;
@hjroh0315
hjroh0315 / barrier.rb
Created January 20, 2023 14:47
barrier method optimization using nlsolve on ruby (buggy and inefficient tho)
require "bigdecimal"
require "bigdecimal/newton"
require "bigdecimal/util"
include Newton
class Function # :nodoc: all
def initialize(tval,ineq_constraints,maximize,dim)
@zero=BigDecimal("0.0")
@one=BigDecimal("1.0")
@two=BigDecimal("2.0")
@hjroh0315
hjroh0315 / path_scc.cpp
Last active December 9, 2022 21:05
Path-based SCC (Gabow)
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
using namespace std;
using ll=long long;
struct path_scc
{
stack<int,vector<int>>S,P;
@hjroh0315
hjroh0315 / fenwick.rb
Created December 5, 2022 00:40
fenwick in ruby (ig)
class Fenwick
def initialize(n)
@size=n
@data=[0]*(n+1)
end
def add(idx,v)
while idx<=@size
@data[idx]+=v
idx+=idx&-idx
end
@hjroh0315
hjroh0315 / auto3500.user.js
Created December 1, 2022 12:53
everything is *3500
// ==UserScript==
// @name what the f
// @namespace http://tampermonkey.net/
// @version 1
// @description everything is f*cking *3500
// @author chromate00
// @match https://codeforces.com/*
// @match http://codeforces.com/*
// @grant none
// @run-at document-end
@hjroh0315
hjroh0315 / p_rho.rb
Last active December 20, 2022 12:33
pollard rho in ruby
require'prime'
def pollard_rho(n)
stk=[n]
ans=[]
while stk.size>0 do
cn=stk.pop
#p cn
next if cn==1
if cn%2==0
@hjroh0315
hjroh0315 / skiplist_base.cpp
Last active November 25, 2022 14:13
pain 2
#include<bits/stdc++.h>
using namespace std;
struct Lehmer64
{
using state_t=__uint128_t;
using result_type=uint64_t;
state_t state;
uint64_t sm64(uint64_t x,uint64_t n)
{
@hjroh0315
hjroh0315 / skiplist_segtree.cpp
Created October 28, 2022 10:52
Proof of concept on using skip lists as segment trees. (RMQ is given as an example)
#include<random>
#include<vector>
using namespace std;
using ll=long long;
struct FakeSkipList
{
struct NodePack
{
int H=1;