Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
8da4e1f
Merge pull request #7 from kumaranshu72/segmentTree
kumaranshu72 Oct 2, 2018
ba7c008
made change
Illusion0-0 Oct 2, 2018
10c8126
Add files via upload
KSHITIJBITHEL Oct 2, 2018
9985388
Create heap.cpp
Rohit-Kmr Oct 2, 2018
290745c
added bubble sort
KSHITIJBITHEL Oct 2, 2018
ccb8426
Merge pull request #8 from Tarunyo/master
kumaranshu72 Oct 2, 2018
d912d22
Merge pull request #9 from Rohit-Kmr/master
kumaranshu72 Oct 2, 2018
9e56e47
Merge pull request #10 from KSHITIJBITHEL/master
kumaranshu72 Oct 2, 2018
1349527
Segement tree added for sum of given range problem.
harishsainik Oct 27, 2018
9bf19af
Merge pull request #11 from harishsainik/master
kumaranshu72 Oct 27, 2018
9b206c5
Create Fenwick-tree.cpp
singhsourabh Oct 27, 2018
f398148
segment tree with lazy propagation
amitXsarkar Oct 27, 2018
88dbb70
Added Binary Indexed Tree
raunak96 Oct 27, 2018
9b651a4
Create k-dimensionaltree.cpp
ShreyaPrabhu Oct 27, 2018
cd4a299
add data structure array
bamsarts Oct 27, 2018
fd0e48e
added quick sort
Bak-JH Oct 27, 2018
161f39a
Fixed some spelling errors and reorganized the html
dchenmei Oct 27, 2018
ee380c8
queue
KVVaisakh Oct 27, 2018
cbdfd55
Merge pull request #23 from KVVaisakh/patch-1
kumaranshu72 Oct 27, 2018
ca8bc08
Merge pull request #21 from dchenmei/typo
kumaranshu72 Oct 27, 2018
0a398ca
Merge pull request #20 from Bak-JH/master
kumaranshu72 Oct 27, 2018
5378326
Merge pull request #19 from bamsarts/arrays
kumaranshu72 Oct 27, 2018
d4b5efd
Merge pull request #18 from ShreyaPrabhu/k-dimensional-tree
kumaranshu72 Oct 27, 2018
a862db3
Merge pull request #17 from raunak96/master
kumaranshu72 Oct 27, 2018
f6cb469
Merge pull request #15 from amitXsarkar/master
kumaranshu72 Oct 27, 2018
687037d
Create Segment_tree(without_recursion).cpp
avanthakkar Oct 27, 2018
2496b23
Create Fenwick_tree(Binary_indexed_tree).cpp
avanthakkar Oct 27, 2018
e35bba2
Merge pull request #25 from 12abcd45/patch-2
kumaranshu72 Oct 28, 2018
b8c9f9f
Merge pull request #14 from singhsourabh/master
kumaranshu72 Oct 28, 2018
a11f015
Merge pull request #24 from 12abcd45/patch-1
kumaranshu72 Oct 28, 2018
89d3b19
Added list data structure
Bak-JH Oct 29, 2018
d22dd93
Data Structures added
SakritiDixit Oct 30, 2018
29d9da8
Added quick sort algo implementation in python
RathodKinjal76 Oct 31, 2018
001dbf5
Update README.md
kumaranshu72 Feb 26, 2019
bf3e246
Merge pull request #28 from SakritiDixit/master
kumaranshu72 Oct 27, 2020
f40e598
Merge pull request #29 from RathodKinjal76/master
kumaranshu72 Oct 27, 2020
2d5f038
Merge pull request #27 from Bak-JH/master
kumaranshu72 Oct 27, 2020
e5312af
Create hello.cpp
kumaranshu72 Oct 23, 2021
c8f4bb8
Merge pull request #31 from kumaranshu72/kumaranshu72-patch-1
kumaranshu72 Oct 23, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions BIT_subarrays_sum_in_given_range.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#include<bits/stdc++.h>
using namespace std;
#define N 500000
pair<long long int,int> a[N+1],c[N+1];
long long int b;
int bit[N+1];
void update(int ind,int n)
{
while(ind<=n)
{
bit[ind]++;
ind+=ind&(-ind);
}
}
long long int que(int ind)
{
long long int ans=0;
while(ind>0)
{
ans+=bit[ind];
ind-=ind&(-ind);
}
return ans;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int n,q;
long long int cnt,l,r;
cin>>n>>q;
for(int i=1;i<=n;i++)
cin>>b,a[i].first+=a[i-1].first+b,a[i].second=i,c[i]=a[i];
sort(c+1,c+n+1);
for(int i=1;i<=n;i++)
a[c[i].second].second=i;
while(q--)
{
cnt=0;
cin>>l>>r;
for(int i=1;i<=n;i++)
{
int h=upper_bound(c+1,c+n+1,make_pair(a[i].first-l,INT_MAX))-c;
int lo=lower_bound(c+1,c+n+1,make_pair(a[i].first-r,INT_MIN))-c;
if(a[i].first>=l && a[i].first<=r)
cnt+=1;
cnt+=que(h-1)-que(lo-1);
update(a[i].second,n);
}
cout<<cnt<<endl;
for(int i=1;i<=n;i++)
bit[i]=0;
}
return 0;
}
10 changes: 4 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<ul>
<li>Algorithms can br from any field(ML etc) and any language</li>
<li>
Add Comments. Your code should be self documented
</li>
<li> Use relivant names</li>
</ul>
<li> Algorithms can be from any field (ML etc) and language </li>
<li> Add Comments. Your code should be self documented </li>
<li> Use relevant names </li>
</ul>
1 change: 1 addition & 0 deletions DisjointSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ int main(){
cout<<i<<" "<<ds.Find(i)<<"\n"; // displays parent of i'th indes is ds.Find(i)
// alternatively we can say that those that have same ds.find() values belong to same set
}
return 0;
}


30 changes: 30 additions & 0 deletions Fenwick-tree.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <bits/stdc++.h>
#define LSB(x) x&-x
using namespace std;
int BIT[1000], A[1000], N;
void update(int idx, int val){
for(; idx<=N; idx+= LSB(idx)){
BIT[idx] += val;
}
}

int query(int idx){
int sum = 0;
for(; idx>0; idx-= LSB(idx)){
sum += BIT[idx];
}
return sum;
}

int main(){
N = 16;
int l,r;
//creating BIT
for(int i = 1; i<=N; i++){
A[i] = i;
update(i, A[i]);
}
//range query
cin >> l >> r;
cout << query(r) - query(l-1);
}
32 changes: 32 additions & 0 deletions Fenwick_tree(Binary_indexed_tree).cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include<bits/stdc++.h>
#define ll long long int
using namespace std;

ll Fen_tree[100005], a[100005], n;
void updt(ll x, ll val)
{
for(; x <= n; x += x&-x)
Fen_tree[x] += val;
}
ll query(ll val)
{
ll sum = 0;
for(; val > 0; val -= val&-val)
sum += Fen_tree[val];
return sum;
}

int main()
{
cin>>n;
ll i,x,l,r;
for(i = 1; i <= n; i++)
{
cin>>a[i];
updt(i, a[i]);
}
cin>>x>>l>>r;
cout<<"Sum of first "<<x<<" elements is "<<query(x)<<endl;
cout<<"Sum of all elements in range "<<"[ "<<l<<" , "<<r<<" ] is "<<(query(r)-query(l-1));
return 0;
}
109 changes: 109 additions & 0 deletions List.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#include <iostream>

template < typename T >
class Node
{
public:
T data;
Node* next;

Node (T data) { this->data = data; }
Node(){}
};

template < typename T >
class List
{
public:
int count;
Node<T>* head = new Node<T>;

List ();

void add (T data);
void remove (int index);
int size () { return this->count; }
void print ();
};

template <typename T>
List<T>::List ()
{
this->count = 0;
this->head->next = nullptr;
this->head->next = nullptr;
}

template < typename T >
void List<T>::add (T data)
{
Node<T>* newNode = new Node<T>(data);
newNode->next = nullptr;

if (head->next == nullptr) { head->next = newNode; }
else {
Node<T>* temp = head;
while (temp->next != nullptr)
temp = temp->next;
temp->next = newNode;
}

++List::count;
}

template <typename T>
void List<T>::remove (int index)
{
Node<T>* temp = head;
Node<T>* target = head;

if(count < index) { std::cout << "out of index!" << std::endl; return; }

for (int i = 0; i < index; ++i) {
temp = temp->next;
target = target->next;
}
target = target->next;

temp->next = target->next;
target->next = nullptr;
delete target;
--List::count;
}

template <typename T>
void List<T>::print ()
{
Node<T>* iterator;
iterator = head;

while(iterator->next != nullptr) {
iterator = iterator->next;
std::cout << iterator->data << " ";
}
std::cout << std::endl;
}

int main ()
{
// These codes are test
List<char> test;
test.add ('A');
test.print ();

test.add ('B');
test.print ();

test.add ('C');
test.print ();

test.remove(5);
test.print();

test.remove(1);
test.print();

return 0;
}


3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
<h1> Add only Advanced Data Structrues</h1>
<h1> Some cool data structures Repo</h1>
<p> This repo contains the implementation of various data structus in different languages.</p>
67 changes: 67 additions & 0 deletions Segment Tree Lazy Propagation.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll tree[400001],tree1[400001];
void lazy(ll node,ll l,ll r)
{
tree[node]+=tree1[node]*(r-l+1);
if(l==r)
{
tree1[node]=0;
return;
}
tree1[2*node]+=tree1[node];
tree1[2*node+1]+=tree1[node];
tree1[node]=0;
}
ll q0(ll node,ll l,ll r,ll l1,ll r1,ll val=0){
//cout<<val<<endl;
lazy(node,l,r);
if(l1<=l&&r<=r1)
{
tree1[node]+=val;
lazy(node,l,r);
//cout<<tree[node]<<" ";
return tree[node];
}
else if(r<l1||r1<l)
{
return 0;
}
else{
ll mid=(l+r)/2;

ll x1=q0(2*node,l,mid,l1,r1,val);
ll x2=q0(2*node+1,mid+1,r,l1,r1,val);
tree[node]=tree[2*node]+tree[2*node+1];
return x1+x2;
}
}
int main() {
// your code goes here
ll t;
cin>>t;
while(t--)
{
ll n,m;
cin>>n>>m;
ll i,j,k;
memset(tree,0,sizeof(tree));
memset(tree1,0,sizeof(tree1));
while(m--)
{
ll x,p,q,v;
cin>>x;
if(x==0)
{
cin>>p>>q>>v;
q0(1,1,n,p,q,v);
}
else{
cin>>p>>q;
cout<<q0(1,1,n,p,q)<<endl;
}
}
}
return 0;
}
Loading