11610

To solve the problem indexes of the array are also needed to be updated and queried. #include <cstdio> #include <vector> #include <cstring> #include <algorithm> #include <iostream> using namespace std; struct RevPrime{ int reversePrime; int factorCount; }; int prime[1000001]; RevPrime arr[80000]; int Bit[2][80000]; vector<int> vb; int k=1; int reverse(int a) { int num=0; while(a) { num*=10;

1428

The problem can be solved using Binary Indexed tree or Fenwick tree. #include <cstdio> #include <queue> #include <vector> #include <cstdlib> #include <cstring> #include <iostream> #include <string> #define SZ 100000+5 #define ll long long using namespace std; int arr[SZ]; ll Left[SZ],Right[SZ],sum[SZ]; int mx; ll Cumulative(int idx) { ll value=0; while(idx>0) { value += sum[idx]; idx -=

12532

/*****Binary Index tree 12532******/ #include <stdio.h> #include <iostream> #include <string> #include <string.h> #include <math.h> #define SZ 100005 #define ll long long using namespace std; int num[SZ]; int neg[SZ]; int zero[SZ]; int maxInd; void update(int *arr,int ind,int val) { while(ind<maxInd) { arr[ind]+=val; ind+=(ind & (-ind)); } } int read(int *arr,int ind) { int res =0; while(ind>0)