Skip to content

Instantly share code, notes, and snippets.

View cgiosy's full-sized avatar

cgiosy cgiosy

View GitHub Profile
@cgiosy
cgiosy / maxminaddsum.cpp
Last active July 9, 2020 02:36
Range Chmin Chmax Add Range Sum
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr int LG=32-__builtin_clz(200000-1);
constexpr ll MX=4e18;
int N, M, Q, t, l, r; ll x;
struct node {
ll sum, lz, mx, mx2, mn, mn2; int mxc, mnc;
@cgiosy
cgiosy / lazyseg.cpp
Last active March 26, 2025 04:36
쉽고 짧고 빠른, 세그먼트 트리 레이지 프로퍼게이션 & 비츠
/* struct node { ... }; */
int N;
node A[1<<LG_SZ];
void qry(int s=0, int e=N-1, int i=1) {
if(l<=s && e<=r && A[i].apply(e-s+1)) return;
int m=s+e>>1;
A[i*2].down(A[i], m-s+1);
A[i*2+1].down(A[i], e-m);
if(l<=m) qry(s, m, i*2);
if(r>m) qry(m+1, e, i*2+1);
@cgiosy
cgiosy / _mm256_mulmod_epu32.cpp
Last active April 2, 2023 10:07
AVX2 Barrett Reduction
#pragma GCC optimize("O3")
#pragma GCC target("avx,avx2,fma")
#include <cstdio>
#include <algorithm>
#include <x86intrin.h>
// https://arxiv.org/ftp/arxiv/papers/1407/1407.3383.pdf
struct Mod {
int m, s, n;
constexpr Mod(int const MOD): m(MOD), s(std::__lg(std::max(m, 4u)-1)-1), n((1ULL<<s+33)/m) {}
};