zeyad_khattab's blog

By zeyad_khattab, history, 6 months ago, In English,

It is commonly known that we can use Fenwick Tree to perform 2 tasks :

1) calculate the prefix sum (a[1]+a[2]+...+a[idx-1]+a[idx]) up to some index

2) increment a certain index by a certain value

but, my question is how can we modify the fenwick tree implementation so that instead of calculating prefix sums, we are calculating suffix sums so the sum we are now querying is (a[idx]+a[idx+1]+...+a[n-1]+a[n]), so I tried to change the implementation by basically swapping the indices that are accessed in the update and the query functions and I tried submitting in different problems and the submissions are accepted and I wanted to know if someone had a proof of why does it work ?

Read more »

 
 
 
 
  • Vote: I like it
  • +1
  • Vote: I do not like it

By zeyad_khattab, history, 7 months ago, In English,

How can we solve the following problem efficiently (I am mainly looking for a Segment Tree solution) ? Given an array of integers A of size N , and Q queries of the form L,R,X we need to find the minimum index i such that L<=i<=R and A[i]>=X 1<=L<=R<=N and |X|<=10^9 1<=N<=10^5 1<=Q<=10^5 |A[i]|<=10^9 for 1<=i<=N

Read more »

 
 
 
 
  • Vote: I like it
  • +7
  • Vote: I do not like it

By zeyad_khattab, history, 9 months ago, In English,

Can someone help me solve this problem ? 101755D - Трансферное окно My approach was to build a graph with the players as the nodes and there is an edge between player a and player b if I can exchange a with b then I created 2 nodes; Source and Sink. Then I added edges from from the Source to players I have and edges from players I want to the Sink, and applied max flow on this graph. All edges have capacity one. But then, I cannot construct the solution. My code (which gets WA at test 8) https://ideone.com/U4EjyO

Read more »

 
 
 
 
  • Vote: I like it
  • +4
  • Vote: I do not like it