fork download
  1. #include <bits/stdc++.h>
  2. #define FOR(i, a, b) for(int i = (a), _b = (b); i <= _b; ++i)
  3. #define fi first
  4. #define se second
  5. #define el "\n"
  6. #define pb push_back
  7. #define sz(a) (int)a.size()
  8. #define FILL(a, x) memset(a, x, sizeof(a))
  9.  
  10. using namespace std;
  11. typedef long long ll;
  12. typedef pair<int, int> ii;
  13. const int N = (int)1e6+3;
  14. int n;
  15. int IT[N];
  16.  
  17. void Update(int x, int v){
  18. for( ; x <= n; x += x & (-x)) IT[x] += v;
  19. }
  20.  
  21. ll Get(int x){
  22. ll res = 0;
  23. for( ; x >= 1; x -= x & (-x)) res += IT[x];
  24. return res;
  25. }
  26.  
  27. int main()
  28. {
  29. ios_base::sync_with_stdio(false);
  30. cin.tie(NULL); cout.tie(NULL);
  31. freopen("TH.inp", "r", stdin);
  32. freopen("TH.out", "w", stdout);
  33. cin >> n;
  34. Update(1, 3);
  35. Update(2, 5);
  36. cout<<Get(3);
  37. return 0;
  38. }
  39.  
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
Standard output is empty