結果

問題 No.2080 Simple Nim Query
ユーザー 👑 p-adicp-adic
提出日時 2024-09-07 09:41:04
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 4,304 bytes
コンパイル時間 379 ms
コンパイル使用メモリ 82,772 KB
実行使用メモリ 107,620 KB
最終ジャッジ日時 2024-09-07 09:41:23
合計ジャッジ時間 15,860 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
54,304 KB
testcase_01 AC 37 ms
54,556 KB
testcase_02 AC 35 ms
54,596 KB
testcase_03 AC 1,030 ms
81,828 KB
testcase_04 AC 783 ms
78,904 KB
testcase_05 AC 902 ms
103,536 KB
testcase_06 AC 2,802 ms
106,700 KB
testcase_07 AC 2,735 ms
107,192 KB
testcase_08 AC 1,367 ms
107,620 KB
testcase_09 AC 1,393 ms
107,480 KB
testcase_10 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

def rec_str(a):return"".join(["[",", ".join(rec_str(x)for x in a),"]"])if isinstance(a,list)else str(a)
class BIT:
	def __init__(self,x):
		if isinstance(x,int):
			self.N=x
			self.F=[0]*(x+1)
		else:
			self.N=len(x)
			self.F=[0]*(self.N+1)
			for j in R(1,self.N+1):
				i=j-1
				self.F[j]=x[i]
				k=j-(j&-j)
				while i>k:
					self.F[j]+=self.F[i]
					i-=i&-i
	def Add(self,i,u):
		i+=1
		while i<=self.N:
			self.F[i]+=u
			i+=i&-i
	def InitialSegmentSum(self,r):
		assert(r>-2)
		a=0
		i=min(r+1,self.N)
		while i:
			a+=self.F[i]
			i-=i&-i
		return a
class IntervalAddBIT:
	def __init__(self,N):
		self.N=N
		self.F=BIT(N+1)
		self.G=BIT(N+1)
	def IntervalAdd(self,l,r,u):
		self.F.Add(l,-(l-1)*u)
		self.F.Add(r+1,r*u)
		self.G.Add(l,u)
		self.G.Add(r+1,-u)
	def Add(self,i,u):self.IntervalAdd(i,i,u)
	def Set(self,i,u):self.Add(i,u-self.Get(i))
	def InitialSegmentSum(self,r):return self.F.InitialSegmentSum(r)+r*self.G.InitialSegmentSum(r)
	def IntervalSum(self,l,r):return self.InitialSegmentSum(r)-self.InitialSegmentSum(l-1)
	def Get(self,i):return self.IntervalSum(i,i)
	def list(self):return[self.Get(i)for i in R(self.N)]
	def __str__(self):return rec_str(self.list())

class NonNegativeLineMultiSubset:
	def __init__(self,ubound):
		assert(-1<=ubound)
		self.ubound=ubound
		self.bit=IntervalAddBIT(ubound+1)
	def copy(self):
		a=__class__([])
		a.ubound=self.ubound
		a.bit=self.bit.copy()
		return a
	def insert(self,i,c=1):assert(0<=i<=self.ubound);self.bit.Add(i,c)
	def IntervalInsert(self,i_start,i_final,c=1):assert(0<=i_start and i_final<=self.ubound);self.bit.IntervalAdd(i_start,i_final,c)
	def erase(self,i,c=1):self.bit.Add(i,-c)
	def EraseAll(self,i):self.bit.Set(i,0)
	def IntervalErase(self,i,c=1):self.bit.IntervalAdd(i_start,i_final,-c)
	def count(self,i):return self.bit.Get(i)if 0<=i<=self.ubound else 0
	def find(self,i):return self.count(i)>0
	def InitialSegmentCount(self,i_final):return self.bit.InitialSegmentSum(i_final)
	def IntervalCount(self,i_start,i_final):return self.bit.IntervalSum(i_start,i_final)

	#VVV Supported if multiplicities are non-negative
	def empty(self):return self.InitialSegmentCount(self.ubound)<1
	def MaximumLeq(self,i,k=0):#Returning lbound-1 if not exists
		num=self.InitialSegmentCount(i)-k
		i-=0
		def f(sum,j):return i<=j or num<=sum
		a=self.Search(f)
		return a if num>=0 and self.find(a)else 0-1
	def MaximumLt(self,i,k=0):return self.MaximumLeq(i-1,k)
	def MinimumGeq(self,i,k=0):return self.MinimumGt(i-1,k)
	def MinimumGt(self,i,k=0):#Returning ubound+1 if not exists
		num=self.InitialSegmentCount(i)+k
		i-=0
		def f(sum,j):return i<j and num<sum
		return self.Search(f)
	def Maximum(self,k=0):return self.MaximumLeq(self.ubound,k)
	def Minimum(self,k=0):return self.MinimumGeq(0,k)
	def RightEndPointOf(self,i,b=False):
		if not b and not self.find(i):return i-1
		c=i-self.InitialSegmentCount(i)
		def f(sum,j):return i<=j and sum+c<j
		return self.Search(f)-1
	def LeftEndPointOf(self,i,b=False):
		if not b and not self.find(i):return i+1
		c=i-self.InitialSegmentCount(i)
		def f(sum,j):return i<=j or(self.find(j)and sum+c==j)
		return self.Search(f)
	def ConnectedComponentOf(self,i,b=False):
		if not b:b=self.find(i)
		return[self.LeftEndPointOf(i,b),self.RightEndPointOf(i,b)]
	def GetConnectedComponent(self):
		a=[]
		l=self.Minimum()
		while l<=self.ubound:
			r=self.RightEndPointOf(l,True)
			a+=[[l,r]]
			l=self.MinimumGt(r)
		return a
	#AAA Supported if multiplicities are non-negative

	def __str__(self):
		s=[]
		for i in R(0,self.ubound+1):
			c=self.count(i)
			if c==1:s+=[str(i)]
			elif c>0:s+=[str(i)+'x'+str(c)]
			elif c<0:s+=[str(i)+"x("+str(c)+')']
		return '{{'+", ".join(s)+'}}'
	def lbound(self):return 0
	def ubound(self):return self.ubound

	#private:
	def Search(self,f):#Computing minimum of j satisfying f(bit.InitialSegmentSum(j),j) or j==bit.N
		l,r=-1,self.bit.N
		while l+1<r:
			m=(l+r)>>1
			if f(self.bit.InitialSegmentSum(m),m):r=m
			else:l=m
		return r

R=range
J=lambda:map(int,input().split())
N,Q=J()
A=list(J())
S=NonNegativeLineMultiSubset(N-1)
for i in R(N):
	if A[i]==1:S.insert(i)
for _ in R(Q):
	T,X,Y=J()
	if T==1:
		X-=1
		S.EraseAll(X)
		if Y==1:S.insert(X)
	else:
		X-=1;Y-=1
		l,r=S.ConnectedComponentOf(Y)
		print("SF"[r<Y or ((Y-max(X,l))&1)==(X<l)])
0