Skip to content

Instantly share code, notes, and snippets.

View bhushangawde's full-sized avatar
🎯
Focusing

Bhushan Gawde bhushangawde

🎯
Focusing
View GitHub Profile
// C++ program for range minimum
// query using segment tree
#include <bits/stdc++.h>
using namespace std;
// A utility function to get minimum of two numbers
int minVal(int x, int y) { return (x < y)? x: y; }
// A utility function to get the
// middle index from corner indexes.
@bhushangawde
bhushangawde / range_sum_query_mutable_leetcode.cpp
Created May 23, 2023 16:21 — forked from babhishek21/range_sum_query_mutable_leetcode.cpp
Range Sum Query for Mutable Arrays using Segment Trees
#include <bits/stdc++.h> // using GCC/G++11
using namespace std;
/**
* Range Sum Query for Mutable Arrays using Segment Trees (LeetCode)
* https://leetcode.com/problems/range-sum-query-mutable/
*
* Build a tree whose nodes represent the entire range. Its two children represent the two halves
* of this range. This continues down the tree with height log(n) until we reach the n individual
* leaves of the tree (each representing a single element).
// C++ program to show segment tree operations like construction, query
// and update
#include <bits/stdc++.h>
using namespace std;
// A utility function to get the middle index from corner indexes.
int getMid(int s, int e) { return s + (e -s)/2; }
/* A recursive function to get the sum of values in the given range
of the array. The following are parameters for this function.