js-sdsl.js 88 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752
  1. (function(t, i) {
  2. typeof exports === "object" && typeof module !== "undefined" ? i(exports) : typeof define === "function" && define.amd ? define("sdsl", [ "exports" ], i) : (t = typeof globalThis !== "undefined" ? globalThis : t || self,
  3. i(t.sdsl = {}));
  4. })(this, (function(t) {
  5. "use strict";
  6. var extendStatics = function(t, i) {
  7. extendStatics = Object.setPrototypeOf || {
  8. __proto__: []
  9. } instanceof Array && function(t, i) {
  10. t.__proto__ = i;
  11. } || function(t, i) {
  12. for (var e in i) if (Object.prototype.hasOwnProperty.call(i, e)) t[e] = i[e];
  13. };
  14. return extendStatics(t, i);
  15. };
  16. function __extends(t, i) {
  17. if (typeof i !== "function" && i !== null) throw new TypeError("Class extends value " + String(i) + " is not a constructor or null");
  18. extendStatics(t, i);
  19. function __() {
  20. this.constructor = t;
  21. }
  22. t.prototype = i === null ? Object.create(i) : (__.prototype = i.prototype, new __);
  23. }
  24. function __generator(t, i) {
  25. var e = {
  26. label: 0,
  27. sent: function() {
  28. if (s[0] & 1) throw s[1];
  29. return s[1];
  30. },
  31. trys: [],
  32. ops: []
  33. }, r, n, s, h;
  34. return h = {
  35. next: verb(0),
  36. throw: verb(1),
  37. return: verb(2)
  38. }, typeof Symbol === "function" && (h[Symbol.iterator] = function() {
  39. return this;
  40. }), h;
  41. function verb(t) {
  42. return function(i) {
  43. return step([ t, i ]);
  44. };
  45. }
  46. function step(h) {
  47. if (r) throw new TypeError("Generator is already executing.");
  48. while (e) try {
  49. if (r = 1, n && (s = h[0] & 2 ? n["return"] : h[0] ? n["throw"] || ((s = n["return"]) && s.call(n),
  50. 0) : n.next) && !(s = s.call(n, h[1])).done) return s;
  51. if (n = 0, s) h = [ h[0] & 2, s.value ];
  52. switch (h[0]) {
  53. case 0:
  54. case 1:
  55. s = h;
  56. break;
  57. case 4:
  58. e.label++;
  59. return {
  60. value: h[1],
  61. done: false
  62. };
  63. case 5:
  64. e.label++;
  65. n = h[1];
  66. h = [ 0 ];
  67. continue;
  68. case 7:
  69. h = e.ops.pop();
  70. e.trys.pop();
  71. continue;
  72. default:
  73. if (!(s = e.trys, s = s.length > 0 && s[s.length - 1]) && (h[0] === 6 || h[0] === 2)) {
  74. e = 0;
  75. continue;
  76. }
  77. if (h[0] === 3 && (!s || h[1] > s[0] && h[1] < s[3])) {
  78. e.label = h[1];
  79. break;
  80. }
  81. if (h[0] === 6 && e.label < s[1]) {
  82. e.label = s[1];
  83. s = h;
  84. break;
  85. }
  86. if (s && e.label < s[2]) {
  87. e.label = s[2];
  88. e.ops.push(h);
  89. break;
  90. }
  91. if (s[2]) e.ops.pop();
  92. e.trys.pop();
  93. continue;
  94. }
  95. h = i.call(t, e);
  96. } catch (t) {
  97. h = [ 6, t ];
  98. n = 0;
  99. } finally {
  100. r = s = 0;
  101. }
  102. if (h[0] & 5) throw h[1];
  103. return {
  104. value: h[0] ? h[1] : void 0,
  105. done: true
  106. };
  107. }
  108. }
  109. function __values(t) {
  110. var i = typeof Symbol === "function" && Symbol.iterator, e = i && t[i], r = 0;
  111. if (e) return e.call(t);
  112. if (t && typeof t.length === "number") return {
  113. next: function() {
  114. if (t && r >= t.length) t = void 0;
  115. return {
  116. value: t && t[r++],
  117. done: !t
  118. };
  119. }
  120. };
  121. throw new TypeError(i ? "Object is not iterable." : "Symbol.iterator is not defined.");
  122. }
  123. function __read(t, i) {
  124. var e = typeof Symbol === "function" && t[Symbol.iterator];
  125. if (!e) return t;
  126. var r = e.call(t), n, s = [], h;
  127. try {
  128. while ((i === void 0 || i-- > 0) && !(n = r.next()).done) s.push(n.value);
  129. } catch (t) {
  130. h = {
  131. error: t
  132. };
  133. } finally {
  134. try {
  135. if (n && !n.done && (e = r["return"])) e.call(r);
  136. } finally {
  137. if (h) throw h.error;
  138. }
  139. }
  140. return s;
  141. }
  142. function __spreadArray(t, i, e) {
  143. if (e || arguments.length === 2) for (var r = 0, n = i.length, s; r < n; r++) {
  144. if (s || !(r in i)) {
  145. if (!s) s = Array.prototype.slice.call(i, 0, r);
  146. s[r] = i[r];
  147. }
  148. }
  149. return t.concat(s || Array.prototype.slice.call(i));
  150. }
  151. var i = function() {
  152. function ContainerIterator(t) {
  153. if (t === void 0) {
  154. t = 0;
  155. }
  156. this.iteratorType = t;
  157. }
  158. return ContainerIterator;
  159. }();
  160. var e = function() {
  161. function Base() {
  162. this.t = 0;
  163. }
  164. Base.prototype.size = function() {
  165. return this.t;
  166. };
  167. Base.prototype.empty = function() {
  168. return this.t === 0;
  169. };
  170. return Base;
  171. }();
  172. var r = function(t) {
  173. __extends(Container, t);
  174. function Container() {
  175. return t !== null && t.apply(this, arguments) || this;
  176. }
  177. return Container;
  178. }(e);
  179. var n = function(t) {
  180. __extends(Stack, t);
  181. function Stack(i) {
  182. if (i === void 0) {
  183. i = [];
  184. }
  185. var e = t.call(this) || this;
  186. e.i = [];
  187. i.forEach((function(t) {
  188. return e.push(t);
  189. }));
  190. return e;
  191. }
  192. Stack.prototype.clear = function() {
  193. this.t = 0;
  194. this.i.length = 0;
  195. };
  196. Stack.prototype.push = function(t) {
  197. this.i.push(t);
  198. this.t += 1;
  199. };
  200. Stack.prototype.pop = function() {
  201. this.i.pop();
  202. if (this.t > 0) this.t -= 1;
  203. };
  204. Stack.prototype.top = function() {
  205. return this.i[this.t - 1];
  206. };
  207. return Stack;
  208. }(e);
  209. var s = function(t) {
  210. __extends(SequentialContainer, t);
  211. function SequentialContainer() {
  212. return t !== null && t.apply(this, arguments) || this;
  213. }
  214. return SequentialContainer;
  215. }(r);
  216. var h = function(t) {
  217. __extends(RandomIterator, t);
  218. function RandomIterator(i, e, r, n, s) {
  219. var h = t.call(this, s) || this;
  220. h.h = i;
  221. h.u = e;
  222. h.o = r;
  223. h.v = n;
  224. if (h.iteratorType === 0) {
  225. h.pre = function() {
  226. if (this.h === 0) {
  227. throw new RangeError("Random iterator access denied!");
  228. }
  229. this.h -= 1;
  230. return this;
  231. };
  232. h.next = function() {
  233. if (this.h === this.u()) {
  234. throw new RangeError("Random Iterator access denied!");
  235. }
  236. this.h += 1;
  237. return this;
  238. };
  239. } else {
  240. h.pre = function() {
  241. if (this.h === this.u() - 1) {
  242. throw new RangeError("Random iterator access denied!");
  243. }
  244. this.h += 1;
  245. return this;
  246. };
  247. h.next = function() {
  248. if (this.h === -1) {
  249. throw new RangeError("Random iterator access denied!");
  250. }
  251. this.h -= 1;
  252. return this;
  253. };
  254. }
  255. return h;
  256. }
  257. Object.defineProperty(RandomIterator.prototype, "pointer", {
  258. get: function() {
  259. return this.o(this.h);
  260. },
  261. set: function(t) {
  262. this.v(this.h, t);
  263. },
  264. enumerable: false,
  265. configurable: true
  266. });
  267. RandomIterator.prototype.equals = function(t) {
  268. return this.h === t.h;
  269. };
  270. return RandomIterator;
  271. }(i);
  272. var u = function(t) {
  273. __extends(DequeIterator, t);
  274. function DequeIterator() {
  275. return t !== null && t.apply(this, arguments) || this;
  276. }
  277. DequeIterator.prototype.copy = function() {
  278. return new DequeIterator(this.h, this.u, this.o, this.v, this.iteratorType);
  279. };
  280. return DequeIterator;
  281. }(h);
  282. var f = function(t) {
  283. __extends(Deque, t);
  284. function Deque(i, e) {
  285. if (i === void 0) {
  286. i = [];
  287. }
  288. if (e === void 0) {
  289. e = 1 << 12;
  290. }
  291. var r = t.call(this) || this;
  292. r.l = 0;
  293. r._ = 0;
  294. r.L = 0;
  295. r.p = 0;
  296. r.O = 0;
  297. r.k = [];
  298. var n;
  299. if ("size" in i) {
  300. if (typeof i.size === "number") {
  301. n = i.size;
  302. } else {
  303. n = i.size();
  304. }
  305. } else if ("length" in i) {
  306. n = i.length;
  307. } else {
  308. throw new RangeError("Can't get container's size!");
  309. }
  310. r.S = e;
  311. r.O = Math.max(Math.ceil(n / r.S), 1);
  312. for (var s = 0; s < r.O; ++s) {
  313. r.k.push(new Array(r.S));
  314. }
  315. var h = Math.ceil(n / r.S);
  316. r.l = r.L = (r.O >> 1) - (h >> 1);
  317. r._ = r.p = r.S - n % r.S >> 1;
  318. i.forEach((function(t) {
  319. return r.pushBack(t);
  320. }));
  321. r.size = r.size.bind(r);
  322. r.getElementByPos = r.getElementByPos.bind(r);
  323. r.setElementByPos = r.setElementByPos.bind(r);
  324. return r;
  325. }
  326. Deque.prototype.I = function() {
  327. var t = [];
  328. var i = Math.max(this.O >> 1, 1);
  329. for (var e = 0; e < i; ++e) {
  330. t[e] = new Array(this.S);
  331. }
  332. for (var e = this.l; e < this.O; ++e) {
  333. t[t.length] = this.k[e];
  334. }
  335. for (var e = 0; e < this.L; ++e) {
  336. t[t.length] = this.k[e];
  337. }
  338. t[t.length] = __spreadArray([], __read(this.k[this.L]), false);
  339. this.l = i;
  340. this.L = t.length - 1;
  341. for (var e = 0; e < i; ++e) {
  342. t[t.length] = new Array(this.S);
  343. }
  344. this.k = t;
  345. this.O = t.length;
  346. };
  347. Deque.prototype.g = function(t) {
  348. var i = this._ + t + 1;
  349. var e = i % this.S;
  350. var r = e - 1;
  351. var n = this.l + (i - e) / this.S;
  352. if (e === 0) n -= 1;
  353. n %= this.O;
  354. if (r < 0) r += this.S;
  355. return {
  356. curNodeBucketIndex: n,
  357. curNodePointerIndex: r
  358. };
  359. };
  360. Deque.prototype.clear = function() {
  361. this.k = [ [] ];
  362. this.O = 1;
  363. this.l = this.L = this.t = 0;
  364. this._ = this.p = this.S >> 1;
  365. };
  366. Deque.prototype.front = function() {
  367. return this.k[this.l][this._];
  368. };
  369. Deque.prototype.back = function() {
  370. return this.k[this.L][this.p];
  371. };
  372. Deque.prototype.begin = function() {
  373. return new u(0, this.size, this.getElementByPos, this.setElementByPos);
  374. };
  375. Deque.prototype.end = function() {
  376. return new u(this.t, this.size, this.getElementByPos, this.setElementByPos);
  377. };
  378. Deque.prototype.rBegin = function() {
  379. return new u(this.t - 1, this.size, this.getElementByPos, this.setElementByPos, 1);
  380. };
  381. Deque.prototype.rEnd = function() {
  382. return new u(-1, this.size, this.getElementByPos, this.setElementByPos, 1);
  383. };
  384. Deque.prototype.pushBack = function(t) {
  385. if (this.t) {
  386. if (this.p < this.S - 1) {
  387. this.p += 1;
  388. } else if (this.L < this.O - 1) {
  389. this.L += 1;
  390. this.p = 0;
  391. } else {
  392. this.L = 0;
  393. this.p = 0;
  394. }
  395. if (this.L === this.l && this.p === this._) this.I();
  396. }
  397. this.t += 1;
  398. this.k[this.L][this.p] = t;
  399. };
  400. Deque.prototype.popBack = function() {
  401. if (!this.t) return;
  402. this.k[this.L][this.p] = undefined;
  403. if (this.t !== 1) {
  404. if (this.p > 0) {
  405. this.p -= 1;
  406. } else if (this.L > 0) {
  407. this.L -= 1;
  408. this.p = this.S - 1;
  409. } else {
  410. this.L = this.O - 1;
  411. this.p = this.S - 1;
  412. }
  413. }
  414. this.t -= 1;
  415. };
  416. Deque.prototype.pushFront = function(t) {
  417. if (this.t) {
  418. if (this._ > 0) {
  419. this._ -= 1;
  420. } else if (this.l > 0) {
  421. this.l -= 1;
  422. this._ = this.S - 1;
  423. } else {
  424. this.l = this.O - 1;
  425. this._ = this.S - 1;
  426. }
  427. if (this.l === this.L && this._ === this.p) this.I();
  428. }
  429. this.t += 1;
  430. this.k[this.l][this._] = t;
  431. };
  432. Deque.prototype.popFront = function() {
  433. if (!this.t) return;
  434. this.k[this.l][this._] = undefined;
  435. if (this.t !== 1) {
  436. if (this._ < this.S - 1) {
  437. this._ += 1;
  438. } else if (this.l < this.O - 1) {
  439. this.l += 1;
  440. this._ = 0;
  441. } else {
  442. this.l = 0;
  443. this._ = 0;
  444. }
  445. }
  446. this.t -= 1;
  447. };
  448. Deque.prototype.forEach = function(t) {
  449. for (var i = 0; i < this.t; ++i) {
  450. t(this.getElementByPos(i), i);
  451. }
  452. };
  453. Deque.prototype.getElementByPos = function(t) {
  454. var i = this.g(t), e = i.curNodeBucketIndex, r = i.curNodePointerIndex;
  455. return this.k[e][r];
  456. };
  457. Deque.prototype.setElementByPos = function(t, i) {
  458. var e = this.g(t), r = e.curNodeBucketIndex, n = e.curNodePointerIndex;
  459. this.k[r][n] = i;
  460. };
  461. Deque.prototype.insert = function(t, i, e) {
  462. if (e === void 0) {
  463. e = 1;
  464. }
  465. if (t === 0) {
  466. while (e--) this.pushFront(i);
  467. } else if (t === this.t) {
  468. while (e--) this.pushBack(i);
  469. } else {
  470. var r = [];
  471. for (var n = t; n < this.t; ++n) {
  472. r.push(this.getElementByPos(n));
  473. }
  474. this.cut(t - 1);
  475. for (var n = 0; n < e; ++n) this.pushBack(i);
  476. for (var n = 0; n < r.length; ++n) this.pushBack(r[n]);
  477. }
  478. };
  479. Deque.prototype.cut = function(t) {
  480. if (t < 0) {
  481. this.clear();
  482. return;
  483. }
  484. var i = this.g(t), e = i.curNodeBucketIndex, r = i.curNodePointerIndex;
  485. this.L = e;
  486. this.p = r;
  487. this.t = t + 1;
  488. };
  489. Deque.prototype.eraseElementByPos = function(t) {
  490. var i = this;
  491. if (t === 0) this.popFront(); else if (t === this.t - 1) this.popBack(); else {
  492. var e = [];
  493. for (var r = t + 1; r < this.t; ++r) {
  494. e.push(this.getElementByPos(r));
  495. }
  496. this.cut(t);
  497. this.popBack();
  498. e.forEach((function(t) {
  499. return i.pushBack(t);
  500. }));
  501. }
  502. };
  503. Deque.prototype.eraseElementByValue = function(t) {
  504. if (!this.t) return;
  505. var i = [];
  506. for (var e = 0; e < this.t; ++e) {
  507. var r = this.getElementByPos(e);
  508. if (r !== t) i.push(r);
  509. }
  510. var n = i.length;
  511. for (var e = 0; e < n; ++e) this.setElementByPos(e, i[e]);
  512. this.cut(n - 1);
  513. };
  514. Deque.prototype.eraseElementByIterator = function(t) {
  515. var i = t.h;
  516. this.eraseElementByPos(i);
  517. t = t.next();
  518. return t;
  519. };
  520. Deque.prototype.find = function(t) {
  521. for (var i = 0; i < this.t; ++i) {
  522. if (this.getElementByPos(i) === t) {
  523. return new u(i, this.size, this.getElementByPos, this.setElementByPos);
  524. }
  525. }
  526. return this.end();
  527. };
  528. Deque.prototype.reverse = function() {
  529. var t = 0;
  530. var i = this.t - 1;
  531. while (t < i) {
  532. var e = this.getElementByPos(t);
  533. this.setElementByPos(t, this.getElementByPos(i));
  534. this.setElementByPos(i, e);
  535. t += 1;
  536. i -= 1;
  537. }
  538. };
  539. Deque.prototype.unique = function() {
  540. if (this.t <= 1) return;
  541. var t = 1;
  542. var i = this.getElementByPos(0);
  543. for (var e = 1; e < this.t; ++e) {
  544. var r = this.getElementByPos(e);
  545. if (r !== i) {
  546. i = r;
  547. this.setElementByPos(t++, r);
  548. }
  549. }
  550. while (this.t > t) this.popBack();
  551. };
  552. Deque.prototype.sort = function(t) {
  553. var i = [];
  554. for (var e = 0; e < this.t; ++e) {
  555. i.push(this.getElementByPos(e));
  556. }
  557. i.sort(t);
  558. for (var e = 0; e < this.t; ++e) this.setElementByPos(e, i[e]);
  559. };
  560. Deque.prototype.shrinkToFit = function() {
  561. if (!this.t) return;
  562. var t = [];
  563. this.forEach((function(i) {
  564. return t.push(i);
  565. }));
  566. this.O = Math.max(Math.ceil(this.t / this.S), 1);
  567. this.t = this.l = this.L = this._ = this.p = 0;
  568. this.k = [];
  569. for (var i = 0; i < this.O; ++i) {
  570. this.k.push(new Array(this.S));
  571. }
  572. for (var i = 0; i < t.length; ++i) this.pushBack(t[i]);
  573. };
  574. Deque.prototype[Symbol.iterator] = function() {
  575. return function() {
  576. var t;
  577. return __generator(this, (function(i) {
  578. switch (i.label) {
  579. case 0:
  580. t = 0;
  581. i.label = 1;
  582. case 1:
  583. if (!(t < this.t)) return [ 3, 4 ];
  584. return [ 4, this.getElementByPos(t) ];
  585. case 2:
  586. i.sent();
  587. i.label = 3;
  588. case 3:
  589. ++t;
  590. return [ 3, 1 ];
  591. case 4:
  592. return [ 2 ];
  593. }
  594. }));
  595. }.bind(this)();
  596. };
  597. return Deque;
  598. }(s);
  599. var a = function(t) {
  600. __extends(Queue, t);
  601. function Queue(i) {
  602. if (i === void 0) {
  603. i = [];
  604. }
  605. var e = t.call(this) || this;
  606. e.T = new f(i);
  607. e.t = e.T.size();
  608. return e;
  609. }
  610. Queue.prototype.clear = function() {
  611. this.T.clear();
  612. this.t = 0;
  613. };
  614. Queue.prototype.push = function(t) {
  615. this.T.pushBack(t);
  616. this.t += 1;
  617. };
  618. Queue.prototype.pop = function() {
  619. this.T.popFront();
  620. if (this.t) this.t -= 1;
  621. };
  622. Queue.prototype.front = function() {
  623. return this.T.front();
  624. };
  625. return Queue;
  626. }(e);
  627. var o = function(t) {
  628. __extends(PriorityQueue, t);
  629. function PriorityQueue(i, e, r) {
  630. if (i === void 0) {
  631. i = [];
  632. }
  633. if (e === void 0) {
  634. e = function(t, i) {
  635. if (t > i) return -1;
  636. if (t < i) return 1;
  637. return 0;
  638. };
  639. }
  640. if (r === void 0) {
  641. r = true;
  642. }
  643. var n = t.call(this) || this;
  644. n.M = e;
  645. if (Array.isArray(i)) {
  646. n.q = r ? __spreadArray([], __read(i), false) : i;
  647. } else {
  648. n.q = [];
  649. i.forEach((function(t) {
  650. return n.q.push(t);
  651. }));
  652. }
  653. n.t = n.q.length;
  654. var s = n.t >> 1;
  655. for (var h = n.t - 1 >> 1; h >= 0; --h) {
  656. n.D(h, s);
  657. }
  658. return n;
  659. }
  660. PriorityQueue.prototype.m = function(t) {
  661. var i = this.q[t];
  662. while (t > 0) {
  663. var e = t - 1 >> 1;
  664. var r = this.q[e];
  665. if (this.M(r, i) <= 0) break;
  666. this.q[t] = r;
  667. t = e;
  668. }
  669. this.q[t] = i;
  670. };
  671. PriorityQueue.prototype.D = function(t, i) {
  672. var e = this.q[t];
  673. while (t < i) {
  674. var r = t << 1 | 1;
  675. var n = r + 1;
  676. var s = this.q[r];
  677. if (n < this.t && this.M(s, this.q[n]) > 0) {
  678. r = n;
  679. s = this.q[n];
  680. }
  681. if (this.M(s, e) >= 0) break;
  682. this.q[t] = s;
  683. t = r;
  684. }
  685. this.q[t] = e;
  686. };
  687. PriorityQueue.prototype.clear = function() {
  688. this.t = 0;
  689. this.q.length = 0;
  690. };
  691. PriorityQueue.prototype.push = function(t) {
  692. this.q.push(t);
  693. this.m(this.t);
  694. this.t += 1;
  695. };
  696. PriorityQueue.prototype.pop = function() {
  697. if (!this.t) return;
  698. var t = this.q.pop();
  699. this.t -= 1;
  700. if (this.t) {
  701. this.q[0] = t;
  702. this.D(0, this.t >> 1);
  703. }
  704. };
  705. PriorityQueue.prototype.top = function() {
  706. return this.q[0];
  707. };
  708. PriorityQueue.prototype.find = function(t) {
  709. return this.q.indexOf(t) >= 0;
  710. };
  711. PriorityQueue.prototype.remove = function(t) {
  712. var i = this.q.indexOf(t);
  713. if (i < 0) return false;
  714. if (i === 0) {
  715. this.pop();
  716. } else if (i === this.t - 1) {
  717. this.q.pop();
  718. this.t -= 1;
  719. } else {
  720. this.q.splice(i, 1, this.q.pop());
  721. this.t -= 1;
  722. this.m(i);
  723. this.D(i, this.t >> 1);
  724. }
  725. return true;
  726. };
  727. PriorityQueue.prototype.updateItem = function(t) {
  728. var i = this.q.indexOf(t);
  729. if (i < 0) return false;
  730. this.m(i);
  731. this.D(i, this.t >> 1);
  732. return true;
  733. };
  734. PriorityQueue.prototype.toArray = function() {
  735. return __spreadArray([], __read(this.q), false);
  736. };
  737. return PriorityQueue;
  738. }(e);
  739. var c = function(t) {
  740. __extends(VectorIterator, t);
  741. function VectorIterator() {
  742. return t !== null && t.apply(this, arguments) || this;
  743. }
  744. VectorIterator.prototype.copy = function() {
  745. return new VectorIterator(this.h, this.u, this.o, this.v, this.iteratorType);
  746. };
  747. return VectorIterator;
  748. }(h);
  749. var v = function(t) {
  750. __extends(Vector, t);
  751. function Vector(i, e) {
  752. if (i === void 0) {
  753. i = [];
  754. }
  755. if (e === void 0) {
  756. e = true;
  757. }
  758. var r = t.call(this) || this;
  759. if (Array.isArray(i)) {
  760. r.C = e ? __spreadArray([], __read(i), false) : i;
  761. r.t = i.length;
  762. } else {
  763. r.C = [];
  764. i.forEach((function(t) {
  765. return r.pushBack(t);
  766. }));
  767. }
  768. r.size = r.size.bind(r);
  769. r.getElementByPos = r.getElementByPos.bind(r);
  770. r.setElementByPos = r.setElementByPos.bind(r);
  771. return r;
  772. }
  773. Vector.prototype.clear = function() {
  774. this.t = 0;
  775. this.C.length = 0;
  776. };
  777. Vector.prototype.begin = function() {
  778. return new c(0, this.size, this.getElementByPos, this.setElementByPos);
  779. };
  780. Vector.prototype.end = function() {
  781. return new c(this.t, this.size, this.getElementByPos, this.setElementByPos);
  782. };
  783. Vector.prototype.rBegin = function() {
  784. return new c(this.t - 1, this.size, this.getElementByPos, this.setElementByPos, 1);
  785. };
  786. Vector.prototype.rEnd = function() {
  787. return new c(-1, this.size, this.getElementByPos, this.setElementByPos, 1);
  788. };
  789. Vector.prototype.front = function() {
  790. return this.C[0];
  791. };
  792. Vector.prototype.back = function() {
  793. return this.C[this.t - 1];
  794. };
  795. Vector.prototype.forEach = function(t) {
  796. for (var i = 0; i < this.t; ++i) {
  797. t(this.C[i], i);
  798. }
  799. };
  800. Vector.prototype.getElementByPos = function(t) {
  801. return this.C[t];
  802. };
  803. Vector.prototype.eraseElementByPos = function(t) {
  804. this.C.splice(t, 1);
  805. this.t -= 1;
  806. };
  807. Vector.prototype.eraseElementByValue = function(t) {
  808. var i = 0;
  809. for (var e = 0; e < this.t; ++e) {
  810. if (this.C[e] !== t) {
  811. this.C[i++] = this.C[e];
  812. }
  813. }
  814. this.t = this.C.length = i;
  815. };
  816. Vector.prototype.eraseElementByIterator = function(t) {
  817. var i = t.h;
  818. t = t.next();
  819. this.eraseElementByPos(i);
  820. return t;
  821. };
  822. Vector.prototype.pushBack = function(t) {
  823. this.C.push(t);
  824. this.t += 1;
  825. };
  826. Vector.prototype.popBack = function() {
  827. if (!this.t) return;
  828. this.C.pop();
  829. this.t -= 1;
  830. };
  831. Vector.prototype.setElementByPos = function(t, i) {
  832. this.C[t] = i;
  833. };
  834. Vector.prototype.insert = function(t, i, e) {
  835. var r;
  836. if (e === void 0) {
  837. e = 1;
  838. }
  839. (r = this.C).splice.apply(r, __spreadArray([ t, 0 ], __read(new Array(e).fill(i)), false));
  840. this.t += e;
  841. };
  842. Vector.prototype.find = function(t) {
  843. for (var i = 0; i < this.t; ++i) {
  844. if (this.C[i] === t) {
  845. return new c(i, this.size, this.getElementByPos, this.getElementByPos);
  846. }
  847. }
  848. return this.end();
  849. };
  850. Vector.prototype.reverse = function() {
  851. this.C.reverse();
  852. };
  853. Vector.prototype.unique = function() {
  854. var t = 1;
  855. for (var i = 1; i < this.t; ++i) {
  856. if (this.C[i] !== this.C[i - 1]) {
  857. this.C[t++] = this.C[i];
  858. }
  859. }
  860. this.t = this.C.length = t;
  861. };
  862. Vector.prototype.sort = function(t) {
  863. this.C.sort(t);
  864. };
  865. Vector.prototype[Symbol.iterator] = function() {
  866. return function() {
  867. return __generator(this, (function(t) {
  868. switch (t.label) {
  869. case 0:
  870. return [ 5, __values(this.C) ];
  871. case 1:
  872. return [ 2, t.sent() ];
  873. }
  874. }));
  875. }.bind(this)();
  876. };
  877. return Vector;
  878. }(s);
  879. var d = function() {
  880. function LinkNode(t) {
  881. this.R = undefined;
  882. this.V = undefined;
  883. this.H = undefined;
  884. this.R = t;
  885. }
  886. return LinkNode;
  887. }();
  888. var l = function(t) {
  889. __extends(LinkListIterator, t);
  890. function LinkListIterator(i, e, r) {
  891. var n = t.call(this, r) || this;
  892. n.h = i;
  893. n.N = e;
  894. if (n.iteratorType === 0) {
  895. n.pre = function() {
  896. if (this.h.V === this.N) {
  897. throw new RangeError("LinkList iterator access denied!");
  898. }
  899. this.h = this.h.V;
  900. return this;
  901. };
  902. n.next = function() {
  903. if (this.h === this.N) {
  904. throw new RangeError("LinkList iterator access denied!");
  905. }
  906. this.h = this.h.H;
  907. return this;
  908. };
  909. } else {
  910. n.pre = function() {
  911. if (this.h.H === this.N) {
  912. throw new RangeError("LinkList iterator access denied!");
  913. }
  914. this.h = this.h.H;
  915. return this;
  916. };
  917. n.next = function() {
  918. if (this.h === this.N) {
  919. throw new RangeError("LinkList iterator access denied!");
  920. }
  921. this.h = this.h.V;
  922. return this;
  923. };
  924. }
  925. return n;
  926. }
  927. Object.defineProperty(LinkListIterator.prototype, "pointer", {
  928. get: function() {
  929. if (this.h === this.N) {
  930. throw new RangeError("LinkList iterator access denied!");
  931. }
  932. return this.h.R;
  933. },
  934. set: function(t) {
  935. if (this.h === this.N) {
  936. throw new RangeError("LinkList iterator access denied!");
  937. }
  938. this.h.R = t;
  939. },
  940. enumerable: false,
  941. configurable: true
  942. });
  943. LinkListIterator.prototype.equals = function(t) {
  944. return this.h === t.h;
  945. };
  946. LinkListIterator.prototype.copy = function() {
  947. return new LinkListIterator(this.h, this.N, this.iteratorType);
  948. };
  949. return LinkListIterator;
  950. }(i);
  951. var w = function(t) {
  952. __extends(LinkList, t);
  953. function LinkList(i) {
  954. if (i === void 0) {
  955. i = [];
  956. }
  957. var e = t.call(this) || this;
  958. e.N = new d;
  959. e.j = undefined;
  960. e.P = undefined;
  961. i.forEach((function(t) {
  962. return e.pushBack(t);
  963. }));
  964. return e;
  965. }
  966. LinkList.prototype.clear = function() {
  967. this.t = 0;
  968. this.j = this.P = undefined;
  969. this.N.V = this.N.H = undefined;
  970. };
  971. LinkList.prototype.begin = function() {
  972. return new l(this.j || this.N, this.N);
  973. };
  974. LinkList.prototype.end = function() {
  975. return new l(this.N, this.N);
  976. };
  977. LinkList.prototype.rBegin = function() {
  978. return new l(this.P || this.N, this.N, 1);
  979. };
  980. LinkList.prototype.rEnd = function() {
  981. return new l(this.N, this.N, 1);
  982. };
  983. LinkList.prototype.front = function() {
  984. return this.j ? this.j.R : undefined;
  985. };
  986. LinkList.prototype.back = function() {
  987. return this.P ? this.P.R : undefined;
  988. };
  989. LinkList.prototype.forEach = function(t) {
  990. if (!this.t) return;
  991. var i = this.j;
  992. var e = 0;
  993. while (i !== this.N) {
  994. t(i.R, e++);
  995. i = i.H;
  996. }
  997. };
  998. LinkList.prototype.getElementByPos = function(t) {
  999. var i = this.j;
  1000. while (t--) {
  1001. i = i.H;
  1002. }
  1003. return i.R;
  1004. };
  1005. LinkList.prototype.eraseElementByPos = function(t) {
  1006. if (t === 0) this.popFront(); else if (t === this.t - 1) this.popBack(); else {
  1007. var i = this.j;
  1008. while (t--) {
  1009. i = i.H;
  1010. }
  1011. i = i;
  1012. var e = i.V;
  1013. var r = i.H;
  1014. r.V = e;
  1015. e.H = r;
  1016. this.t -= 1;
  1017. }
  1018. };
  1019. LinkList.prototype.eraseElementByValue = function(t) {
  1020. while (this.j && this.j.R === t) this.popFront();
  1021. while (this.P && this.P.R === t) this.popBack();
  1022. if (!this.j) return;
  1023. var i = this.j;
  1024. while (i !== this.N) {
  1025. if (i.R === t) {
  1026. var e = i.V;
  1027. var r = i.H;
  1028. r.V = e;
  1029. e.H = r;
  1030. this.t -= 1;
  1031. }
  1032. i = i.H;
  1033. }
  1034. };
  1035. LinkList.prototype.eraseElementByIterator = function(t) {
  1036. var i = t.h;
  1037. if (i === this.N) {
  1038. throw new RangeError("Invalid iterator");
  1039. }
  1040. t = t.next();
  1041. if (this.j === i) this.popFront(); else if (this.P === i) this.popBack(); else {
  1042. var e = i.V;
  1043. var r = i.H;
  1044. r.V = e;
  1045. e.H = r;
  1046. this.t -= 1;
  1047. }
  1048. return t;
  1049. };
  1050. LinkList.prototype.pushBack = function(t) {
  1051. this.t += 1;
  1052. var i = new d(t);
  1053. if (!this.P) {
  1054. this.j = this.P = i;
  1055. this.N.H = this.j;
  1056. this.j.V = this.N;
  1057. } else {
  1058. this.P.H = i;
  1059. i.V = this.P;
  1060. this.P = i;
  1061. }
  1062. this.P.H = this.N;
  1063. this.N.V = this.P;
  1064. };
  1065. LinkList.prototype.popBack = function() {
  1066. if (!this.P) return;
  1067. this.t -= 1;
  1068. if (this.j === this.P) {
  1069. this.j = this.P = undefined;
  1070. this.N.H = undefined;
  1071. } else {
  1072. this.P = this.P.V;
  1073. this.P.H = this.N;
  1074. }
  1075. this.N.V = this.P;
  1076. };
  1077. LinkList.prototype.setElementByPos = function(t, i) {
  1078. var e = this.j;
  1079. while (t--) {
  1080. e = e.H;
  1081. }
  1082. e.R = i;
  1083. };
  1084. LinkList.prototype.insert = function(t, i, e) {
  1085. if (e === void 0) {
  1086. e = 1;
  1087. }
  1088. if (e <= 0) return;
  1089. if (t === 0) {
  1090. while (e--) this.pushFront(i);
  1091. } else if (t === this.t) {
  1092. while (e--) this.pushBack(i);
  1093. } else {
  1094. var r = this.j;
  1095. for (var n = 1; n < t; ++n) {
  1096. r = r.H;
  1097. }
  1098. var s = r.H;
  1099. this.t += e;
  1100. while (e--) {
  1101. r.H = new d(i);
  1102. r.H.V = r;
  1103. r = r.H;
  1104. }
  1105. r.H = s;
  1106. s.V = r;
  1107. }
  1108. };
  1109. LinkList.prototype.find = function(t) {
  1110. if (!this.j) return this.end();
  1111. var i = this.j;
  1112. while (i !== this.N) {
  1113. if (i.R === t) {
  1114. return new l(i, this.N);
  1115. }
  1116. i = i.H;
  1117. }
  1118. return this.end();
  1119. };
  1120. LinkList.prototype.reverse = function() {
  1121. if (this.t <= 1) return;
  1122. var t = this.j;
  1123. var i = this.P;
  1124. var e = 0;
  1125. while (e << 1 < this.t) {
  1126. var r = t.R;
  1127. t.R = i.R;
  1128. i.R = r;
  1129. t = t.H;
  1130. i = i.V;
  1131. e += 1;
  1132. }
  1133. };
  1134. LinkList.prototype.unique = function() {
  1135. if (this.t <= 1) return;
  1136. var t = this.j;
  1137. while (t !== this.N) {
  1138. var i = t;
  1139. while (i.H && i.R === i.H.R) {
  1140. i = i.H;
  1141. this.t -= 1;
  1142. }
  1143. t.H = i.H;
  1144. t.H.V = t;
  1145. t = t.H;
  1146. }
  1147. };
  1148. LinkList.prototype.sort = function(t) {
  1149. if (this.t <= 1) return;
  1150. var i = [];
  1151. this.forEach((function(t) {
  1152. return i.push(t);
  1153. }));
  1154. i.sort(t);
  1155. var e = this.j;
  1156. i.forEach((function(t) {
  1157. e.R = t;
  1158. e = e.H;
  1159. }));
  1160. };
  1161. LinkList.prototype.pushFront = function(t) {
  1162. this.t += 1;
  1163. var i = new d(t);
  1164. if (!this.j) {
  1165. this.j = this.P = i;
  1166. this.P.H = this.N;
  1167. this.N.V = this.P;
  1168. } else {
  1169. i.H = this.j;
  1170. this.j.V = i;
  1171. this.j = i;
  1172. }
  1173. this.N.H = this.j;
  1174. this.j.V = this.N;
  1175. };
  1176. LinkList.prototype.popFront = function() {
  1177. if (!this.j) return;
  1178. this.t -= 1;
  1179. if (this.j === this.P) {
  1180. this.j = this.P = undefined;
  1181. this.N.V = this.P;
  1182. } else {
  1183. this.j = this.j.H;
  1184. this.j.V = this.N;
  1185. }
  1186. this.N.H = this.j;
  1187. };
  1188. LinkList.prototype.merge = function(t) {
  1189. var i = this;
  1190. if (!this.j) {
  1191. t.forEach((function(t) {
  1192. return i.pushBack(t);
  1193. }));
  1194. return;
  1195. }
  1196. var e = this.j;
  1197. t.forEach((function(t) {
  1198. while (e && e !== i.N && e.R <= t) {
  1199. e = e.H;
  1200. }
  1201. if (e === i.N) {
  1202. i.pushBack(t);
  1203. e = i.P;
  1204. } else if (e === i.j) {
  1205. i.pushFront(t);
  1206. e = i.j;
  1207. } else {
  1208. i.t += 1;
  1209. var r = e.V;
  1210. r.H = new d(t);
  1211. r.H.V = r;
  1212. r.H.H = e;
  1213. e.V = r.H;
  1214. }
  1215. }));
  1216. };
  1217. LinkList.prototype[Symbol.iterator] = function() {
  1218. return function() {
  1219. var t;
  1220. return __generator(this, (function(i) {
  1221. switch (i.label) {
  1222. case 0:
  1223. if (!this.j) return [ 2 ];
  1224. t = this.j;
  1225. i.label = 1;
  1226. case 1:
  1227. if (!(t !== this.N)) return [ 3, 3 ];
  1228. return [ 4, t.R ];
  1229. case 2:
  1230. i.sent();
  1231. t = t.H;
  1232. return [ 3, 1 ];
  1233. case 3:
  1234. return [ 2 ];
  1235. }
  1236. }));
  1237. }.bind(this)();
  1238. };
  1239. return LinkList;
  1240. }(s);
  1241. var _ = function() {
  1242. function TreeNode(t, i) {
  1243. this.A = 1;
  1244. this.B = undefined;
  1245. this.R = undefined;
  1246. this.G = undefined;
  1247. this.J = undefined;
  1248. this.F = undefined;
  1249. this.B = t;
  1250. this.R = i;
  1251. }
  1252. TreeNode.prototype.pre = function() {
  1253. var t = this;
  1254. if (t.A === 1 && t.F.F === t) {
  1255. t = t.J;
  1256. } else if (t.G) {
  1257. t = t.G;
  1258. while (t.J) {
  1259. t = t.J;
  1260. }
  1261. } else {
  1262. var i = t.F;
  1263. while (i.G === t) {
  1264. t = i;
  1265. i = t.F;
  1266. }
  1267. t = i;
  1268. }
  1269. return t;
  1270. };
  1271. TreeNode.prototype.next = function() {
  1272. var t = this;
  1273. if (t.J) {
  1274. t = t.J;
  1275. while (t.G) {
  1276. t = t.G;
  1277. }
  1278. return t;
  1279. } else {
  1280. var i = t.F;
  1281. while (i.J === t) {
  1282. t = i;
  1283. i = t.F;
  1284. }
  1285. if (t.J !== i) {
  1286. return i;
  1287. } else return t;
  1288. }
  1289. };
  1290. TreeNode.prototype.rotateLeft = function() {
  1291. var t = this.F;
  1292. var i = this.J;
  1293. var e = i.G;
  1294. if (t.F === this) t.F = i; else if (t.G === this) t.G = i; else t.J = i;
  1295. i.F = t;
  1296. i.G = this;
  1297. this.F = i;
  1298. this.J = e;
  1299. if (e) e.F = this;
  1300. return i;
  1301. };
  1302. TreeNode.prototype.rotateRight = function() {
  1303. var t = this.F;
  1304. var i = this.G;
  1305. var e = i.J;
  1306. if (t.F === this) t.F = i; else if (t.G === this) t.G = i; else t.J = i;
  1307. i.F = t;
  1308. i.J = this;
  1309. this.F = i;
  1310. this.G = e;
  1311. if (e) e.F = this;
  1312. return i;
  1313. };
  1314. return TreeNode;
  1315. }();
  1316. var y = function(t) {
  1317. __extends(TreeNodeEnableIndex, t);
  1318. function TreeNodeEnableIndex() {
  1319. var i = t !== null && t.apply(this, arguments) || this;
  1320. i.G = undefined;
  1321. i.J = undefined;
  1322. i.F = undefined;
  1323. i.K = 1;
  1324. return i;
  1325. }
  1326. TreeNodeEnableIndex.prototype.rotateLeft = function() {
  1327. var i = t.prototype.rotateLeft.call(this);
  1328. this.recount();
  1329. i.recount();
  1330. return i;
  1331. };
  1332. TreeNodeEnableIndex.prototype.rotateRight = function() {
  1333. var i = t.prototype.rotateRight.call(this);
  1334. this.recount();
  1335. i.recount();
  1336. return i;
  1337. };
  1338. TreeNodeEnableIndex.prototype.recount = function() {
  1339. this.K = 1;
  1340. if (this.G) this.K += this.G.K;
  1341. if (this.J) this.K += this.J.K;
  1342. };
  1343. return TreeNodeEnableIndex;
  1344. }(_);
  1345. var L = function(t) {
  1346. __extends(TreeContainer, t);
  1347. function TreeContainer(i, e) {
  1348. if (i === void 0) {
  1349. i = function(t, i) {
  1350. if (t < i) return -1;
  1351. if (t > i) return 1;
  1352. return 0;
  1353. };
  1354. }
  1355. if (e === void 0) {
  1356. e = false;
  1357. }
  1358. var r = t.call(this) || this;
  1359. r.U = undefined;
  1360. r.W = function(t, i) {
  1361. if (t === undefined) return false;
  1362. var e = r.W(t.G, i);
  1363. if (e) return true;
  1364. if (i(t)) return true;
  1365. return r.W(t.J, i);
  1366. };
  1367. r.M = i;
  1368. if (e) {
  1369. r.X = y;
  1370. r.Y = function(t, i, e) {
  1371. var r = this.Z(t, i, e);
  1372. if (r) {
  1373. var n = r.F;
  1374. while (n !== this.N) {
  1375. n.K += 1;
  1376. n = n.F;
  1377. }
  1378. var s = this.$(r);
  1379. if (s) {
  1380. var h = s, u = h.parentNode, f = h.grandParent, a = h.curNode;
  1381. u.recount();
  1382. f.recount();
  1383. a.recount();
  1384. }
  1385. }
  1386. };
  1387. r.tt = function(t) {
  1388. var i = this.it(t);
  1389. while (i !== this.N) {
  1390. i.K -= 1;
  1391. i = i.F;
  1392. }
  1393. };
  1394. } else {
  1395. r.X = _;
  1396. r.Y = function(t, i, e) {
  1397. var r = this.Z(t, i, e);
  1398. if (r) this.$(r);
  1399. };
  1400. r.tt = r.it;
  1401. }
  1402. r.N = new r.X;
  1403. return r;
  1404. }
  1405. TreeContainer.prototype.et = function(t, i) {
  1406. var e;
  1407. while (t) {
  1408. var r = this.M(t.B, i);
  1409. if (r < 0) {
  1410. t = t.J;
  1411. } else if (r > 0) {
  1412. e = t;
  1413. t = t.G;
  1414. } else return t;
  1415. }
  1416. return e === undefined ? this.N : e;
  1417. };
  1418. TreeContainer.prototype.rt = function(t, i) {
  1419. var e;
  1420. while (t) {
  1421. var r = this.M(t.B, i);
  1422. if (r <= 0) {
  1423. t = t.J;
  1424. } else {
  1425. e = t;
  1426. t = t.G;
  1427. }
  1428. }
  1429. return e === undefined ? this.N : e;
  1430. };
  1431. TreeContainer.prototype.nt = function(t, i) {
  1432. var e;
  1433. while (t) {
  1434. var r = this.M(t.B, i);
  1435. if (r < 0) {
  1436. e = t;
  1437. t = t.J;
  1438. } else if (r > 0) {
  1439. t = t.G;
  1440. } else return t;
  1441. }
  1442. return e === undefined ? this.N : e;
  1443. };
  1444. TreeContainer.prototype.st = function(t, i) {
  1445. var e;
  1446. while (t) {
  1447. var r = this.M(t.B, i);
  1448. if (r < 0) {
  1449. e = t;
  1450. t = t.J;
  1451. } else {
  1452. t = t.G;
  1453. }
  1454. }
  1455. return e === undefined ? this.N : e;
  1456. };
  1457. TreeContainer.prototype.ht = function(t) {
  1458. while (true) {
  1459. var i = t.F;
  1460. if (i === this.N) return;
  1461. if (t.A === 1) {
  1462. t.A = 0;
  1463. return;
  1464. }
  1465. if (t === i.G) {
  1466. var e = i.J;
  1467. if (e.A === 1) {
  1468. e.A = 0;
  1469. i.A = 1;
  1470. if (i === this.U) {
  1471. this.U = i.rotateLeft();
  1472. } else i.rotateLeft();
  1473. } else {
  1474. if (e.J && e.J.A === 1) {
  1475. e.A = i.A;
  1476. i.A = 0;
  1477. e.J.A = 0;
  1478. if (i === this.U) {
  1479. this.U = i.rotateLeft();
  1480. } else i.rotateLeft();
  1481. return;
  1482. } else if (e.G && e.G.A === 1) {
  1483. e.A = 1;
  1484. e.G.A = 0;
  1485. e.rotateRight();
  1486. } else {
  1487. e.A = 1;
  1488. t = i;
  1489. }
  1490. }
  1491. } else {
  1492. var e = i.G;
  1493. if (e.A === 1) {
  1494. e.A = 0;
  1495. i.A = 1;
  1496. if (i === this.U) {
  1497. this.U = i.rotateRight();
  1498. } else i.rotateRight();
  1499. } else {
  1500. if (e.G && e.G.A === 1) {
  1501. e.A = i.A;
  1502. i.A = 0;
  1503. e.G.A = 0;
  1504. if (i === this.U) {
  1505. this.U = i.rotateRight();
  1506. } else i.rotateRight();
  1507. return;
  1508. } else if (e.J && e.J.A === 1) {
  1509. e.A = 1;
  1510. e.J.A = 0;
  1511. e.rotateLeft();
  1512. } else {
  1513. e.A = 1;
  1514. t = i;
  1515. }
  1516. }
  1517. }
  1518. }
  1519. };
  1520. TreeContainer.prototype.it = function(t) {
  1521. var i, e;
  1522. if (this.t === 1) {
  1523. this.clear();
  1524. return this.N;
  1525. }
  1526. var r = t;
  1527. while (r.G || r.J) {
  1528. if (r.J) {
  1529. r = r.J;
  1530. while (r.G) r = r.G;
  1531. } else {
  1532. r = r.G;
  1533. }
  1534. i = __read([ r.B, t.B ], 2), t.B = i[0], r.B = i[1];
  1535. e = __read([ r.R, t.R ], 2), t.R = e[0], r.R = e[1];
  1536. t = r;
  1537. }
  1538. if (this.N.G === r) {
  1539. this.N.G = r.F;
  1540. } else if (this.N.J === r) {
  1541. this.N.J = r.F;
  1542. }
  1543. this.ht(r);
  1544. var n = r.F;
  1545. if (r === n.G) {
  1546. n.G = undefined;
  1547. } else n.J = undefined;
  1548. this.t -= 1;
  1549. this.U.A = 0;
  1550. return n;
  1551. };
  1552. TreeContainer.prototype.$ = function(t) {
  1553. while (true) {
  1554. var i = t.F;
  1555. if (i.A === 0) return;
  1556. var e = i.F;
  1557. if (i === e.G) {
  1558. var r = e.J;
  1559. if (r && r.A === 1) {
  1560. r.A = i.A = 0;
  1561. if (e === this.U) return;
  1562. e.A = 1;
  1563. t = e;
  1564. continue;
  1565. } else if (t === i.J) {
  1566. t.A = 0;
  1567. if (t.G) t.G.F = i;
  1568. if (t.J) t.J.F = e;
  1569. i.J = t.G;
  1570. e.G = t.J;
  1571. t.G = i;
  1572. t.J = e;
  1573. if (e === this.U) {
  1574. this.U = t;
  1575. this.N.F = t;
  1576. } else {
  1577. var n = e.F;
  1578. if (n.G === e) {
  1579. n.G = t;
  1580. } else n.J = t;
  1581. }
  1582. t.F = e.F;
  1583. i.F = t;
  1584. e.F = t;
  1585. e.A = 1;
  1586. return {
  1587. parentNode: i,
  1588. grandParent: e,
  1589. curNode: t
  1590. };
  1591. } else {
  1592. i.A = 0;
  1593. if (e === this.U) {
  1594. this.U = e.rotateRight();
  1595. } else e.rotateRight();
  1596. e.A = 1;
  1597. }
  1598. } else {
  1599. var r = e.G;
  1600. if (r && r.A === 1) {
  1601. r.A = i.A = 0;
  1602. if (e === this.U) return;
  1603. e.A = 1;
  1604. t = e;
  1605. continue;
  1606. } else if (t === i.G) {
  1607. t.A = 0;
  1608. if (t.G) t.G.F = e;
  1609. if (t.J) t.J.F = i;
  1610. e.J = t.G;
  1611. i.G = t.J;
  1612. t.G = e;
  1613. t.J = i;
  1614. if (e === this.U) {
  1615. this.U = t;
  1616. this.N.F = t;
  1617. } else {
  1618. var n = e.F;
  1619. if (n.G === e) {
  1620. n.G = t;
  1621. } else n.J = t;
  1622. }
  1623. t.F = e.F;
  1624. i.F = t;
  1625. e.F = t;
  1626. e.A = 1;
  1627. return {
  1628. parentNode: i,
  1629. grandParent: e,
  1630. curNode: t
  1631. };
  1632. } else {
  1633. i.A = 0;
  1634. if (e === this.U) {
  1635. this.U = e.rotateLeft();
  1636. } else e.rotateLeft();
  1637. e.A = 1;
  1638. }
  1639. }
  1640. return;
  1641. }
  1642. };
  1643. TreeContainer.prototype.Z = function(t, i, e) {
  1644. if (this.U === undefined) {
  1645. this.t += 1;
  1646. this.U = new this.X(t, i);
  1647. this.U.A = 0;
  1648. this.U.F = this.N;
  1649. this.N.F = this.U;
  1650. this.N.G = this.U;
  1651. this.N.J = this.U;
  1652. return;
  1653. }
  1654. var r;
  1655. var n = this.N.G;
  1656. var s = this.M(n.B, t);
  1657. if (s === 0) {
  1658. n.R = i;
  1659. return;
  1660. } else if (s > 0) {
  1661. n.G = new this.X(t, i);
  1662. n.G.F = n;
  1663. r = n.G;
  1664. this.N.G = r;
  1665. } else {
  1666. var h = this.N.J;
  1667. var u = this.M(h.B, t);
  1668. if (u === 0) {
  1669. h.R = i;
  1670. return;
  1671. } else if (u < 0) {
  1672. h.J = new this.X(t, i);
  1673. h.J.F = h;
  1674. r = h.J;
  1675. this.N.J = r;
  1676. } else {
  1677. if (e !== undefined) {
  1678. var f = e.h;
  1679. if (f !== this.N) {
  1680. var a = this.M(f.B, t);
  1681. if (a === 0) {
  1682. f.R = i;
  1683. return;
  1684. } else if (a > 0) {
  1685. var o = f.pre();
  1686. var c = this.M(o.B, t);
  1687. if (c === 0) {
  1688. o.R = i;
  1689. return;
  1690. } else if (c < 0) {
  1691. r = new this.X(t, i);
  1692. if (o.J === undefined) {
  1693. o.J = r;
  1694. r.F = o;
  1695. } else {
  1696. f.G = r;
  1697. r.F = f;
  1698. }
  1699. }
  1700. }
  1701. }
  1702. }
  1703. if (r === undefined) {
  1704. r = this.U;
  1705. while (true) {
  1706. var v = this.M(r.B, t);
  1707. if (v > 0) {
  1708. if (r.G === undefined) {
  1709. r.G = new this.X(t, i);
  1710. r.G.F = r;
  1711. r = r.G;
  1712. break;
  1713. }
  1714. r = r.G;
  1715. } else if (v < 0) {
  1716. if (r.J === undefined) {
  1717. r.J = new this.X(t, i);
  1718. r.J.F = r;
  1719. r = r.J;
  1720. break;
  1721. }
  1722. r = r.J;
  1723. } else {
  1724. r.R = i;
  1725. return;
  1726. }
  1727. }
  1728. }
  1729. }
  1730. }
  1731. this.t += 1;
  1732. return r;
  1733. };
  1734. TreeContainer.prototype.clear = function() {
  1735. this.t = 0;
  1736. this.U = undefined;
  1737. this.N.F = undefined;
  1738. this.N.G = this.N.J = undefined;
  1739. };
  1740. TreeContainer.prototype.updateKeyByIterator = function(t, i) {
  1741. var e = t.h;
  1742. if (e === this.N) {
  1743. throw new TypeError("Invalid iterator!");
  1744. }
  1745. if (this.t === 1) {
  1746. e.B = i;
  1747. return true;
  1748. }
  1749. if (e === this.N.G) {
  1750. if (this.M(e.next().B, i) > 0) {
  1751. e.B = i;
  1752. return true;
  1753. }
  1754. return false;
  1755. }
  1756. if (e === this.N.J) {
  1757. if (this.M(e.pre().B, i) < 0) {
  1758. e.B = i;
  1759. return true;
  1760. }
  1761. return false;
  1762. }
  1763. var r = e.pre().B;
  1764. if (this.M(r, i) >= 0) return false;
  1765. var n = e.next().B;
  1766. if (this.M(n, i) <= 0) return false;
  1767. e.B = i;
  1768. return true;
  1769. };
  1770. TreeContainer.prototype.eraseElementByPos = function(t) {
  1771. var i = this;
  1772. var e = 0;
  1773. this.W(this.U, (function(r) {
  1774. if (t === e) {
  1775. i.tt(r);
  1776. return true;
  1777. }
  1778. e += 1;
  1779. return false;
  1780. }));
  1781. };
  1782. TreeContainer.prototype.ut = function(t, i) {
  1783. while (t) {
  1784. var e = this.M(t.B, i);
  1785. if (e < 0) {
  1786. t = t.J;
  1787. } else if (e > 0) {
  1788. t = t.G;
  1789. } else return t;
  1790. }
  1791. return t;
  1792. };
  1793. TreeContainer.prototype.eraseElementByKey = function(t) {
  1794. if (!this.t) return;
  1795. var i = this.ut(this.U, t);
  1796. if (i === undefined) return;
  1797. this.tt(i);
  1798. };
  1799. TreeContainer.prototype.eraseElementByIterator = function(t) {
  1800. var i = t.h;
  1801. if (i === this.N) {
  1802. throw new RangeError("Invalid iterator");
  1803. }
  1804. if (i.J === undefined) {
  1805. t = t.next();
  1806. }
  1807. this.tt(i);
  1808. return t;
  1809. };
  1810. TreeContainer.prototype.getHeight = function() {
  1811. if (!this.t) return 0;
  1812. var traversal = function(t) {
  1813. if (!t) return 0;
  1814. return Math.max(traversal(t.G), traversal(t.J)) + 1;
  1815. };
  1816. return traversal(this.U);
  1817. };
  1818. return TreeContainer;
  1819. }(r);
  1820. var p = function(t) {
  1821. __extends(TreeIterator, t);
  1822. function TreeIterator(i, e, r) {
  1823. var n = t.call(this, r) || this;
  1824. n.h = i;
  1825. n.N = e;
  1826. if (n.iteratorType === 0) {
  1827. n.pre = function() {
  1828. if (this.h === this.N.G) {
  1829. throw new RangeError("Tree iterator access denied!");
  1830. }
  1831. this.h = this.h.pre();
  1832. return this;
  1833. };
  1834. n.next = function() {
  1835. if (this.h === this.N) {
  1836. throw new RangeError("Tree iterator access denied!");
  1837. }
  1838. this.h = this.h.next();
  1839. return this;
  1840. };
  1841. } else {
  1842. n.pre = function() {
  1843. if (this.h === this.N.J) {
  1844. throw new RangeError("Tree iterator access denied!");
  1845. }
  1846. this.h = this.h.next();
  1847. return this;
  1848. };
  1849. n.next = function() {
  1850. if (this.h === this.N) {
  1851. throw new RangeError("Tree iterator access denied!");
  1852. }
  1853. this.h = this.h.pre();
  1854. return this;
  1855. };
  1856. }
  1857. return n;
  1858. }
  1859. Object.defineProperty(TreeIterator.prototype, "index", {
  1860. get: function() {
  1861. var t = this.h;
  1862. var i = this.N.F;
  1863. if (t === this.N) {
  1864. if (i) {
  1865. return i.K - 1;
  1866. }
  1867. return 0;
  1868. }
  1869. var e = 0;
  1870. if (t.G) {
  1871. e += t.G.K;
  1872. }
  1873. while (t !== i) {
  1874. var r = t.F;
  1875. if (t === r.J) {
  1876. e += 1;
  1877. if (r.G) {
  1878. e += r.G.K;
  1879. }
  1880. }
  1881. t = r;
  1882. }
  1883. return e;
  1884. },
  1885. enumerable: false,
  1886. configurable: true
  1887. });
  1888. TreeIterator.prototype.equals = function(t) {
  1889. return this.h === t.h;
  1890. };
  1891. return TreeIterator;
  1892. }(i);
  1893. var O = function(t) {
  1894. __extends(OrderedSetIterator, t);
  1895. function OrderedSetIterator() {
  1896. return t !== null && t.apply(this, arguments) || this;
  1897. }
  1898. Object.defineProperty(OrderedSetIterator.prototype, "pointer", {
  1899. get: function() {
  1900. if (this.h === this.N) {
  1901. throw new RangeError("OrderedSet iterator access denied!");
  1902. }
  1903. return this.h.B;
  1904. },
  1905. enumerable: false,
  1906. configurable: true
  1907. });
  1908. OrderedSetIterator.prototype.copy = function() {
  1909. return new OrderedSetIterator(this.h, this.N, this.iteratorType);
  1910. };
  1911. return OrderedSetIterator;
  1912. }(p);
  1913. var b = function(t) {
  1914. __extends(OrderedSet, t);
  1915. function OrderedSet(i, e, r) {
  1916. if (i === void 0) {
  1917. i = [];
  1918. }
  1919. var n = t.call(this, e, r) || this;
  1920. n.ft = function(t) {
  1921. return __generator(this, (function(i) {
  1922. switch (i.label) {
  1923. case 0:
  1924. if (t === undefined) return [ 2 ];
  1925. return [ 5, __values(this.ft(t.G)) ];
  1926. case 1:
  1927. i.sent();
  1928. return [ 4, t.B ];
  1929. case 2:
  1930. i.sent();
  1931. return [ 5, __values(this.ft(t.J)) ];
  1932. case 3:
  1933. i.sent();
  1934. return [ 2 ];
  1935. }
  1936. }));
  1937. };
  1938. i.forEach((function(t) {
  1939. return n.insert(t);
  1940. }));
  1941. return n;
  1942. }
  1943. OrderedSet.prototype.begin = function() {
  1944. return new O(this.N.G || this.N, this.N);
  1945. };
  1946. OrderedSet.prototype.end = function() {
  1947. return new O(this.N, this.N);
  1948. };
  1949. OrderedSet.prototype.rBegin = function() {
  1950. return new O(this.N.J || this.N, this.N, 1);
  1951. };
  1952. OrderedSet.prototype.rEnd = function() {
  1953. return new O(this.N, this.N, 1);
  1954. };
  1955. OrderedSet.prototype.front = function() {
  1956. return this.N.G ? this.N.G.B : undefined;
  1957. };
  1958. OrderedSet.prototype.back = function() {
  1959. return this.N.J ? this.N.J.B : undefined;
  1960. };
  1961. OrderedSet.prototype.forEach = function(t) {
  1962. var i, e;
  1963. var r = 0;
  1964. try {
  1965. for (var n = __values(this), s = n.next(); !s.done; s = n.next()) {
  1966. var h = s.value;
  1967. t(h, r++);
  1968. }
  1969. } catch (t) {
  1970. i = {
  1971. error: t
  1972. };
  1973. } finally {
  1974. try {
  1975. if (s && !s.done && (e = n.return)) e.call(n);
  1976. } finally {
  1977. if (i) throw i.error;
  1978. }
  1979. }
  1980. };
  1981. OrderedSet.prototype.getElementByPos = function(t) {
  1982. var i, e;
  1983. var r;
  1984. var n = 0;
  1985. try {
  1986. for (var s = __values(this), h = s.next(); !h.done; h = s.next()) {
  1987. var u = h.value;
  1988. if (n === t) {
  1989. r = u;
  1990. break;
  1991. }
  1992. n += 1;
  1993. }
  1994. } catch (t) {
  1995. i = {
  1996. error: t
  1997. };
  1998. } finally {
  1999. try {
  2000. if (h && !h.done && (e = s.return)) e.call(s);
  2001. } finally {
  2002. if (i) throw i.error;
  2003. }
  2004. }
  2005. return r;
  2006. };
  2007. OrderedSet.prototype.insert = function(t, i) {
  2008. this.Y(t, undefined, i);
  2009. };
  2010. OrderedSet.prototype.find = function(t) {
  2011. var i = this.ut(this.U, t);
  2012. if (i !== undefined) {
  2013. return new O(i, this.N);
  2014. }
  2015. return this.end();
  2016. };
  2017. OrderedSet.prototype.lowerBound = function(t) {
  2018. var i = this.et(this.U, t);
  2019. return new O(i, this.N);
  2020. };
  2021. OrderedSet.prototype.upperBound = function(t) {
  2022. var i = this.rt(this.U, t);
  2023. return new O(i, this.N);
  2024. };
  2025. OrderedSet.prototype.reverseLowerBound = function(t) {
  2026. var i = this.nt(this.U, t);
  2027. return new O(i, this.N);
  2028. };
  2029. OrderedSet.prototype.reverseUpperBound = function(t) {
  2030. var i = this.st(this.U, t);
  2031. return new O(i, this.N);
  2032. };
  2033. OrderedSet.prototype.union = function(t) {
  2034. var i = this;
  2035. t.forEach((function(t) {
  2036. return i.insert(t);
  2037. }));
  2038. };
  2039. OrderedSet.prototype[Symbol.iterator] = function() {
  2040. return this.ft(this.U);
  2041. };
  2042. return OrderedSet;
  2043. }(L);
  2044. var k = function(t) {
  2045. __extends(OrderedMapIterator, t);
  2046. function OrderedMapIterator() {
  2047. return t !== null && t.apply(this, arguments) || this;
  2048. }
  2049. Object.defineProperty(OrderedMapIterator.prototype, "pointer", {
  2050. get: function() {
  2051. var t = this;
  2052. if (this.h === this.N) {
  2053. throw new RangeError("OrderedMap iterator access denied");
  2054. }
  2055. return new Proxy([], {
  2056. get: function(i, e) {
  2057. if (e === "0") return t.h.B; else if (e === "1") return t.h.R;
  2058. },
  2059. set: function(i, e, r) {
  2060. if (e !== "1") {
  2061. throw new TypeError("props must be 1");
  2062. }
  2063. t.h.R = r;
  2064. return true;
  2065. }
  2066. });
  2067. },
  2068. enumerable: false,
  2069. configurable: true
  2070. });
  2071. OrderedMapIterator.prototype.copy = function() {
  2072. return new OrderedMapIterator(this.h, this.N, this.iteratorType);
  2073. };
  2074. return OrderedMapIterator;
  2075. }(p);
  2076. var S = function(t) {
  2077. __extends(OrderedMap, t);
  2078. function OrderedMap(i, e, r) {
  2079. if (i === void 0) {
  2080. i = [];
  2081. }
  2082. var n = t.call(this, e, r) || this;
  2083. n.ft = function(t) {
  2084. return __generator(this, (function(i) {
  2085. switch (i.label) {
  2086. case 0:
  2087. if (t === undefined) return [ 2 ];
  2088. return [ 5, __values(this.ft(t.G)) ];
  2089. case 1:
  2090. i.sent();
  2091. return [ 4, [ t.B, t.R ] ];
  2092. case 2:
  2093. i.sent();
  2094. return [ 5, __values(this.ft(t.J)) ];
  2095. case 3:
  2096. i.sent();
  2097. return [ 2 ];
  2098. }
  2099. }));
  2100. };
  2101. i.forEach((function(t) {
  2102. var i = __read(t, 2), e = i[0], r = i[1];
  2103. return n.setElement(e, r);
  2104. }));
  2105. return n;
  2106. }
  2107. OrderedMap.prototype.begin = function() {
  2108. return new k(this.N.G || this.N, this.N);
  2109. };
  2110. OrderedMap.prototype.end = function() {
  2111. return new k(this.N, this.N);
  2112. };
  2113. OrderedMap.prototype.rBegin = function() {
  2114. return new k(this.N.J || this.N, this.N, 1);
  2115. };
  2116. OrderedMap.prototype.rEnd = function() {
  2117. return new k(this.N, this.N, 1);
  2118. };
  2119. OrderedMap.prototype.front = function() {
  2120. if (!this.t) return undefined;
  2121. var t = this.N.G;
  2122. return [ t.B, t.R ];
  2123. };
  2124. OrderedMap.prototype.back = function() {
  2125. if (!this.t) return undefined;
  2126. var t = this.N.J;
  2127. return [ t.B, t.R ];
  2128. };
  2129. OrderedMap.prototype.forEach = function(t) {
  2130. var i, e;
  2131. var r = 0;
  2132. try {
  2133. for (var n = __values(this), s = n.next(); !s.done; s = n.next()) {
  2134. var h = s.value;
  2135. t(h, r++);
  2136. }
  2137. } catch (t) {
  2138. i = {
  2139. error: t
  2140. };
  2141. } finally {
  2142. try {
  2143. if (s && !s.done && (e = n.return)) e.call(n);
  2144. } finally {
  2145. if (i) throw i.error;
  2146. }
  2147. }
  2148. };
  2149. OrderedMap.prototype.lowerBound = function(t) {
  2150. var i = this.et(this.U, t);
  2151. return new k(i, this.N);
  2152. };
  2153. OrderedMap.prototype.upperBound = function(t) {
  2154. var i = this.rt(this.U, t);
  2155. return new k(i, this.N);
  2156. };
  2157. OrderedMap.prototype.reverseLowerBound = function(t) {
  2158. var i = this.nt(this.U, t);
  2159. return new k(i, this.N);
  2160. };
  2161. OrderedMap.prototype.reverseUpperBound = function(t) {
  2162. var i = this.st(this.U, t);
  2163. return new k(i, this.N);
  2164. };
  2165. OrderedMap.prototype.setElement = function(t, i, e) {
  2166. this.Y(t, i, e);
  2167. };
  2168. OrderedMap.prototype.find = function(t) {
  2169. var i = this.ut(this.U, t);
  2170. if (i !== undefined) {
  2171. return new k(i, this.N);
  2172. }
  2173. return this.end();
  2174. };
  2175. OrderedMap.prototype.getElementByKey = function(t) {
  2176. var i = this.ut(this.U, t);
  2177. return i ? i.R : undefined;
  2178. };
  2179. OrderedMap.prototype.getElementByPos = function(t) {
  2180. var i, e;
  2181. var r;
  2182. var n = 0;
  2183. try {
  2184. for (var s = __values(this), h = s.next(); !h.done; h = s.next()) {
  2185. var u = h.value;
  2186. if (n === t) {
  2187. r = u;
  2188. break;
  2189. }
  2190. n += 1;
  2191. }
  2192. } catch (t) {
  2193. i = {
  2194. error: t
  2195. };
  2196. } finally {
  2197. try {
  2198. if (h && !h.done && (e = s.return)) e.call(s);
  2199. } finally {
  2200. if (i) throw i.error;
  2201. }
  2202. }
  2203. return r;
  2204. };
  2205. OrderedMap.prototype.union = function(t) {
  2206. var i = this;
  2207. t.forEach((function(t) {
  2208. var e = __read(t, 2), r = e[0], n = e[1];
  2209. return i.setElement(r, n);
  2210. }));
  2211. };
  2212. OrderedMap.prototype[Symbol.iterator] = function() {
  2213. return this.ft(this.U);
  2214. };
  2215. return OrderedMap;
  2216. }(L);
  2217. var I = function(t) {
  2218. __extends(HashContainer, t);
  2219. function HashContainer(i, e) {
  2220. if (i === void 0) {
  2221. i = 16;
  2222. }
  2223. if (e === void 0) {
  2224. e = function(t) {
  2225. var i;
  2226. if (typeof t !== "string") {
  2227. i = JSON.stringify(t);
  2228. } else i = t;
  2229. var e = 0;
  2230. var r = i.length;
  2231. for (var n = 0; n < r; n++) {
  2232. var s = i.charCodeAt(n);
  2233. e = (e << 5) - e + s;
  2234. e |= 0;
  2235. }
  2236. return e >>> 0;
  2237. };
  2238. }
  2239. var r = t.call(this) || this;
  2240. if (i < 16 || (i & i - 1) !== 0) {
  2241. throw new RangeError("InitBucketNum range error");
  2242. }
  2243. r.O = r.ot = i;
  2244. r.ct = e;
  2245. return r;
  2246. }
  2247. HashContainer.prototype.clear = function() {
  2248. this.t = 0;
  2249. this.O = this.ot;
  2250. this.vt = [];
  2251. };
  2252. return HashContainer;
  2253. }(e);
  2254. var g = function(t) {
  2255. __extends(HashSet, t);
  2256. function HashSet(i, e, r) {
  2257. if (i === void 0) {
  2258. i = [];
  2259. }
  2260. var n = t.call(this, e, r) || this;
  2261. n.vt = [];
  2262. i.forEach((function(t) {
  2263. return n.insert(t);
  2264. }));
  2265. return n;
  2266. }
  2267. HashSet.prototype.I = function() {
  2268. var t = this;
  2269. if (this.O >= 1073741824) return;
  2270. var i = [];
  2271. var e = this.O;
  2272. this.O <<= 1;
  2273. var r = Object.keys(this.vt);
  2274. var n = r.length;
  2275. var _loop_1 = function(n) {
  2276. var h = parseInt(r[n]);
  2277. var u = s.vt[h];
  2278. var f = u.size();
  2279. if (f === 0) return "continue";
  2280. if (f === 1) {
  2281. var a = u.front();
  2282. i[s.ct(a) & s.O - 1] = new v([ a ], false);
  2283. return "continue";
  2284. }
  2285. var o = [];
  2286. var c = [];
  2287. u.forEach((function(i) {
  2288. var r = t.ct(i);
  2289. if ((r & e) === 0) {
  2290. o.push(i);
  2291. } else c.push(i);
  2292. }));
  2293. if (u instanceof b) {
  2294. if (o.length > 6) {
  2295. i[h] = new b(o);
  2296. } else {
  2297. i[h] = new v(o, false);
  2298. }
  2299. if (c.length > 6) {
  2300. i[h + e] = new b(c);
  2301. } else {
  2302. i[h + e] = new v(c, false);
  2303. }
  2304. } else {
  2305. i[h] = new v(o, false);
  2306. i[h + e] = new v(c, false);
  2307. }
  2308. };
  2309. var s = this;
  2310. for (var h = 0; h < n; ++h) {
  2311. _loop_1(h);
  2312. }
  2313. this.vt = i;
  2314. };
  2315. HashSet.prototype.forEach = function(t) {
  2316. var i = Object.values(this.vt);
  2317. var e = i.length;
  2318. var r = 0;
  2319. for (var n = 0; n < e; ++n) {
  2320. i[n].forEach((function(i) {
  2321. return t(i, r++);
  2322. }));
  2323. }
  2324. };
  2325. HashSet.prototype.insert = function(t) {
  2326. var i = this.ct(t) & this.O - 1;
  2327. var e = this.vt[i];
  2328. if (!e) {
  2329. this.vt[i] = new v([ t ], false);
  2330. this.t += 1;
  2331. } else {
  2332. var r = e.size();
  2333. if (e instanceof v) {
  2334. if (!e.find(t).equals(e.end())) return;
  2335. e.pushBack(t);
  2336. if (r + 1 >= 8) {
  2337. if (this.O <= 64) {
  2338. this.t += 1;
  2339. this.I();
  2340. return;
  2341. }
  2342. this.vt[i] = new b(e);
  2343. }
  2344. this.t += 1;
  2345. } else {
  2346. e.insert(t);
  2347. var n = e.size();
  2348. this.t += n - r;
  2349. }
  2350. }
  2351. if (this.t > this.O * .75) {
  2352. this.I();
  2353. }
  2354. };
  2355. HashSet.prototype.eraseElementByKey = function(t) {
  2356. var i = this.ct(t) & this.O - 1;
  2357. var e = this.vt[i];
  2358. if (!e) return;
  2359. var r = e.size();
  2360. if (r === 0) return;
  2361. if (e instanceof v) {
  2362. e.eraseElementByValue(t);
  2363. var n = e.size();
  2364. this.t += n - r;
  2365. } else {
  2366. e.eraseElementByKey(t);
  2367. var n = e.size();
  2368. this.t += n - r;
  2369. if (n <= 6) {
  2370. this.vt[i] = new v(e);
  2371. }
  2372. }
  2373. };
  2374. HashSet.prototype.find = function(t) {
  2375. var i = this.ct(t) & this.O - 1;
  2376. var e = this.vt[i];
  2377. if (!e) return false;
  2378. return !e.find(t).equals(e.end());
  2379. };
  2380. HashSet.prototype[Symbol.iterator] = function() {
  2381. return function() {
  2382. var t, i, e, r, n, s, h, u;
  2383. var f, a;
  2384. return __generator(this, (function(o) {
  2385. switch (o.label) {
  2386. case 0:
  2387. t = Object.values(this.vt);
  2388. i = t.length;
  2389. e = 0;
  2390. o.label = 1;
  2391. case 1:
  2392. if (!(e < i)) return [ 3, 10 ];
  2393. r = t[e];
  2394. o.label = 2;
  2395. case 2:
  2396. o.trys.push([ 2, 7, 8, 9 ]);
  2397. n = (f = void 0, __values(r)), s = n.next();
  2398. o.label = 3;
  2399. case 3:
  2400. if (!!s.done) return [ 3, 6 ];
  2401. h = s.value;
  2402. return [ 4, h ];
  2403. case 4:
  2404. o.sent();
  2405. o.label = 5;
  2406. case 5:
  2407. s = n.next();
  2408. return [ 3, 3 ];
  2409. case 6:
  2410. return [ 3, 9 ];
  2411. case 7:
  2412. u = o.sent();
  2413. f = {
  2414. error: u
  2415. };
  2416. return [ 3, 9 ];
  2417. case 8:
  2418. try {
  2419. if (s && !s.done && (a = n.return)) a.call(n);
  2420. } finally {
  2421. if (f) throw f.error;
  2422. }
  2423. return [ 7 ];
  2424. case 9:
  2425. ++e;
  2426. return [ 3, 1 ];
  2427. case 10:
  2428. return [ 2 ];
  2429. }
  2430. }));
  2431. }.bind(this)();
  2432. };
  2433. return HashSet;
  2434. }(I);
  2435. var T = function(t) {
  2436. __extends(HashMap, t);
  2437. function HashMap(i, e, r) {
  2438. if (i === void 0) {
  2439. i = [];
  2440. }
  2441. var n = t.call(this, e, r) || this;
  2442. n.vt = [];
  2443. i.forEach((function(t) {
  2444. return n.setElement(t[0], t[1]);
  2445. }));
  2446. return n;
  2447. }
  2448. HashMap.prototype.I = function() {
  2449. var t = this;
  2450. if (this.O >= 1073741824) return;
  2451. var i = [];
  2452. var e = this.O;
  2453. this.O <<= 1;
  2454. var r = Object.keys(this.vt);
  2455. var n = r.length;
  2456. var _loop_1 = function(n) {
  2457. var h = parseInt(r[n]);
  2458. var u = s.vt[h];
  2459. var f = u.size();
  2460. if (f === 0) return "continue";
  2461. if (f === 1) {
  2462. var a = u.front();
  2463. i[s.ct(a[0]) & s.O - 1] = new v([ a ], false);
  2464. return "continue";
  2465. }
  2466. var o = [];
  2467. var c = [];
  2468. u.forEach((function(i) {
  2469. var r = t.ct(i[0]);
  2470. if ((r & e) === 0) {
  2471. o.push(i);
  2472. } else c.push(i);
  2473. }));
  2474. if (u instanceof S) {
  2475. if (o.length > 6) {
  2476. i[h] = new S(o);
  2477. } else {
  2478. i[h] = new v(o, false);
  2479. }
  2480. if (c.length > 6) {
  2481. i[h + e] = new S(c);
  2482. } else {
  2483. i[h + e] = new v(c, false);
  2484. }
  2485. } else {
  2486. i[h] = new v(o, false);
  2487. i[h + e] = new v(c, false);
  2488. }
  2489. };
  2490. var s = this;
  2491. for (var h = 0; h < n; ++h) {
  2492. _loop_1(h);
  2493. }
  2494. this.vt = i;
  2495. };
  2496. HashMap.prototype.forEach = function(t) {
  2497. var i = Object.values(this.vt);
  2498. var e = i.length;
  2499. var r = 0;
  2500. for (var n = 0; n < e; ++n) {
  2501. i[n].forEach((function(i) {
  2502. return t(i, r++);
  2503. }));
  2504. }
  2505. };
  2506. HashMap.prototype.setElement = function(t, i) {
  2507. var e, r;
  2508. var n = this.ct(t) & this.O - 1;
  2509. var s = this.vt[n];
  2510. if (!s) {
  2511. this.t += 1;
  2512. this.vt[n] = new v([ [ t, i ] ], false);
  2513. } else {
  2514. var h = s.size();
  2515. if (s instanceof v) {
  2516. try {
  2517. for (var u = __values(s), f = u.next(); !f.done; f = u.next()) {
  2518. var a = f.value;
  2519. if (a[0] === t) {
  2520. a[1] = i;
  2521. return;
  2522. }
  2523. }
  2524. } catch (t) {
  2525. e = {
  2526. error: t
  2527. };
  2528. } finally {
  2529. try {
  2530. if (f && !f.done && (r = u.return)) r.call(u);
  2531. } finally {
  2532. if (e) throw e.error;
  2533. }
  2534. }
  2535. s.pushBack([ t, i ]);
  2536. if (h + 1 >= 8) {
  2537. if (this.O <= 64) {
  2538. this.t += 1;
  2539. this.I();
  2540. return;
  2541. }
  2542. this.vt[n] = new S(this.vt[n]);
  2543. }
  2544. this.t += 1;
  2545. } else {
  2546. s.setElement(t, i);
  2547. var o = s.size();
  2548. this.t += o - h;
  2549. }
  2550. }
  2551. if (this.t > this.O * .75) {
  2552. this.I();
  2553. }
  2554. };
  2555. HashMap.prototype.getElementByKey = function(t) {
  2556. var i, e;
  2557. var r = this.ct(t) & this.O - 1;
  2558. var n = this.vt[r];
  2559. if (!n) return undefined;
  2560. if (n instanceof S) {
  2561. return n.getElementByKey(t);
  2562. } else {
  2563. try {
  2564. for (var s = __values(n), h = s.next(); !h.done; h = s.next()) {
  2565. var u = h.value;
  2566. if (u[0] === t) return u[1];
  2567. }
  2568. } catch (t) {
  2569. i = {
  2570. error: t
  2571. };
  2572. } finally {
  2573. try {
  2574. if (h && !h.done && (e = s.return)) e.call(s);
  2575. } finally {
  2576. if (i) throw i.error;
  2577. }
  2578. }
  2579. return undefined;
  2580. }
  2581. };
  2582. HashMap.prototype.eraseElementByKey = function(t) {
  2583. var i, e;
  2584. var r = this.ct(t) & this.O - 1;
  2585. var n = this.vt[r];
  2586. if (!n) return;
  2587. if (n instanceof v) {
  2588. var s = 0;
  2589. try {
  2590. for (var h = __values(n), u = h.next(); !u.done; u = h.next()) {
  2591. var f = u.value;
  2592. if (f[0] === t) {
  2593. n.eraseElementByPos(s);
  2594. this.t -= 1;
  2595. return;
  2596. }
  2597. s += 1;
  2598. }
  2599. } catch (t) {
  2600. i = {
  2601. error: t
  2602. };
  2603. } finally {
  2604. try {
  2605. if (u && !u.done && (e = h.return)) e.call(h);
  2606. } finally {
  2607. if (i) throw i.error;
  2608. }
  2609. }
  2610. } else {
  2611. var a = n.size();
  2612. n.eraseElementByKey(t);
  2613. var o = n.size();
  2614. this.t += o - a;
  2615. if (o <= 6) {
  2616. this.vt[r] = new v(n);
  2617. }
  2618. }
  2619. };
  2620. HashMap.prototype.find = function(t) {
  2621. var i, e;
  2622. var r = this.ct(t) & this.O - 1;
  2623. var n = this.vt[r];
  2624. if (!n) return false;
  2625. if (n instanceof S) {
  2626. return !n.find(t).equals(n.end());
  2627. }
  2628. try {
  2629. for (var s = __values(n), h = s.next(); !h.done; h = s.next()) {
  2630. var u = h.value;
  2631. if (u[0] === t) return true;
  2632. }
  2633. } catch (t) {
  2634. i = {
  2635. error: t
  2636. };
  2637. } finally {
  2638. try {
  2639. if (h && !h.done && (e = s.return)) e.call(s);
  2640. } finally {
  2641. if (i) throw i.error;
  2642. }
  2643. }
  2644. return false;
  2645. };
  2646. HashMap.prototype[Symbol.iterator] = function() {
  2647. return function() {
  2648. var t, i, e, r, n, s, h, u;
  2649. var f, a;
  2650. return __generator(this, (function(o) {
  2651. switch (o.label) {
  2652. case 0:
  2653. t = Object.values(this.vt);
  2654. i = t.length;
  2655. e = 0;
  2656. o.label = 1;
  2657. case 1:
  2658. if (!(e < i)) return [ 3, 10 ];
  2659. r = t[e];
  2660. o.label = 2;
  2661. case 2:
  2662. o.trys.push([ 2, 7, 8, 9 ]);
  2663. n = (f = void 0, __values(r)), s = n.next();
  2664. o.label = 3;
  2665. case 3:
  2666. if (!!s.done) return [ 3, 6 ];
  2667. h = s.value;
  2668. return [ 4, h ];
  2669. case 4:
  2670. o.sent();
  2671. o.label = 5;
  2672. case 5:
  2673. s = n.next();
  2674. return [ 3, 3 ];
  2675. case 6:
  2676. return [ 3, 9 ];
  2677. case 7:
  2678. u = o.sent();
  2679. f = {
  2680. error: u
  2681. };
  2682. return [ 3, 9 ];
  2683. case 8:
  2684. try {
  2685. if (s && !s.done && (a = n.return)) a.call(n);
  2686. } finally {
  2687. if (f) throw f.error;
  2688. }
  2689. return [ 7 ];
  2690. case 9:
  2691. ++e;
  2692. return [ 3, 1 ];
  2693. case 10:
  2694. return [ 2 ];
  2695. }
  2696. }));
  2697. }.bind(this)();
  2698. };
  2699. return HashMap;
  2700. }(I);
  2701. t.Deque = f;
  2702. t.HashMap = T;
  2703. t.HashSet = g;
  2704. t.LinkList = w;
  2705. t.OrderedMap = S;
  2706. t.OrderedSet = b;
  2707. t.PriorityQueue = o;
  2708. t.Queue = a;
  2709. t.Stack = n;
  2710. t.Vector = v;
  2711. Object.defineProperty(t, "dt", {
  2712. value: true
  2713. });
  2714. }));