export const removeElement=(t,e,n)=>{let r=t.indexOf(e);if(-1===r)return!1;if(n)return t.splice(r,1),!0;for(let o=r+1,c=t.length;o<c;++o)t[o]!==e&&(t[r++]=t[o]);return t.length=r,!0};function swap(t,e,n){const r=t[e];t[e]=t[n],t[n]=r}function partition(t,e,n,r,o){const c=t[o];swap(t,r,o);let u=n;for(let s=n;s<r;++s)e(t[s],c)<0&&(swap(t,u,s),++u);return swap(t,r,u),u}function quickSortRange(t,e,n,r,o,c){if(r<=n)return;const u=partition(t,e,n,r,Math.floor(Math.random()*(r-n))+n);o<u&&quickSortRange(t,e,n,u-1,o,c),u<c&&quickSortRange(t,e,u+1,r,o,c)}export function sortRange(t,e,n,r,o,c){return 0===n&&r===t.length-1&&0===o&&c>=r?t.sort(e):quickSortRange(t,e,n,r,o,c),t}export const binaryIndexOf=(t,e,n)=>{const r=lowerBound(t,e,n);return r<t.length&&0===n(e,t[r])?r:-1};function mergeOrIntersect(t,e,n,r){const o=[];let c=0,u=0;for(;c<t.length&&u<e.length;){const s=n(t[c],e[u]);!r&&s||o.push(s<=0?t[c]:e[u]),s<=0&&c++,s>=0&&u++}if(r){for(;c<t.length;)o.push(t[c++]);for(;u<e.length;)o.push(e[u++])}return o}export const intersectOrdered=(t,e,n)=>mergeOrIntersect(t,e,n,!1);export const mergeOrdered=(t,e,n)=>mergeOrIntersect(t,e,n,!0);export const DEFAULT_COMPARATOR=(t,e)=>t<e?-1:t>e?1:0;export function lowerBound(t,e,n,r,o){let c=r||0,u=void 0!==o?o:t.length;for(;c<u;){const r=c+u>>1;n(e,t[r])>0?c=r+1:u=r}return u}export function upperBound(t,e,n,r,o){let c=r||0,u=void 0!==o?o:t.length;for(;c<u;){const r=c+u>>1;n(e,t[r])>=0?c=r+1:u=r}return u}