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; | |
class node{ | |
public: | |
long long maxSum,prefixSum,suffixSum,sum; | |
void setValue(int value){ | |
maxSum=prefixSum=suffixSum=sum=value; | |
} | |
void specifyNode(node &left,node &right){ | |
sum = left.sum+right.sum; |
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; | |
int maxRange(int *arr,int llimit,int hlimit){ | |
int max_value = arr[llimit]; | |
for(int i=llimit;i<hlimit;i++){ | |
if(max_value<arr[i]) max_value = arr[i]; | |
} | |
return max_value; | |
} | |
int main(){ |
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; | |
void buildSegment(int *arr,int *arr_value,int node,int llimit,int hlimit){ | |
if(llimit==hlimit){ | |
arr_value[node-1]= arr[llimit]; | |
return; | |
}else{ | |
int mid = (llimit+hlimit)/2; | |
buildSegment(arr,arr_value,2*node,llimit,mid); | |
buildSegment(arr,arr_value,2*node+1,mid+1,hlimit); |