This file contains 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
/** | |
* @param a - initial array | |
* @param query - query array - [li, ri, xi], li and ri are zero-based indexed | |
* @return array after processing all queries | |
*/ | |
vector<int> HandleRangeUpdateQuery (vector<int> a, vector<vector<int>> query) { | |
// creating another array to handle queries | |
vector<int> b (a.size() + 1, 0); | |
for (auto& q : query) { |
This file contains 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
/** | |
* @param a - initial array | |
* @param query - query array - [li, ri, xi], li and ri are zero-based indexed | |
* @return array after processing all queries | |
*/ | |
vector<int> HandleRangeUpdateQuery (vector<int> a, vector<vector<int>> query) { | |
// brute force method | |
// O(Q * N) slow method | |
for (auto& q: query) { | |
int l = q[0], r = q[1], x = q[2]; |