Created
June 10, 2021 13:05
-
-
Save maskmanlucifer/97d8a0758bb4f2759bed95d1b82d61b4 to your computer and use it in GitHub Desktop.
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
>> BIT aka Fenwick tree. | |
>>> Resources: | |
Tutorial no.1: https://cp-algorithms.com/data_structures/fenwick.html | |
Tutorial no.2: https://www.youtube.com/watch?v=CWDQJGaN1gY | |
Visualization: https://visualgo.net/bn/fenwicktree?slide=1 | |
>>> Implementation: | |
const int N=200000; | |
int bit[N]; | |
int pres(int idx) | |
{ | |
int ans=0; | |
while(idx>0) | |
{ | |
ans+=bit[idx]; | |
idx-=idx&-idx; | |
} | |
return ans; | |
} | |
void update(int idx,int val,int n) | |
{ | |
while(idx<=n) | |
{ | |
bit[idx]+=val; | |
idx+=idx&-idx; | |
} | |
} | |
int rsm(int l, int r) | |
{ | |
return pres(r) - pres(l-1); | |
} | |
>>> Problems: | |
Problem-1: https://www.spoj.com/problems/INVCNT/ | |
Solution : https://pastebin.com/embed_iframe/ZGheLfLF | |
Problem-2 : https://codeforces.com/contest/1042/problem/D | |
Solution: https://codeforces.com/contest/1042/submission/90062975 | |
Problem-3: https://codeforces.com/contest/459/problem/D | |
Solution: https://codeforces.com/contest/459/submission/90060302 | |
Problem-4: https://codeforces.com/contest/1401/problem/E | |
Solution: https://codeforces.com/contest/1401/submission/90651339 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment