[Python] BIT + SortedList
```python3 []
class BIT:
    def __init__(self,N):
        self.length=N+1
        self.stree = [0]*(N+1)
    
    def increase(self,i,x):
        while i<self.length:
            self.stree[i]+=x
            i |= (i+1)
    
    def total(self, i):
        s = 0

        while i>=0:
            s+=self.stree[i]
            i &= i+1
            i-=1
        return s


class Solution:
    def numberOfAlternatingGroups(self, colors: List[int], queries: List[List[int]]) -> List[int]:
        splits=SortedList([i for i in range(len(colors)) if colors[i]==colors[i-1]])
        groups = SortedList([b-a for a, b in zip([n-len(colors) for n in splits[-1:]]+splits[:-1],splits)] if splits else [len(colors)])
        bit = BIT(len(colors))
        res=[]
        for g in groups:
            bit.increase(g,g)
        
        for q in queries:
            if q[0]==2:
                _, idx, col = q
                if colors[idx]==col:
                    continue
                lo=hi=a=b=g=None
                if splits:
                    
                    lo = (splits.bisect_left(idx)-1)%len(splits)
                    hi = splits.bisect_right(idx)%len(splits)
                    g=((splits[hi]-splits[lo])%len(colors) if lo!= hi else len(colors))
                    a=((idx-splits[lo])%len(colors) if splits[lo]!=idx else len(colors))
                    b=((splits[hi]-idx)%len(colors) if splits[hi]!=idx else len(colors))
                colors[idx]=col
                if colors[idx]==colors[idx-1] and idx not in splits:
                    if splits:
                        bit.increase(g,-g)
                        bit.increase(a,a)
                        bit.increase(b,b)
                        groups.remove(g)
                        groups.add(a)
                        groups.add(b)
                    splits.add(idx)
                if colors[idx]!=colors[idx-1] and idx in splits:
                    if splits:
                        bit.increase(g,g)
                        bit.increase(a,-a)
                        bit.increase(b,-b)
                        groups.add(g)
                        groups.remove(a)
                        groups.remove(b)
                    splits.remove(idx)
                if not groups:
                    groups.add(len(colors))
                lo=hi=a=b=g=None
                if splits:
                    lo = (splits.bisect_left((idx+1)%len(colors))-1)%len(splits)
                    hi = splits.bisect_right((idx+1)%len(colors))%len(splits)
                    g=((splits[hi]-splits[lo])%len(colors) if lo!= hi else len(colors))
                    a=(((idx+1)%len(colors)-splits[lo])%len(colors) if splits[lo]!=((idx+1)%len(colors)) else len(colors))
                    b=((splits[hi]-((idx+1)%len(colors)))%len(colors) if splits[hi]!=((idx+1)%len(colors)) else len(colors))
                if colors[idx]==colors[(idx+1)%len(colors)] and (idx+1)%len(colors) not in splits:
                    if splits:
                        bit.increase(g,-g)
                        bit.increase(a,a)
                        bit.increase(b,b)
                        groups.remove(g)
                        groups.add(a)
                        groups.add(b)
                    splits.add((idx+1)%len(colors))

                if colors[idx]!=colors[(idx+1)%len(colors)] and (idx+1)%len(colors) in splits:
                    if splits:
                        bit.increase(g,g)
                        bit.increase(a,-a)
                        bit.increase(b,-b)
                        groups.add(g)
                        groups.remove(a)
                        groups.remove(b)
                    splits.remove((idx+1)%len(colors))
                if not groups:
                    groups.add(len(colors))
            else:
                _, val = q
                cnt = len(groups)-groups.bisect_left(val)
                res.append(((bit.total(len(colors))-bit.total(val-1)-(val-1)*cnt)%len(colors) if splits else len(colors)))
        return res


```
['Python3']