title: Segment Tree Approach in solving
body: <p>I have given an Array having N element and <strong>Having Three Type of Queries</strong>
  <br><strong>Query 1:</strong>
  Add a value C to all the element in Range [L,R] i.e <code>A[i]+=c where L&lt;=i&lt;=R</code>
  <br><strong>Query 2</strong> Assign a Value C to all the element in Range [L,R] i.e <code>A[i] =c where L&lt;=i&lt;=R</code><br>
  <strong>Query 3</strong> Getting the Sum of all the element from L to R
  <br><Br> I have solve it <strong>Using Segment Tree with Lazy propagation</strong> <br><br>
  <strong>My Approach:</strong> <br><Br>
  Maintaing an Level[2][n] array where <code>Level[0][n] store the values to be incremented and Level[1][n] new value that we have to assign</code><br><br></p>
  
  <p>Here is my change function:</p>
  
  <pre><code>public static void change(int curr , int x , int y , int a , int b, long c , long[] T , int add){
  
  
             if(level[0][curr]!=-1 || level[1][curr]!=-1){
  
                 if(level[1][curr]!=-1) T[curr] =  (((long)(y-x+1))*level[1][curr])%mod;
  
                 if(level[0][curr]!=-1)
                     T[curr]+= (((long)(y-x+1))*level[0][curr])%mod;
                 T[curr]%=mod;
  
                   if(x!=y){
  
                       if(level[0][curr]!=-1){
  
                           if(level[0][2*curr]==-1) level[0][2*curr]= level[0][curr];
                           else level[0][2*curr] += level[0][curr];
  
                           if(level[0][2*curr+1]==-1) level[0][2*curr+1]= level[0][curr];
                           else level[0][2*curr+1] += level[0][curr];
                       }
  
  
  
                       if(level[1][curr]!=-1){
  
                             level[1][2*curr]=level[1][curr];
                             level[1][2*curr+1]=level[1][curr];
                       }
  
                       level[0][2*curr]%=mod;
                       level[0][2*curr+1]%=mod;
  
                   }
                   level[0][curr]=level[1][curr]=-1;
             }
  
             if(x&gt;y || y&lt;a || x&gt;b) return;
  
             if(a&lt;=x &amp;&amp; b&gt;=y){
  
                 if(add==1) T[curr]+= (((long)(y-x+1))*c)%mod;
                 else T[curr] = (((long)(y-x+1))*c)%mod;
                 T[curr]%=mod;
  
                 if(x!=y){
  
                     if(add==1)
                     {
                          if(level[0][2*curr]==-1) level[0][2*curr]= c;
                           else level[0][2*curr] +=c;
  
                           if(level[0][2*curr+1]==-1) level[0][2*curr+1]=c;
                           else level[0][2*curr+1] += c;
  
                           level[0][2*curr]%=mod;
                           level[0][2*curr+1]%=mod;
                     }else{
                         level[1][2*curr]=c;
                         level[1][2*curr+1]=c;  
                         level[0][2*curr]=-1;
                         level[0][2*curr+1]=-1;
                     }
  
                 }
  
                 return;
             }
             change(2*curr, x, (x+y)/2, a, b, c, T, add);
             change(2*curr+1, (x+y)/2+1, y, a, b, c, T, add);
  
             T[curr] = T[2*curr]+T[2*curr+1];
             T[curr]%=mod;
  
      }
  </code></pre>
  
  <p>I am not getting the Correct Answer and could not figure out where i have done wrong i have tried multiple test data and getting the right answer but getting wrong answer with large data set<br><br>Please Help me very i have done wrong<br><a href="http://ideone.com/9drONK" rel="nofollow">Full Working Code</a></p>
  
  <pre><code> 1 ≤ N ≤ 10^5
      1 ≤ Q ≤ 10^5
      1&lt;=L&lt;=R&lt;=10^5
      1&lt;=Value&lt;=10^9
      Mod = 10^9+7
  </code></pre>