fork(3) download
  1. #include<iostream>
  2. #include<string>
  3. #include<algorithm>
  4. #include<stdio.h>
  5. #include<stdlib.h>
  6. #include<iomanip>
  7. #include<math.h>
  8. using namespace std;
  9.  
  10. char g;
  11. long long n,m,i,l,r,x,t[1000000],t1[1000000];
  12.  
  13. void down(long long v,long long k){
  14. if(t1[v]!=-1){
  15. t[v*2]=t1[v]*(k-(k/2));t[v*2+1]=t1[v]*(k/2);
  16. t1[v*2]=t1[v];t1[v*2+1]=t1[v];
  17. t1[v]=-1;
  18. }
  19. }
  20. void modi(long long v,long long l,long long r,long long lt,long long rt,long long x){
  21. if((lt<=l)&&(rt>=r)&&(t1[v]!=-1)){
  22. t1[v]=x;
  23. t[v]=(r-l+1)*x;
  24. return;
  25. }
  26. down(v,r-l+1);
  27. long long mid=(l+r)/2;
  28. if(lt<=mid)modi(v*2,l,mid,lt,rt,x);
  29. if(rt>mid)modi(v*2+1,mid+1,r,lt,rt,x);
  30. if(t1[v*2]==t1[v*2+1])t1[v]=t1[v*2];else t1[v]=-1;
  31. t[v]=t[v*2]+t[v*2+1];
  32. }
  33. long long sum(long long v,long long l,long long r,long long lt,long long rt){
  34. if((lt<=l)&&(rt>=r))return t[v];
  35. down(v,r-l+1);
  36. long long mid=(l+r)/2;
  37. long long s=0;
  38. if(lt<=mid)s+=sum(v*2,l,mid,lt,rt);
  39. if(rt>mid)s+=sum(v*2+1,mid+1,r,lt,rt);
  40. return s;
  41. }
  42. int main(){
  43. freopen("sum.in","r",stdin);
  44. freopen("sum.out","w",stdout);
  45. cin>>n>>m;
  46. for(i=0;i<m;i++){
  47. cin>>g>>l>>r;
  48. if(g=='A'){
  49. cin>>x;
  50. modi(1,1,n,l,r,x);
  51. }else{
  52. cout<<sum(1,1,n,l,r)<<"\n";
  53. }
  54. }
  55. // system("PAUSE");
  56. }
Success #stdin #stdout 0s 18968KB
stdin
Standard input is empty
stdout
Standard output is empty