結果

問題 No.3016 unordered_mapなるたけ落とすマン
ユーザー tatt61880tatt61880
提出日時 2021-03-28 18:54:53
言語 Kuin
(KuinC++ v.2021.9.17)
結果
AC  
実行時間 334 ms / 1,000 ms
コード長 5,544 bytes
コンパイル時間 3,563 ms
コンパイル使用メモリ 150,236 KB
実行使用メモリ 22,916 KB
最終ジャッジ日時 2024-09-16 12:17:00
合計ジャッジ時間 19,278 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 258 ms
20,628 KB
testcase_04 AC 300 ms
21,404 KB
testcase_05 AC 294 ms
21,224 KB
testcase_06 AC 296 ms
21,216 KB
testcase_07 AC 310 ms
21,072 KB
testcase_08 AC 328 ms
20,928 KB
testcase_09 AC 292 ms
21,036 KB
testcase_10 AC 298 ms
21,008 KB
testcase_11 AC 306 ms
20,704 KB
testcase_12 AC 288 ms
20,592 KB
testcase_13 AC 294 ms
20,656 KB
testcase_14 AC 312 ms
20,624 KB
testcase_15 AC 305 ms
20,444 KB
testcase_16 AC 299 ms
20,524 KB
testcase_17 AC 302 ms
20,320 KB
testcase_18 AC 264 ms
20,308 KB
testcase_19 AC 323 ms
20,184 KB
testcase_20 AC 313 ms
20,068 KB
testcase_21 AC 306 ms
20,176 KB
testcase_22 AC 275 ms
20,136 KB
testcase_23 AC 280 ms
20,208 KB
testcase_24 AC 290 ms
20,140 KB
testcase_25 AC 300 ms
20,044 KB
testcase_26 AC 274 ms
19,908 KB
testcase_27 AC 284 ms
19,892 KB
testcase_28 AC 334 ms
19,856 KB
testcase_29 AC 280 ms
19,824 KB
testcase_30 AC 269 ms
19,652 KB
testcase_31 AC 249 ms
19,600 KB
testcase_32 AC 287 ms
19,516 KB
testcase_33 AC 260 ms
19,412 KB
testcase_34 AC 280 ms
19,416 KB
testcase_35 AC 255 ms
19,300 KB
testcase_36 AC 280 ms
19,396 KB
testcase_37 AC 226 ms
19,244 KB
testcase_38 AC 288 ms
19,340 KB
testcase_39 AC 265 ms
19,296 KB
testcase_40 AC 243 ms
18,988 KB
testcase_41 AC 1 ms
5,376 KB
testcase_42 AC 2 ms
5,376 KB
testcase_43 AC 2 ms
5,376 KB
testcase_44 AC 15 ms
5,376 KB
testcase_45 AC 15 ms
5,376 KB
testcase_46 AC 15 ms
5,376 KB
testcase_47 AC 150 ms
15,696 KB
testcase_48 AC 171 ms
17,400 KB
testcase_49 AC 169 ms
19,016 KB
testcase_50 AC 111 ms
22,916 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

func main()
	var ss: [][]char :: cui@input().split(" ")
	var n: int :: ss[0].toInt(&)
	var m: int :: ss[1].toInt(&)
	var map: @Map :: #@Map
	
	var s: []char
	var j: int
	
	do s :: cui@input() ~ " " ~ cui@input() ~ " "
	do j :: 0
	for i(0, n - 1)
		var val: int :: 0
		while(s[j] <> ' ')
			do val :: val * 10 + s[j] $ int - 48
			do j :+ 1
		end while
		do j :+ 1
		do map.add(val, map.get(val) + 1)
	end for
	
	for i(0, m - 1)
		var val: int :: 0
		while(s[j] <> ' ')
			do val :: val * 10 + s[j] $ int - 48
			do j :+ 1
		end while
		do j :+ 1
		do cui@print("\{map.get(val)} ")
	end for
end func

class Node()
	+var height: int
	+var key: int
	+var value: int
	+var prev: Node
	+var next: Node
	+var lst: Node
	+var rst: Node
	+*func toStr(): []char
		ret me.value.toStr()
	end func
	+func init(key: int, value: int, prev: Node, next: Node): Node
		do me.height :: 1
		do me.key :: key
		do me.value :: value
		do me.prev :: prev
		do me.next :: next
		ret me
	end func
end class

; AVL Tree
class Map()
	var root: @Node
	var change: bool
	var lMax: int
	var lMaxValue: int
	var num: int
	+*func toStr(): []char
		ret me.toGraph(me.root, "", "")
	end func
	func toGraph(t: @Node, head: []char, bar: []char): []char
		var res: []char :: ""
		if(t <>& null)
			do res :~ me.toGraph(t.rst, head ~ "  ", "/")
			do res :~ head ~ bar ~ t.key.toStr() ~ "\n"
			do res :~ me.toGraph(t.lst, head ~ "  ", "`")
		end if
		ret res
	end func
	+func size(): int
		ret me.num
	end func
	+func begin(): @Node
		var t: @Node :: me.root
		if(t =& null)
			ret null
		end if
		while(true)
			if(t.lst =& null)
				ret t
			end if
			do t :: t.lst
		end while
	end func
	+func add(key: int, value: int)
		do me.root :: me.addSub(me.root, null, key, value)
	end func
	func addSub(t: @Node, parent: @Node, key: int, value: int): @Node
		if(t =& null)
			var a: @Node
			do me.change :: true
			if(parent =& null)
				do a :: (#@Node).init(key, value, null, null)
			elif(key < parent.key)
				do a :: (#@Node).init(key, value, 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, value, 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, value)
			ret me.balanceL(t)
		elif(key > t.key)
			do t.rst :: me.addSub(t.rst, t, key, value)
			ret me.balanceR(t)
		else
			do me.change :: false
			do t.value :: value
			ret t
		end if
	end func
	+func del(key: int)
		do me.root :: me.delSub(me.root, key)
	end func
	func delSub(t: @Node, key: int): @Node
		if(t =& null)
			do me.change :: false
			ret null
		elif(key < t.key)
			do t.lst :: me.delSub(t.lst, key)
			ret me.balanceR(t)
		elif(key > t.key)
			do t.rst :: me.delSub(t.rst, key)
			ret me.balanceL(t)
		else
			do me.num :- 1
			if(t.next <>& null)
				do t.next.prev :: t.prev
			end if
			if(t.prev <>& null)
				do t.prev.next :: t.next
			end if
			if(t.lst =& null)
				do me.change :: true
				ret t.rst
			else
				do t.lst :: me.delSubMax(t.lst)
				do t.key :: me.lMax
				do t.value :: me.lMaxValue
				ret me.balanceR(t)
			end if
		end if
	end func
	func delSubMax(t: @Node): @Node
		if(t.rst <>& null)
			do t.rst :: me.delSubMax(t.rst)
			ret me.balanceL(t)
		else
			do me.change :: true
			do me.lMax :: t.key
			do me.lMaxValue :: t.value
			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 get(key: int): int
		var t: @Node :: me.find(key)
		ret t =& null ?(0, t.value)
	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
				do t :: t.lst
			elif(key > t.key)
				if(t.rst =& null)
					ret t.next
				end if
				do t :: t.rst
			else
				ret t
			end if
		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
end class
0