From 313a5620c99f8a431fd6593f0d348984d0206df3 Mon Sep 17 00:00:00 2001 From: Prince Batra Date: Wed, 18 Oct 2017 22:30:19 +0530 Subject: [PATCH] Add files via upload Segment tree implementation. --- segment tree.txt | 470 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 470 insertions(+) create mode 100644 segment tree.txt diff --git a/segment tree.txt b/segment tree.txt new file mode 100644 index 00000000..68fc7387 --- /dev/null +++ b/segment tree.txt @@ -0,0 +1,470 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + +Sapphire Engine + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+

Sapphire Engine : Online Compiler and IDE

+

Sapphire Engine : Online Compiler and IDE

+

Sapphire Engine : Online Compiler and IDE

+
+
+
+
+
+
+
+
+
+ +
+
+
+
+ + + + +
+
+
+
+
x
#include <bits/stdc++.h>
 
1
#include <bits/stdc++.h>
2
using namespace std;
3
int tree[10000];
4
int arr[10000];
5
6
void update_tree(int node, int index, int st, int en, int val){
7
    if(st==en && index==st){
8
        tree[node]=val;
9
        return;
10
    }
11
    int mid=(st+en)/2;
12
    if(index<=mid)
13
        update_tree(2*node, index, st, mid,val);
14
    else
15
        update_tree(2*node+1, index, mid+1, en,val);
16
17
    tree[node]=tree[2*node]+tree[2*node+1];
18
}
19
int query_tree(int node,int qst,int qen,int st,int en)
20
{
21
    if(qst<=st && qen>=en){
22
        return tree[node];
23
    }
24
    if(qen<st || qst>en){
25
        return 0;
26
    }
27
28
    int mid=(st+en)/2;
29
    int l_arr=query_tree(2*node,qst,qen,st,mid);
30
    int r_arr=query_tree(2*node+1,qst,qen,mid+1,en);
31
    return l_arr+r_arr;
32
}
33
34
35
36
int build_tree(int node, int st, int en){
37
    //terminating condition
38
    if(st==en){
39
        tree[node]=arr[st];
40
        return tree[node];
41
    }
42
    int mid=(st+en)/2;
43
    int l_sum=build_tree(2*node,st,mid);
44
    int r_sum=build_tree(2*node+1,mid+1,en);
45
    tree[node] = l_sum + r_sum;
46
    return tree[node];
+
+
+ +
+ +
+
+
+
+ Custom Inputs +
+
+ +
+
+ +
+
+ +
+
+
+
+
+
+
+
+
+
+ + + + + + + + + + + + + + + + + +
Code IDStatusTime (sec)Exit Signal
30364C++ : Runtime Error - SIGSEGV0.461139
+
+
+
+
+
+ + + + + + + + + + + +
Standard Output
Standard output is empty
+
+
+
+
+
+
+
+
+ + + + + + + + + + + +
Standard Error
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+ + + + + + + + + + + + + + + + + + + +
+
+ + + \ No newline at end of file