Skip to content

Instantly share code, notes, and snippets.

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define MAXN 10000010
int gcd(int a, int b) { return a ? gcd(b % a, a) : b; }
// From dalvik/vm/native/dalvik_system_Zygote.c
/*
* Calls POSIX setgroups() using the int[] object as an argument.
* A NULL argument is tolerated.
*/
static int setgroupsIntarray(ArrayObject* gidArray)
{
gid_t *gids;
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
int X1[3];
int X2[3];
int Y1[3];
#include<iostream>
#include<cmath>
#include<stdio.h>
#define fr(i,a,b) for(i=a;i<=b;i++)
using namespace std;
const int maxn=1002;
const double pi=acos(-1.0);
const double limit=1e8;
const double zero=1e-10;
double s[maxn];
#include<iostream>
#include<vector>
#define fr(i,a,b) for(i=a;i<=b;i++)
using namespace std;
long long a,m,p,q,r,s,ans,pw[100],i,ca=0,now,tot;
vector<long long> len,len2;
vector<char> ty,ty2;
long long atleast(long long value){
if(value<=0)
return 0;
@msg555
msg555 / gist:3356863
Created August 15, 2012 06:07
Solution to Largest (Zero Carbon) Footprint (http://wcipeg.com/problem/ccc11s2p6)
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;
int X[10010];
int Y[10010];
vector<int> XS[10010];
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <cmath>
using namespace std;
double find(long long a, long long b, long long c, long long &d){
if(!b||!c)return -1;
d=ceil((double) a* (double) c /(double) b);
if(d>100000)return -1;
#include <iostream>
#include <map>
#include <cstring>
#include <cstdio>
#include <utility>
using namespace std;
template<class T> struct splnode {
splnode() : V(0), P(NULL) { C[0] = C[1] = NULL; fix(); }
@msg555
msg555 / linkcut.cpp
Created November 8, 2012 20:43
Solution to http://www.spoj.pl/ranks/DYNACON1/ implementing a fairly fast link-cut tree.
#include <iostream>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cassert>
using namespace std;
template<class T> struct splnode {
typedef splnode<T> node_t;
@msg555
msg555 / gist:4242182
Created December 8, 2012 22:04
Computes RSK tableau in O(N sqrt(N) log(N)) time
vector<vector<int> > bounded_rsk(const vector<int>& A, int k) {
vector<vector<int> > h(k);
for(int i = 0; i < A.size(); i++) {
int x = A[i];
for(int j = 0; j < k; j++) {
int p = lower_bound(h[j].begin(), h[j].end(), x) - h[j].begin();
if(p == h[j].size()) {
h[j].push_back(x);
break;
} else {