fork(3) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. //our 2d Fenwick tree
  5. int F[1047][1047];
  6.  
  7. //add to element on position (x,y) value val
  8. void update(int x, int y, int v) {
  9. for(int i=x; i<1042; i+=i&-i)
  10. for(int j=y; j<1042; j+=j&-j)
  11. F[i][j]+=v;
  12. }
  13.  
  14. //get sum of rectangle (0,0,x,y)
  15. int get(int x, int y) {
  16. int res=0;
  17. for(int i=x; i>0; i-=i&-i)
  18. for(int j=y; j>0; j-=j&-j)
  19. res+=F[i][j];
  20. return res;
  21. }
  22.  
  23. //get sum of rectangle (x1,y1,x2,y2)
  24. int getRect(int x1, int y1, int x2, int y2) {
  25. return get(x2,y2)-get(x2,y1-1)-get(x1-1,y2)+get(x1-1,y1-1);
  26. }
  27.  
  28. int main() {
  29. return 0;
  30. }
Success #stdin #stdout 0s 6960KB
stdin
Standard input is empty
stdout
Standard output is empty