Skip to content

Instantly share code, notes, and snippets.

@sazid
Last active June 17, 2018 21:32
Show Gist options
  • Save sazid/c995a58907cad2514d90bcbf884f11c0 to your computer and use it in GitHub Desktop.
Save sazid/c995a58907cad2514d90bcbf884f11c0 to your computer and use it in GitHub Desktop.
Segment tree
int arr[5] = {4, 2, 3, 8, 1, 9};
int sum[5] = {4};
for (int i = 1; i < 5; i++) sum[i] = sum[i-1] + arr[i];
int a = 1, b = 3;
// print the sum for the range [a,b]
cout << sum[b]-sum[a-1] << endl;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment