fork download
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<iostream>
  4. using namespace std;
  5. int main()
  6. {
  7. long long int n,q,l,r,i;
  8. scanf("%lld %lld %lld %lld",&n,&q,&l,&r);
  9. long long int arr[n+1];
  10. for(i=0;i<=n;i++)
  11. arr[i]=0;
  12. for(i=0;i<q;i++)
  13. {
  14. long long int a,x,y,j,k;
  15. unsigned long long int counter=0,counte=0,count1=0,countf=0;
  16. scanf("%lld %lld %lld",&a,&x,&y);
  17. if(a==1)
  18. {
  19. arr[x]=y;
  20. // printf("hello\n");
  21. }
  22. else
  23. {
  24.  
  25. //printf("%lld %lld xy\n",x,y);
  26. //here for the range of (x,y) index value which are less than r is set as 1 else 0
  27. // continuous 1's will satisfy for R
  28. long long int cc=y-x+2,vv=1;
  29. int brr[cc];
  30. for(j=x;j<=y;j++)
  31. {
  32. if(arr[j]<=r)
  33. brr[vv]=1;
  34. else
  35. brr[vv]=0;
  36.  
  37. vv++;
  38. }
  39. //for(j=1;j<cc;j++)
  40. //printf("%d ",brr[j]);
  41. //printf("\n");
  42. for(j=1;j<cc;j++)
  43. {
  44. if(brr[j]==1)
  45. {
  46. while(brr[j]==1&&j<cc)
  47. {
  48. count1++;
  49. j++;
  50. }
  51. j--;
  52. counte=counte+(count1*(count1+1))/2;
  53. }
  54. else
  55. count1=0;
  56.  
  57. }
  58. //here for the range of (x,y) index value which are less than l is set as 1 else 0
  59. // continuous 1's will satisfy for L
  60. count1=0;
  61. vv=1;
  62. for(j=x;j<=y;j++)
  63. {
  64. if(arr[j]<l)
  65. brr[vv]=1;
  66. else
  67. brr[vv]=0;
  68.  
  69. vv++;
  70. }
  71. //for(j=1;j<cc;j++)
  72. // printf("%d ",brr[j]);
  73. //printf("\n");
  74. for(j=1;j<cc;j++)
  75. {
  76. if(brr[j]==1)
  77. {
  78. while(brr[j]==1&&j<cc)
  79. {
  80. count1++;
  81. j++;
  82. }
  83. j--;
  84. countf=countf+(count1*(count1+1))/2;
  85. }
  86. else
  87. count1=0;
  88.  
  89. }
  90. // cout<<counte;
  91. //cout<<(" ");
  92. // cout<<countf;
  93. //cout<<(" ");
  94.  
  95. // difference of r and l is my output.
  96. counter=counte-countf;
  97. cout<<(counter);
  98. cout<<("\n");
  99.  
  100.  
  101. }
  102. }
  103.  
  104. }
  105.  
Runtime error #stdin #stdout 0s 4472KB
stdin
Standard input is empty
stdout
Standard output is empty