Hello, I tried chef liikes and good sequences and I don’t know why it is giving TLE,
is it due to so many if condition?
import java.util.*;
import java.lang.*;
class Test{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
int t = in.nextInt();
for(int tc =0 ;tc<t;tc++){
int n = in.nextInt();
int q = in.nextInt();
int[] ar = new int[n];
for(int i=0 ;i<n;i++)
ar[i] = in.nextInt();
int count = 1;
for(int j=1 ;j<n;j++){
if(ar[j-1]!=ar[j])
count++ ;
}
for(int i=0;i<q;i++){
int x = in.nextInt()-1;
int y = in.nextInt();
int curr = 0;
int prev =0 ;
int tmp = ar[x] ;
ar[x] = y ;
if((x-1)>=0){
if(ar[x-1]!=y)curr++;
if(ar[x-1]!=tmp)prev++;
}
if((x+1)<n){
if(ar[x+1]!=y)curr++;
if(ar[x+1]!=tmp)prev++;
}
if(curr == prev)
System.out.println(count);
else{
System.out.println(count+curr-prev);
count = count + curr - prev ;
}
}
}
}
}