Questions tagged [prefix-sum]
63 questions
1
vote
1 answer
How to compute bitwise-or on the segment fast?
Given a list of integers.
I wonder if it is possible to calculate bitwise OR on the segment for O(1) per query and O(n) of the premise? (Some prefix sums) (it is Easy to do this for O(log n) per query and O(n log n) of the premise, for example,…

Кирилл Раков
- 11
- 2
1
vote
0 answers
Using Deques for sliding window problems
I was looking at the problem Shortest Subarray with Sum at Least K where the most optimal solution uses a deque.
Since the array can have both positive and negative values, using the two pointer technique will not work. I understand why the 2…

Arat254
- 449
- 2
- 5
- 17
1
vote
0 answers
Find the index which partitions the arrays into 2 subarrays whose absolute difference of their sums is minimized
We have to find an index 'x' such that the absolute difference between
(A[1]+A[2]+..+A[x]) and (A[x+1]+A[x+2]+..+A[n]) for some x ,
is minimized.
I came across this post.
Here the author has asked to minimize the produc of the subarrays, so in my…

Avi solanki
- 53
- 1
- 6
1
vote
1 answer
prefix sum using CUDA
I am having trouble understanding a cuda code for naive prefix sum.
This is code is from https://developer.nvidia.com/gpugems/GPUGems3/gpugems3_ch39.html
In example 39-1 (naive scan), we have a code like this:
__global__ void scan(float *g_odata,…

noobie2023
- 721
- 8
- 25
1
vote
2 answers
glMapBufferRange maps just 1 in 4 values. Why?
I've been trying to run the compute shader - prefix sum demo provided at:
https://github.com/openglsuperbible/sb7code/blob/master/src/prefixsum/prefixsum.cpp
I used the exact code:
#define NUM_ELEMENTS 2048
float random_float()
{
static…

markwalberg
- 311
- 2
- 10
1
vote
2 answers
opencl- parallel reduction without local memory
Most of the algorithms for parallel reduction uses shared(local) memory.
Nvidia,AMD, Intel and so on.
But if devices has doesn't have shared(local) memory.
How can I do it?
If i use same algorithms but store temporary value on global memory, is it…

eclipse0922
- 158
- 2
- 15
1
vote
1 answer
Parallel computing for prefix sum using openMP (c code)
Have some problems with assigning parallel algorithm to prefix sum issue. I am using openMP for parallel implementation. I have the code in c as below.
Result showing:
seqsum[6] = 28 != parallelsum[6] = 34
Please advise. Thanks.
#include…

Orangeblue
- 229
- 1
- 5
- 15
1
vote
1 answer
how to write parallel prefix sum in c#?
I want to write a Parallel prefix sum in c#. i used this algorithm:
initial condition: list of n >= 1 elements stored in A[0...(n-1)]
final condition: each element A[i] contains A[0]+A[1]+...+A[i]
begin
spawn (p1,p2,...,p(n-1))
foe all pi where…

jalal rasooly
- 705
- 3
- 7
- 24
1
vote
1 answer
Assembly Language prefix sum issue
So I am tasked with writing assembly code that will perform a prefix sum on a set of numbers.
The example given was 2 4 6 -1 and the return needs to be 12 10 6. -1 serves as a stopper.
jmp main
prefix: addl %edx, %eax
…

JKT
- 19
- 4
1
vote
1 answer
Gathering results of MPI_SCAN
I have this array [1 2 3 4 5 6 7 8 9] and i am performing scan operation on that.
I have 3 mpi tasks and each task gets 3 elements then each task calculates its scan and returns result to master task
task 0 - [1 2 3] => [1 3 6]
task 1 - [4 5 6 ] =>…

user1423932
- 11
- 2
0
votes
0 answers
Having problems with the logic of prefix sums
I'm trying to solve this problem: https://open.kattis.com/problems/alicedigital
Basically my solution is to take inputs as a prefix sum array instead of storing the inputs themselves while also keeping track of the index of every minimum element in…
0
votes
1 answer
find the total number of subarrays with the ratio of 0's and 1's equal to x:y
question
given an array of elements 0, 1, 2 with find the total number of subarrays with the ratio of 0's and 1's equal to x:y.
input
5
1 1
0 1 2 0 1
output
6
\\5 is the size of array 0 1 2 0 1 are elements of the array 1 1 is x and y and now…

Abhinav
- 7
- 4
0
votes
1 answer
Why does my code to USACO Silver Breed Counting not work?
This is my code:
#include
using namespace std;
int main() {
freopen("bcount.in", "r", stdin);
freopen("bcount.out", "w", stdout);
int n, q;
cin >> n >> q;
vector holsteins(n);
vector guernseys(n);
…

okayatcp12
- 308
- 1
- 9
0
votes
2 answers
Loop-Level Prefix-Sum: Messed up partial sums
#include
#include
void prefix(int n, int A[n]){
//end of recursion
if(n==1) return;
int n2 = n/2;
//Array split
int L[n2];
int R[n-n2];
#pragma omp parallel for
for(int i=0;…

Rapiz
- 161
- 2
- 2
- 9
0
votes
6 answers
238.Product of Array Except Self-Leetcode
I have been trying out this problem on leetcode. 238.Product of array except self
Given an integer array nums, return an array answer such that
answer[i] is equal to the product of all the elements of nums except
nums[i].
The product of any prefix…

Rohan Sharma
- 55
- 1
- 4
- 10