Update every p sequentially but use fenwick tree for sums of p
Moved v calculation to fenwick tree, always update v on power update
Instead of calling fgets for every line, call read once and strtok for each line
Increased buffer size to 10MB, allocated on the heap
Changed from fenwick trees to segment trees, still not fast enough