# NZEC in Funny Marble

I was solving the funny marble problem of december/13 long contest problem. I have implemented segment tree , but getting NZEC error in code. Plz help !

import java.io.*;

class funny{

``````public static void main(String[] args) throws IOException{
String str[]=s.split(" ");
int n=Integer.parseInt(str[0]);
int k=Integer.parseInt(str[1]);
int size = 2 * (int)Math.pow(2.0, Math.ceil(Math.log(n * 1.0) / Math.log(2.0)) * 1.0) - 1;
str=s.split(" ");
long arr[]=new long[n+1];
long tree[]=new long[size];
for(int i=0;i<n;i++){
arr[i]=Long.parseLong(str[i]);
}
createsegment(tree,arr,0,n-1,0);

for(int i=0;i<k;i++){
str=s.split(" ");
String type=(str[0]);
if(type.equals("S")){

int l=Integer.parseInt(str[1]);
int r=Integer.parseInt(str[2]);
System.out.println(findsum(arr,0,n-1,l,r,0));
}else if(type.equals("G")){
int ind=Integer.parseInt(str[1]);
int val=Integer.parseInt(str[2]);

update(tree,0,n-1,ind,val,0);

}else{
int ind=Integer.parseInt(str[1]);
int val=Integer.parseInt(str[2]);
update1(tree,0,n-1,ind,val,0);
}
}
}

public static void update(long tree[],int l,int r,int i,int val,int index){

if(l>i || r<i){
return ;
}
tree[index]+=val;
if(l!=r){
int mid=(l+r)/2;
update(tree,l,mid,i,val,2*index+1);update(tree,mid+1,r,i,val,2*index+2);

}
}

public static void update1(long tree[],int l,int r,int i,int val,int index){
if(l>i || r<i){
return;
}
tree[index]-=val;
if(l!=r){
int mid=(l+r)/2;
update(tree,l,mid,i,val,2*index+1);
update(tree,mid+1,r,i,val,2*index+2);
}
}
public static long findsum(long tree[],int l,int r, int ql,int qr,int index){
if(l>=ql && r<=qr){
return tree[index];
}
if(r<ql || l>qr){
return 0;
}
int mid=(r+l)/2;
return findsum(tree,l,mid,ql,qr,2*index+1)+findsum(tree,mid+1,r,ql,qr,2*index+2);
}

public static long createsegment(long tree[],long arr[],int l,int r,int index){
if(l==r){
tree[index]=arr[l];
return arr[l];
}

int mid=(r+l)/2;
tree[index]= createsegment(tree,arr,l,mid,2*index+1)+createsegment(tree,arr,mid+1,r,2*index+2);
return tree[index];
}
``````

}