fork download
  1. #include<iostream>
  2. using namespace std;
  3. long long int a[10000000];
  4. long long int segtree[450000];
  5. long long int lazy[450000];
  6. void updatetree(int low,int high,int value,int qlow,int qhigh,int pos);
  7. int main()
  8. {
  9. std::ios::sync_with_stdio(false);// std::ios in codeblock
  10. int t,b;
  11. long long int n,c,p,q,v,i;
  12. cin>>t;
  13. while(t--)
  14. {
  15. // memset(lazy,0,sizeof(lazy));
  16. cin>>n>>c;
  17. for(i=0;i<450000;i++)
  18. {
  19. lazy[i]=0;
  20. segtree[i]=0;
  21. }
  22. for(i=0;i<n;i++)
  23. a[i]=0;
  24.  
  25. for(i=0;i<c;i++)
  26. {
  27. cin>>b;
  28. if(b==0)
  29. {
  30. cin>>p>>q>>v;
  31. updatetree(0,n-1,v,p,q,0);// constant value should be from right side
  32. }
  33. /* else
  34.   {
  35.   cin>>p>>q;
  36.   addtree(p,q);
  37.   }*/
  38. }
  39. }
  40. return 0;
  41. }
  42.  
  43. void updatetree(int low,int high,int value,int qlow,int qhigh,int pos)
  44. {
  45. if(lazy[pos]!=0)
  46. {
  47. segtree[pos]+=lazy[pos];
  48. if(low!=high)
  49. {
  50.  
  51. lazy[2*pos+1]+=lazy[pos];
  52. lazy[2*pos+2]+=lazy[pos];
  53. }
  54. lazy[pos]=0;
  55. }
  56. if(low>qhigh||high<qlow) return;// later addition
  57. if(qlow<=low&&qhigh>=high)
  58. {
  59. segtree[pos]+=value;
  60. if(low!=high)
  61. {
  62. lazy[2*pos+1]+=value;
  63. lazy[2*pos+2]+=value;
  64. }
  65. return ;
  66. }
  67. //if partial overlaps
  68. int mid;
  69. mid=(low+high)/2;
  70. updatetree(low,mid,value,qlow,qhigh,2*pos+1);
  71. updatetree(mid+1,high,value,qlow,qhigh,2+pos+2);
  72. segtree[pos]=min(segtree[2*pos+1],segtree[2*pos+2]);
  73. }
  74.  
Success #stdin #stdout 0s 88640KB
stdin
1
8 6
0 2 4 26
0 4 8 80
0 4 5 20
stdout
Standard output is empty