Skip to content

Commit 9b83c3e

Browse files
committed
New Snippets Added
1 parent f9c1707 commit 9b83c3e

38 files changed

+2118
-820
lines changed

C++.sublime-settings

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
// specific settings file, for example, "Preferences (Linux).sublime-settings".
1212
// Because of this, setting them here will have no effect: you must set them
1313
// in your User File Preferences.
14-
"font_face": "",
15-
"font_size": 9,
14+
"font_face": "Monospace",
15+
"font_size": 10,
1616

1717
// Valid options are "no_bold", "no_italic", "no_antialias", "gray_antialias",
1818
// "subpixel_antialias", "no_round" (OS X only), "gdi" (Windows only) and

Default (Linux).sublime-keymap

+737
Large diffs are not rendered by default.

GetCode.sublime-settings

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
//All settings are mandatory
3+
//Codeforces directory
4+
"parent_dir": "/home/abhiy13/Documents/COMP/CP",
5+
//Extension for new files
6+
"extension": "cpp",
7+
//Snippet to begin your new file
8+
"snippets": "template long",
9+
//Codechef directory
10+
"codechef_dir": "/home/abhiy13/Documents/COMP/CP/CC",
11+
//SPOJ directory
12+
"spoj_dir": "/home/abhiy13/Documents/COMP/CP/SPOJ",
13+
//virtual judge directory
14+
"vjudge_dir": "/home/abhiy13/Documents/COMP/CP/VJ"
15+
}

LCA.sublime-snippet

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<snippet>
2+
<content><![CDATA[
3+
const int MAXN = 5e4 + 10;
4+
const int MAXLG = 17;
5+
6+
long long par[MAXN][MAXLG];
7+
long long dist[MAXN];
8+
9+
vector <vector <long long>> V(MAXN , vector <long long>());
10+
11+
void dfs(long long v , long long pa = -1){
12+
par[v][0] = pa;
13+
if(pa + 1){
14+
dist[v] = dist[pa] + 1;
15+
}
16+
for(int i = 1 ; i < MAXLG ; ++i){
17+
par[v][i] = par[par[v][i - 1]][i - 1];
18+
}
19+
for(auto x : V[v]){
20+
if(pa != x){
21+
dfs(x , v);
22+
}
23+
}
24+
}
25+
26+
long long LCA(long long u , long long v){
27+
if(dist[u] < dist[v]){
28+
swap(u , v);
29+
}
30+
for(int i = MAXLG - 1 ; i >= 0 ; --i){
31+
if(par[u][i] + 1 > 0 && dist[par[u][i]] >= dist[v]){
32+
u = par[u][i];
33+
}
34+
}
35+
if(u == v){
36+
return u;
37+
}
38+
for(int i = MAXLG - 1 ; i >= 0 ; --i){
39+
if(par[u][i] - par[v][i]){
40+
v = par[v][i] , u = par[u][i];
41+
}
42+
}
43+
return par[u][0];
44+
}
45+
46+
long long getdis(long long u , long long v){
47+
return dist[u] + dist[v] - 2*dist[LCA(u , v)];
48+
}
49+
50+
]]></content>
51+
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
52+
<tabTrigger>least common ancestor</tabTrigger>
53+
<!-- Optional: Set a source to limit where the snippet will trigger -->
54+
<source>source.cpp , source.c++ , source.c , source.cxx , source.cc </source>
55+
</snippet>

LCAet.sublime-snippet

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<snippet>
2+
<content><![CDATA[
3+
const int MAXN = 1e5 + 10;
4+
5+
vector<vector<int>> G(MAXN);
6+
class LCA {
7+
vector<int> euler;
8+
vector<int> segtree;
9+
vector<int> first;
10+
vector<int> height;
11+
int N , es;
12+
public:
13+
LCA(int _N) : N(_N) {
14+
euler.reserve(2*N);
15+
first.resize(N);
16+
height.resize(N);
17+
dfs(0 , -1);
18+
es = (int) euler.size();
19+
segtree.resize(4*es + 1);
20+
init(0 , es - 1);
21+
}
22+
23+
void dfs(int u , int par = -1 , int h = 0) {
24+
height[u] = h;
25+
first[u] = (int) euler.size();
26+
euler.push_back(u);
27+
for(int x : G[u]) {
28+
if(x != par) {
29+
dfs(x , u , h + 1);
30+
euler.push_back(u);
31+
}
32+
}
33+
}
34+
35+
void init(int s , int e , int idx = 1) {
36+
if(s == e) {
37+
segtree[idx] = euler[s];
38+
return;
39+
}
40+
int mid = (s + e) >> 1;
41+
init(s , mid , (idx << 1));
42+
init(mid + 1 , e , ((idx << 1)|1));
43+
if(height[segtree[idx << 1]] > height[segtree[(idx << 1)|1]]) {
44+
segtree[idx] = segtree[(idx << 1)|1];
45+
} else {
46+
segtree[idx] = segtree[idx << 1];
47+
}
48+
return;
49+
}
50+
51+
int query(int s , int e , int l , int r , int idx = 1) {
52+
if(e < l || r < s) {
53+
return -1;
54+
}
55+
if(l <= s && e <= r) {
56+
return segtree[idx];
57+
}
58+
int mid = (s + e) >> 1;
59+
int lr = query(s , mid , l , r , idx << 1);
60+
int rr = query(mid + 1 , e , l , r , ((idx << 1)|1));
61+
if(lr == -1) return rr;
62+
if(rr == -1) return lr;
63+
return height[lr] > height[rr] ? rr : lr;
64+
}
65+
66+
int lca(int l , int r) {
67+
int x = first[l] , y = first[r];
68+
if(x > y) swap(x , y);
69+
return query(0 , es - 1 , x , y);
70+
}
71+
};
72+
73+
]]></content>
74+
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
75+
<tabTrigger>LCA</tabTrigger>
76+
<!-- Optional: Set a scope to limit where the snippet will trigger -->
77+
<!-- <scope>source.python</scope> -->
78+
</snippet>

Package Control.last-run

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1537865003
1+
1547289227

0 commit comments

Comments
 (0)