bhupixb

BIT class

Jan 23rd, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define P pair < int, int >
  5. #define s second
  6. #define f first
  7. #define pb push_back
  8. #define all(v) v.begin(), v.end()
  9. #define rep(i,a,n) for(int i = a; i <= n; ++i)
  10. #define lb(v, x) lower_bound(all(v), x) - v.begin()
  11. #define up(v, x) upper_bound(all(v), x) - v.begin()
  12. #define fo(i, n) for (int i = 1; i <= n; ++i)
  13.  
  14. const int N = 1e6 + 5;
  15. int a[N];
  16. class bit{
  17. int bit[N];
  18. public:
  19. void add(int i, int val) {
  20. for( ; i < N; i += (i & -1))
  21. bit[i] += val;
  22. }
  23. int query(int i) {
  24. int ans(0);
  25. for(; i; i -= i & -i)
  26. ans += bit[i];
  27. return ans;
  28. }
  29. };
  30. int main(){
  31. ios_base::sync_with_stdio(NULL);
  32. cin.tie(NULL);
  33. cout.tie(NULL);
  34. bit obj;
  35. int n, q, l, r, k;
  36. cin >> n;
  37. fo(i, n)
  38. cin >> a[i];
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47. return 0;
  48. }
Add Comment
Please, Sign In to add comment