ã風åã§æãã¤ããã·ãªã¼ãºã§ãã
ã§ããæä½ã¯æ¬¡ã®éãã§ãã
- $\texttt{new}()$
- $â $ ã§åæåãã
- $S.\texttt{insert}(x)$
- $S â S ⪠\{x\}$ ã§æ´æ°ãã
- $S.\texttt{remove}(x)$
- $S â S \smallsetminus \{x\}$ ã§æ´æ°ãã
- $S.\texttt{less}(a)$
- $\max {\{xâS \mid x\lt a\}}$ ãè¿ã
- $S.\texttt{lesseq}(a)$
- $\max {\{xâS \mid x\le a\}}$ ãè¿ã
ãããã«ã¤ãã¦ãåå´ $O(\log(n)^2)$ æéã§å¦çãã¾ãã$n$ ã¯ãã®æç¹ã®ã¯ã¨ãªæ°ã ã£ããã$|S|$ ã«æ¹åã§ããããã¾ãã
åºæ¬æ¹é
éçãã¼ã¿æ§é ã $\log(n)$ åæã¤ãã¨ã§åçã«ãããã¯ã§ãã
åºéæå°å¤ãæ±ããã»ã°æ¨ã $\log(n)$ åæã¡ã¾ãã $i$ çªç®ã®ã»ã°æ¨ã¯ãé·ãã $0$ ã¾ã㯠$2^i$ ã®ããããã§ãã
$S.\texttt{insert}(x)$ ã®éã¯ãé·ãã $0$ ã¨ãªãã»ã°æ¨ã®ãã¡çªå·ãæå°ã®ãã®ã $i$ çªã ã¨ãã¦ã$[0\ldots i)$ çªç®ã®ã»ã°æ¨ã®è¦ç´ 㨠$x$ ãæé ã«é£çµãããã»ã°æ¨ã $i$ çªç®ã«ç½®ãã$[0\ldots i)$ çªç®ã®ã»ã°æ¨ã¯ç©ºã«ãã¾ãã
$S.\texttt{remove}(x)$ ã®éã¯ãã»ã°æ¨ä¸ã®äºåæ¢ç´¢ãè¡ããã¨ã§ $x$ ã®æ¤ç´¢ãè¡ããã¨ãã§ãããããè¦ã¤ãã£ãå ´å㯠$â$ ã§æ´æ°ãã¾ããåã»ã°æ¨ã«ã¤ãã¦æ¤ç´¢ãè¡ãã¾ãã
$S.\texttt{less}(a)$ ã $S.\texttt{lesseq}(a)$ ã®éã¯ãåã»ã°æ¨ã«å¯¾ãã¦äºåæ¢ç´¢ãè¡ããæ¡ä»¶ãæºããæ大ã®å ï¼ç©ºã®å ´åã¯ç¡è¦ï¼ãéããå ¨ä½ã®æ大å¤ãæ±ãã¾ãã
ç´°é¨
æéå¤ã ãè¦ãã¨æé ã«ä¸¦ãã§ãã¾ããã$â$ ãå ¥ããã¨ãããã®ã§ãæ°ãã¤ãã¦å ´ååãããã¾ãã
æ¿å ¥ã®éãéè¤ãã¦è¦ç´ ãå ¥ããªãããã«æ³¨æãã¾ããããå ¥ãããå ´åã注æãã¾ãã
$[0\ldots i)$ çªç®ã®ã»ã°æ¨ã¨ $\{x\}$ ãçµã¿åããããã¼ãã§ã¯ããã¼ã¸ã½ã¼ãã§ä½¿ããµãã«ã¼ãã³ã®è¦é ã§ãã½ã¼ãæ¸ã¿ã®åäºã¤ãã½ã¼ãæ¸ã¿ã«ãªãããã«ä¸¦ã¹ã¾ããçæ¯æ°åã®åã®å½¢ã«ãªãã®ã§ã$O(2^i)$ æéã§å¯è½ã§ãã $i$ çªç®ã®ã»ã°æ¨ãä½ãããã«ã¯ $2^i$ åã®æ¿å ¥ãå¿ è¦ãªãããã»ã°æ¨ã®é¨åã«é¢ãã¦ã¯åå´ $O(1)$ æéã§ãã æ¿å ¥æä½ã®åã«éè¤ã®ç¢ºèªãå ¥ãã$O(\log(n)^2)$ æéã§ãã
åé¤ã®éã$i$ çªç®ã®ã»ã°æ¨ã« $â$ ã $2^{i-1}$ å以ä¸ã§ããå ´åã$i-1$ çªç®ã®ã»ã°æ¨ã®é·ãã $0$ ã§ããã°éæ ¼ãããããããã§ãªãå ´åã¯çµ±åãããï¼$i-1$ çªç®ã®ã»ã°æ¨ã®è¦ç´ ã¨ãã£ã¤ã㦠$i$ çªç®ã®ã»ã°æ¨ãåæ§ç¯ããï¼ãã¨ãã§ãã¾ããããã«ãããå ¨ä½ã®ãã¡ã® $â$ ãååæªæºã«ãªãããã«ã§ãã管çããè¦ç´ ã $2|S|$ ç¨åº¦ã§æãããã¾ãã
successor query ã«å¯¾å¿ãããå ´åãåããã®ãéåãã®æ¯è¼é¢æ°ã§æ§ç¯ãã¦ãããã§ãããé£ãåãè¦ç´ ã®æ·»åã管çãããªã©ã§å¯¾å¿ãã¦ãããã§ãã
å®è£
ããã¾ãããRust ã§ãã æ¬å½ã¯ Python ã®ãã¨ãèãã¦æãã¤ããã®ã§ãããPython ã§å®è£ ãã¦éããªãæ°ãããªãã£ãã®ã§å®è£ ãã¦ãã¾ãããæå¿ã®æ¹ã«ãé¡ããã¾ãã æ¡ã®å® Rust ã§ãååé ãã£ãã§ãã
æ®éã« TLE ããã¨æã£ã¦ãããã§ããã9170 ms / 10 s ã§éã«åã£ãã®ã§ããããã£ãã§ãã
ãã®ä»
å¤ã®åé¤ã¨ predecessor query ã¨è¦ç´ ã®åæãé«éã«ã§ãããã¼ã¿æ§é ã§ããã°ãã»ã°æ¨ã®é¨åã¯ç½®ãæãããããã§ãã
ã¾ããä»åã¯åã»ã°æ¨ã§ã®çãã® max ãèãã¾ãããããã®ããã«ããã¤ãã«åå²ãããã®ã§ã®çããçµã¿åãããããã¿ã¤ãã®ã¯ã¨ãªã§ããã°ãå¥ã®ç¨®é¡ã®ã¯ã¨ãªã«ãçãããããã§ãã
ä¾ï¼AhoâCorasick ã®ãã¤
æ°å¹´åã«æ¸ããè¨äºã§ãããææ³ã¯ããã¨åãã§ããä»ã«ããbinomial heap ãä¼¼ããããªæã㧠$2^i$ ãµã¤ãºãã¨ã«åããããã¾ããã
ãã¨ãã
ãµã¨ããã¨ãã«æãã¤ãã log åæªãç³»ã®ãã¼ã¿æ§é ã§ãããä»ã«ã¯ãåºéã管çãããã¼ã¿æ§é ãããããã¨ã«æã¤ãã¨ã§ RUQ ãããã¤ãï¼èªåã®ä¸ã§ã¯ï¼å°è±¡æ·±ãã§ãã
ããã¯ãç¿æ´ããã¦ããã¨ãã«æãã¤ããã·ãªã¼ãºã§ããã
æµ®åå°æ°ç¹æ°ã®è¨äºã¯ã¾ã æéããããããã§ãããã¿ã¾ããã
ããã
ãããããµãã£ã¨ããè¨äºãããã§ããã