Skip to content

Instantly share code, notes, and snippets.

@IvanIsCoding
IvanIsCoding / frequencia.cpp
Last active July 11, 2017 15:23
Solução OBI 2014
// Ivan Carvalho
// Frequência - Fase 2 Programação Nível 2 - OBI 2014
// O(r*n*log(n))
#include <bits/stdc++.h>
#define MP make_pair
using namespace std;
typedef pair<int,int> ii;
typedef struct node* pnode;
const int MAXN = 1e5 + 10;
const int MAXR = 51;
@IvanIsCoding
IvanIsCoding / ciclovias.cpp
Last active July 11, 2017 15:23
Solução OBI 2016
// Ivan Carvalho
// Ciclovias - Fase 2 Programação Nível 2 - OBI 2016
// O(m*log(n))
#include <bits/stdc++.h>
using namespace std;
typedef struct node* pnode;
const int MAXN = 1e5 + 10;
struct node{
int val;
pnode l,r;
@IvanIsCoding
IvanIsCoding / intervalo_treap.cpp
Last active July 11, 2017 15:23
Seletiva IOI 2014
// Ivan Carvalho
// Intervalo - Seletiva IOI - OBI 2014
// Alternative solution : O(n*lg(n))
#include <bits/stdc++.h>
using namespace std;
typedef struct node* pnode;
typedef long long ll;
struct node{
pnode l,r;
ll puro,total;
@IvanIsCoding
IvanIsCoding / cachecol.cpp
Last active July 11, 2017 15:23
Solução OBI 2013
// Ivan Carvalho
// Cachecol da Vovó Vitória - Fase 2 Programação Nível 2 - OBI 2013
// O(log(n))
#include <bits/stdc++.h>
#define REP(A,B) for(long long A=0;A<B;A++)
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll MAXK = 2;
typedef struct matrix{
@IvanIsCoding
IvanIsCoding / catalogo.cpp
Last active July 11, 2017 15:23
Solução OBI 2013
// Ivan Carvalho
// Catálogo de Músicas - Fase 1 Programação Nível 2 - OBI 2013
// O(n*log(n))
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3*1e5 + 10;
int ponteiro,N,n,tam[MAXN],filhos[MAXN],nivel[MAXN],total,resp;
set<int> grafo[MAXN];
map<string,int> conversao;
void dfs1(int x){
@IvanIsCoding
IvanIsCoding / simulador.cpp
Last active July 11, 2017 15:24
Solução OBI 2009
// Ivan Carvalho
// Simulador - Fase 2 Programação Nível 2 - OBI 2009
// O(M^2)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct range{
ll ini,fim;
ll A,B;
range(ll _A,ll _B,ll add = 0){
@IvanIsCoding
IvanIsCoding / trafego.cpp
Last active July 11, 2017 15:24
Seletiva IOI 2014
// Ivan Carvalho
// Tráfego - Seletiva IOI - OBI 2014
#include <bits/stdc++.h>
#define MAXN 50010
using namespace std;
typedef pair<int,int> ii;
struct aresta{
int alvo,d,g,r;
};
int N,M;
@IvanIsCoding
IvanIsCoding / desvio.cpp
Last active July 11, 2017 15:24
Maratona de Programação 2011
// Ivan Carvalho
// Desvio de Rua - Maratona de Programação 2011
#include <bits/stdc++.h>
#define MAXN 1001
using namespace std;
vector<int> grafo[MAXN],transposto[MAXN],bidirecional[MAXN],tipo[MAXN];
int processado[MAXN],n,m,pai[MAXN],conjuntos,iteracao,hapontes;
int dfs_low[MAXN],dfs_num[MAXN],dfs_parent[MAXN],pontosdearticulacao[MAXN],dfsNumberCounter,dfsRoot,dfsRootChildren;
int find(int x){
if(x == pai[x]) return x;
@IvanIsCoding
IvanIsCoding / fila.cpp
Last active July 11, 2017 15:24
Solução OBI 2015
// Ivan Carvalho
// Fila - Fase 2 Programação Nível 2 - OBI 2015
// O(n*log(n))
#include <bits/stdc++.h>
using namespace std;
typedef struct node* pnode;
struct node{
int prior,size,puro,maximo;
pnode l,r;
node(int puro) : l(NULL),r(NULL),puro(puro),maximo(puro),size(1), prior(rand()) {}
@IvanIsCoding
IvanIsCoding / codreverso_treap.cpp
Last active July 11, 2017 15:24
Seletiva IOI 2013
// Ivan Carvalho
// Código Reverso - Seletiva IOI - OBI 2013
// Alternative solution : O(n*lg(n))
#include <bits/stdc++.h>
typedef struct node* pnode;
const int MAXN = 500010;
int entrada[MAXN],resposta[MAXN],N;
struct node{
int key,prior,size;
pnode l,r;