We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
As usual, I think the editorial code/approach is needlessly compex. There's no need for any fancy data structures like segment tree or Fenwick tree, just a few standard arrays:
WARNING: Low-key spoilers ahead. No implementation code, just declarations.
intA[200010];// Input arrayintnext_index[200010];// next_index[i] is the next index j such that A[i] = A[j], or -1 if no such index existsintprev_index[200010];// prev_index[i] is the previous index j such that A[i] = A[j], or -1 if no such index existsboolstart_index[200010];// start_index[i] = true if DP algorithm should be run on a segment beginning at index ilonglongDP[200010][2]={0};// DP[i][0] = count of binary subsets ending with a zero bit at index i// DP[i][1] = count of binary subsets ending with a one bit at index ilonglongsums[200010][2]={0};// Prefix sum array of values in DP
Anyway, I still found this to be a very interesting and fun challenge. Sadly, I'm starting to run out of DP-related problems to solve on this site... :/
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Colorful Polygon
You are viewing a single comment's thread. Return to all comments →
As usual, I think the editorial code/approach is needlessly compex. There's no need for any fancy data structures like segment tree or Fenwick tree, just a few standard arrays:
WARNING: Low-key spoilers ahead. No implementation code, just declarations.
Anyway, I still found this to be a very interesting and fun challenge. Sadly, I'm starting to run out of DP-related problems to solve on this site... :/