Skip to content

Instantly share code, notes, and snippets.

@fredbr
fredbr / mo_sum.cpp
Created September 8, 2017 01:19
Query of sum of intervals using square root decomposition.
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
const int maxq = 100010;
struct Query
{
int l, r, id;
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
// double tambem funciona na maioria dos casos
typedef long long ll;
struct line
@fredbr
fredbr / couriers_wtf.cpp
Last active January 31, 2018 17:35
KKKKKKK
#include <bits/stdc++.h>
#define ff first
#define ss second
using namespace std;
const int maxn = 510000;
const int maxlog = 22;
@fredbr
fredbr / miller_rabin.cpp
Last active June 23, 2018 00:14
Deterministic MIller-Rabin Primality Test to numbers up to 1e18 in O(log(n))
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
// modular multiplication to numbers up to 10^18 in O(1)
// __int128 is a well accepted gcc extension also compatible with clang
inline ll mul(ll a, ll b, ll c)
{
@fredbr
fredbr / hash.cpp
Last active February 20, 2018 21:44
Polynomial Hashing Algorithm for Strings
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
const int maxn = 100100;
// prime bigger than any value of the original string
const ull p = 113;
// codigo de gabriel pastori
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
int main() {
// codigo de lucio cardoso
#include <bits/stdc++.h>
using namespace std;
int n;
bool check(int a, int b, int c)
{
#include <bits/stdc++.h>
#define ff first
#define ss second
using namespace std;
// o resultado pode ultrapassar o inteiro normal
typedef long long ll;
typedef pair<ll, ll> ii;
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
string s;
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
const int inf = 0x3f3f3f3f;
int v[maxn];
int main()