fork download
  1. /* Author haleyk10198 */
  2. /* 作者: haleyk10198 */
  3. #include <bits/stdc++.h>
  4.  
  5. #define MOD 1000000007
  6. #define LINF (1LL<<60)
  7. #define INF 2147483647
  8. #define PI 3.1415926535897932384626433
  9. #define ll long long
  10. #define pii pair<int,int>
  11. #define mp(x,y) make_pair((x),(y))
  12.  
  13. using namespace std;
  14.  
  15. string itos(int x){
  16. stringstream ss;
  17. ss << x;
  18. return ss.str();
  19. }
  20.  
  21. ll t[100010];
  22.  
  23. int n = 10;
  24.  
  25. void add(int pos, int v, ll *t){
  26. for( ++pos; pos; pos -= (pos & -pos))
  27. t[pos] += v;
  28. }
  29.  
  30. ll ask(int pos, ll *t){
  31. ll res = 0;
  32. for( ++pos; pos <= n; pos += (pos & -pos))
  33. res += t[pos];
  34. return res;
  35. }
  36.  
  37.  
  38. int main(){
  39. //freopen("input.txt","r",stdin);
  40. //freopen("output.txt","w",stdout);
  41. ios_base::sync_with_stdio(false);
  42. add(-1, -2, t);
  43. add(3, 2, t);
  44. add(1, -3, t);
  45. add(3, 3, t);
  46. add(5, -9, t);
  47. add(7, 9, t);
  48. for(int i = 0; i < n; i++)
  49. cout << ask(i, t) << (i+1 == '\n'? ' ': ' ');
  50. return 0;
  51. }
  52.  
Success #stdin #stdout 0s 4248KB
stdin
Standard input is empty
stdout
2 2 5 5 0 0 9 9 0 0