結果

問題 No.1439 Let's Compare!!!!
ユーザー tatt61880tatt61880
提出日時 2021-03-27 19:58:36
言語 Kuin
(KuinC++ v.2021.9.17)
結果
RE  
実行時間 -
コード長 5,273 bytes
コンパイル時間 2,934 ms
コンパイル使用メモリ 149,024 KB
実行使用メモリ 27,224 KB
最終ジャッジ日時 2024-09-16 12:10:59
合計ジャッジ時間 7,690 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 RE -
testcase_02 AC 2 ms
5,376 KB
testcase_03 RE -
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
out.cpp:2116:1: warning: non-void function does not return a value in all control paths [-Wreturn-type]
}
^
1 warning generated.

ソースコード

diff #

func main()
	var n: int :: cui@inputInt()
	var s: []char :: cui@input()
	var t: []char :: cui@input()
	
	var set: Set :: #Set
	for i(0, n - 1)
		if(s[i] <> t[i])
			do set.add(i)
		end if
	end for
	
	var q: int :: cui@inputInt()
	for(1, q)
		var c: char :: cui@inputChar()
		var x: int :: cui@inputInt() - 1
		var y: int :: cui@inputInt()
		if(c = 'S')
			do s[x] :: '0'.offset(y)
		else
			do t[x] :: '0'.offset(y)
		end if
		if(s[x] = t[x])
			do set.del(x)
		else
			do set.add(x)
		end if
		var begin: Node :: set.begin()
		
		if(begin =& null)
			do cui@print("=")
		else
			var i: int :: begin.key
			if(s[i] < t[i])
				do cui@print("<")
			else
				do cui@print(">")
			end if
		end if
		do cui@print("\n")
	end for
	
	class Node()
		+var height: int
		+var key: int
		+var prev: Node
		+var next: Node
		+var lst: Node
		+var rst: Node
		+func init(key: int, prev: Node, next: Node): Node
			do me.height :: 1
			do me.key :: key
			do me.prev :: prev
			do me.next :: next
			ret me
		end func
	end class
	
	; AVL Tree
	class Set()
		var root: Node
		var change: bool
		var lMax: int
		var num: int
		+func size(): int
			ret me.num
		end func
		+func begin(): Node
			var t: Node :: me.root
			while(true)
				if(t.lst =& null)
					ret t
				end if
				do t :: t.lst
			end while
		end func
		func height(t: Node): int
			ret t =& null ?(0, t.height)
		end func
		func bias(t: Node): int
			ret me.height(t.lst) - me.height(t.rst)
		end func
		func modHeight(t: Node)
			do t.height :: 1 + lib@max(me.height(t.lst), me.height(t.rst))
		end func
		func rotateL(v: Node): Node
			var u: Node :: v.rst
			var t: Node :: u.lst
			do u.lst :: v
			do v.rst :: t
			ret u
		end func
		func rotateR(u: Node): Node
			var v: Node :: u.lst
			var t: Node :: v.rst
			do v.rst :: u
			do u.lst :: t
			ret v
		end func
		func rotateLR(t: Node): Node
			do t.lst :: me.rotateL(t.lst)
			ret me.rotateR(t)
		end func
		func rotateRL(t: Node): Node
			do t.rst :: me.rotateR(t.rst)
			ret me.rotateL(t)
		end func
		func balanceL(t: Node): Node
			if(!me.change)
				ret t
			end if
			var h: int :: me.height(t)
			if(me.bias(t) = 2)
				if(me.bias(t.lst) >= 0)
					do t :: me.rotateR(t)
				else
					do t :: me.rotateLR(t)
				end if
			else
				do me.modHeight(t)
			end if
			do me.change :: (h <> me.height(t))
			ret t
		end func
		+func balanceR(t: Node): Node
			if(!me.change)
				ret t
			end if
			var h: int :: me.height(t)
			if(me.bias(t) = -2)
				if(me.bias(t.rst) <= 0)
					do t :: me.rotateL(t)
				else
					do t :: me.rotateRL(t)
				end if
			else
				do me.modHeight(t)
			end if
			do me.change :: (h <> me.height(t))
			ret t
		end func
		+func add(key: int)
			do me.root :: me.addSub(me.root, null, key)
		end func
		func addSub(t: Node, parent: Node, key: int): Node
			if(t =& null)
				var a: Node
				do me.change :: true
				if(parent =& null)
					do a :: (#Node).init(key, null, null)
				elif(key < parent.key)
					do a :: (#Node).init(key, parent.prev, parent)
					if(parent.prev <>& null)
						do parent.prev.next :: a
					end if
					do parent.prev :: a
				elif(key > parent.key)
					do a :: (#Node).init(key, parent, parent.next)
					if(parent.next <>& null)
						do parent.next.prev :: a
					end if
					do parent.next :: a
				end if
				do me.num :+ 1
				ret a
			elif(key < t.key)
				do t.lst :: me.addSub(t.lst, t, key)
				ret me.balanceL(t)
			elif(key > t.key)
				do t.rst :: me.addSub(t.rst, t, key)
				ret me.balanceR(t)
			else
				do me.change :: false
				ret t
			end if
		end func
		+func del(key: int)
			do me.root :: me.delSub(me.root, null, key)
		end func
		func delSub(t: Node, parent: Node, key: int): Node
			if(t =& null)
				var a: Node
				do me.change :: true
				ret null
			elif(key < t.key)
				do t.lst :: me.delSub(t.lst, t, key)
				ret me.balanceR(t)
			elif(key > t.key)
				do t.rst :: me.delSub(t.rst, t, key)
				ret me.balanceL(t)
			else
				do me.num :- 1
				if(t.lst =& null)
					do me.change :: true
					if(t.rst <>& null)
						do t.rst.prev :: null
					end if
					ret t.rst
				else
					if(t.prev <>& null)
						do t.prev.next :: t.next
					end if
					if(t.next <>& null)
						do t.next.prev :: t.prev
					end if
					do t.lst :: me.delMax(t.lst)
					do t.key :: me.lMax
					ret me.balanceR(t)
				end if
			end if
		end func
		func delMax(t: Node): Node
			if(t.rst <>& null)
				do t.rst :: me.delMax(t.rst)
				do me.balanceL(t)
			else
				do me.change :: true
				do me.lMax :: t.key
				ret t.lst
			end if
		end func
		+func find(key: int): Node
			var t: Node :: me.root
			while loop(t <>& null)
				if(key < t.key)
					do t :: t.lst
				elif(key > t.key)
					do t :: t.rst
				else
					break loop
				end if
			end while
			ret t
		end func
		+func exist(key: int): bool
			ret me.find(key) <>& null
		end func
		+func lower_bound(key: int): Node
			var t: Node :: me.root
			if(t =& null)
				ret null
			end if
			while(true)
				if(key < t.key)
					if(t.lst =& null)
						ret t
					end if
					if(key > t.lst.key & t.lst.rst =& null)
						ret t
					end if
					do t :: t.lst
				elif(key > t.key)
					if(t.rst =& null)
						ret null
					end if
					do t :: t.rst
				else
					ret t
				end if
			end while
		end func
	end class
end func
0