import times, strutils, sequtils, math, algorithm, tables, sets, lists, intsets import critbits, future, strformat, deques template `max=`(x,y) = x = max(x,y) template `min=`(x,y) = x = min(x,y) template `mod=`(x,y) = x = x mod y template scan2 = (scan(), scan()) template scan3 = (scan(), scan()) let read* = iterator: string {.closure.} = while true: (for s in stdin.readLine.split: yield s) proc scan(): int = read().parseInt proc scanf(): float = read().parseFloat proc toInt(c:char): int = return int(c) - int('0') proc solve()= var n = scan() m = scan() query = scan() s = newseqwith(n,read().parseBinInt) nodeNum = n*7 baseEs = newseqwith(n,newseq[int]()) es = newseqwith(nodeNum,newseq[int]()) roots = newseqwith(nodeNum,0) size = newseqwith(nodeNum,1) for i in 0.. 0) and ((colors and (1 shl right)) > 0): unite(idx*7+j,idx*7+(j+1).mod(7)) # 2. 隣接都市が同じ色を持っていたら辺を張る for town in 0..0 and (nxtC and (1 shl (6-j)))>0: unite(town*7+j,nxt*7+j) #echo roots for (q,x,y) in queries: if q == 1: # 1.自分自身の上下の色とのunite var p = (7-y-1) upper = ((7-(y-1)-1).mod(7)+7).mod(7) lower = ((7-(y+1)-1).mod(7)+7).mod(7) #echo s[x].toBin(7) #echo p, ", ", lower, ", ", upper s[x] += (1 shl p) if ((s[x] and (1 shl upper)) > 0) and ((s[x] and (1 shl p)) > 0): unite(x*7+y,x*7+((y-1).mod(7)+7).mod(7)) if ((s[x] and (1 shl lower)) > 0) and ((s[x] and (1 shl p)) > 0): unite(x*7+y,x*7+((y+1).mod(7)+7).mod(7)) # 2. 隣接する都市の同一の色とのunite for nxt in baseEs[x]: if (s[nxt] and (1 shl p)) > 0: unite(x*7+y,nxt*7+y) elif q == 2: #echo "x: ",x #echo roots echo size[find(x*7)] #echo roots #echo size solve()