FENWIC TREE -Funny Marbles -EASY-What is wrong?

MY CODE IS PASSING ALL SAMPLE TEST CASES ,I THINK THERE IS SOME MINUTE MISTAKE…
PROBLEM LINK >>https://www.codechef.com/problems/MARBLEGF

#include <iostream>
using namespace std;
#include<bits/stdc++.h>


typedef long long ll;
typedef unsigned long long ull;


ull input[1000001];
ull query[5000001];
ull bit[1000001]={0};


void update(ull n, ull idx,ull num) 
{ 
    while (idx <= n) 
    { 
        bit[idx]+=num; 
        idx += idx & (-idx); 
    } 
}


int Qry( ull idx) 
{ 
    ull ans = 0; 
    while (idx) { 
        ans += bit[idx]; 
  
        idx -= idx & (-idx); 
    } 
    return ans; 
} 




int main()
{
             
ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ull n,q,left,right,num,idx;
    char c;
    
    cin>>n>>q;
    for(int i=1;i<=n;i++)
    {
                 
      cin>>input[i];
      update(n,i,input[i]);
    }
    
    while(q--)
    {
                 
       cin>> c;
       
       if(c=='S')
       {
                    cin>>left>>right;
                    
                    left++;
                    right++;
                    if(left==1)
                    {
                              cout<< Qry(right)<<endl;      
                    }
             else
             cout<< Qry(right)-Qry(left-1)<<endl;      
       }
       
       else
       if(c=='G')
       {
                cin>> idx>>num;
                
                update(n,idx+1,num);
                
                    
       }
       else
       if(c=='T')
       {             cin>> idx>>num;
                    update(n,idx+1,-num);
                    
       }
       
       
                 
     }
    
    
    
 }

there might be some issue with indexing. I tried your code with some modification but got a WA. Though you can check out my solution here: https://www.codechef.com/viewsolution/35420812

1 Like