Last active
August 29, 2015 14:04
-
-
Save rkkautsar/2737ea5ae4cf03c6ba45 to your computer and use it in GitHub Desktop.
Programming Contest Template
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
// typedef | |
typedef long long ll; | |
typedef pair<int,int> ii; | |
typedef pair<double,double> dd; | |
typedef pair<int,ii> iii; | |
typedef pair<double,dd> ddd; | |
typedef vector<ll> vll; | |
typedef vector<int> vi; | |
typedef vector<double> vd; | |
typedef vector<string> vs; | |
typedef vector<char> vc; | |
typedef vector<ii> vii; | |
typedef vector<vi> vvi; | |
typedef vector<vd> vvd; | |
typedef vector<vc> vvc; | |
typedef vector<bool> vb; | |
//defines | |
#define abs(_x) ((_x)<0?-(_x):(_x)) | |
#define REP(_x) for(int __x=0;__x<_x;++__x) | |
#define mp(_x,_y) make_pair((_x),(_y)) | |
#define PI 3.1415926535897932385 | |
#define EPS 1e-9 | |
#define INF 0x7FFFFFFF | |
#define INFLL 0x7FFFFFFFFFFFFFFFLL | |
#define ceildiv(_a,_b) ((_a)%(_b)==0?(_a)/(_b):((_a)/(_b))+1) | |
class UFDS{ | |
private: | |
vi parent,rank; | |
int disjoint; | |
public: | |
UFDS(){} | |
UFDS(const int &n){ | |
rank.resize(n,0); | |
parent.resize(n); | |
disjoint=n; | |
for(int i=0;i<n;++i)parent[i]=i; | |
} | |
int findSet(int i){ return (parent[i]==i)? i : (parent[i]=findSet(parent[i])); } | |
bool isSameSet(int i,int j){return findSet(i)==findSet(j);} | |
void unionSet(int i,int j){ | |
if(!isSameSet(i,j)){ | |
int x=findSet(i), y=findSet(j); | |
if(rank[x]>rank[y]){ | |
parent[y]=x; | |
} | |
else { | |
parent[x]=y; | |
if(rank[x]==rank[y]) ++rank[y]; | |
} | |
--disjoint; | |
}} | |
int countDisjointSet(){ return disjoint; } | |
}; | |
class BIT{ | |
private: | |
vi tree; | |
int size; | |
public: | |
BIT(const int &n){ | |
size=n+1; | |
tree.resize(n+1,0); | |
} | |
void update(int x,const int &d){ | |
while(x<size) tree[x]+=d, x+=x&(-x); | |
} | |
int sum(int x){ | |
int sum=0; | |
while(x) sum+=tree[x], x-=x&(-x); | |
return sum; | |
} | |
}; | |
int main(int argc, char **argv){ | |
ios_base::sync_with_stdio(0); | |
cin.tie(0); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment