Answers for "Creating segment for sqrt decomposition"

C++
0

Creating segment for sqrt decomposition

int segment[10000];
int preprocess(int input[], int n) { 
    int current_segment = -1; 
    int segment_size = sqrt(n); 
   
    for (int i=0; i<n; i++) { 
        if (i % segment_size == 0) { 
            current_segment++;  //new segment
        } 
        segment[current_segment] += input[i]; 
    } 
    
    return segment_size;
}
Posted by: Guest on August-03-2021

Browse Popular Code Answers by Language