fork download
  1. #include <bits/stdc++.h>
  2. #define int long long
  3. using namespace std;
  4. int n,m,mxa=0,a[300005],d[1000006],bit[300005];
  5. multiset <int> mse;
  6. void UPDATE(int i, int v)
  7. {
  8. while (i<=n) bit[i]+=v,i+=i&(-i);
  9. return;
  10. }
  11. int GET(int l, int r)
  12. {
  13. l--;
  14. int resl=0,resr=0;
  15. while (l>0) resl+=bit[l],l-=l&(-l);
  16. while (r>0) resr+=bit[r],r-=r&(-r);
  17. return resr-resl;
  18. }
  19. signed main()
  20. {
  21. ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
  22. cin>>n>>m;
  23. for (int i=1;i<=n;i++) cin>>a[i],mxa=max(mxa,a[i]),UPDATE(i,a[i]);
  24. for (int i=1;i<=mxa;i++) for (int j=i;j<=mxa;j+=i) d[j]++;
  25. for (int i=1;i<=n;i++)
  26. {
  27. int cnt=0,vl=a[i];
  28. while (vl>2) cnt++,vl=d[vl];
  29. for (int j=1;j<=cnt;j++) mse.insert(i);
  30. }
  31. for (int i=1;i<=m;i++)
  32. {
  33. int t,l,r;
  34. cin>>t>>l>>r;
  35. if (t==1)
  36. {
  37. int idx=l;
  38. while (*mse.lower_bound(idx)>=l && *mse.lower_bound(idx)<=r)
  39. {
  40. idx=*mse.lower_bound(idx);
  41. UPDATE(idx,d[a[idx]]-a[idx]),a[idx]=d[a[idx]];
  42. if (mse.find(idx)!=mse.end()) mse.erase(mse.find(idx));
  43. if (mse.upper_bound(idx)==mse.end()) break;
  44. else idx=*mse.upper_bound(idx);
  45. }
  46. }
  47. else cout<<GET(l,r)<<'\n';
  48. }
  49. return 0;
  50. }
  51.  
Success #stdin #stdout 0.01s 5304KB
stdin
Standard input is empty
stdout
Standard output is empty