Submission #43269537


Source Code Expand

Copy
import Control.Monad
import qualified Data.ByteString.Char8 as BS
import Data.Char
import Data.List
import Data.Bits
import qualified Data.IntMap as IM
main = do
[q] <- bsGetLnInts
foldM_ (\st _ -> do
qi <- bsGetLnInts
case qi of
(1:x:_) -> return $ mode1 st x
(2:x:_) -> return $ mode2 st x
(3:_) -> print (mode3 st) >> return st
) (IM.empty, IM.empty) [1..q]
bsGetLnInts :: IO [Int]
bsGetLnInts = BS.getLine >>= return . unfoldr (BS.readInt . BS.dropWhile isSpace)
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
import Control.Monad
import qualified Data.ByteString.Char8 as BS
import Data.Char
import Data.List

import Data.Bits
import qualified Data.IntMap as IM

main = do
  [q] <- bsGetLnInts
  foldM_ (\st _ -> do
    qi <- bsGetLnInts
    case qi of
      (1:x:_) -> return $ mode1 st x
      (2:x:_) -> return $ mode2 st x
      (3:_)   -> print (mode3 st) >> return st
    ) (IM.empty, IM.empty) [1..q]

bsGetLnInts :: IO [Int]
bsGetLnInts = BS.getLine >>= return . unfoldr (BS.readInt . BS.dropWhile isSpace)

type State =
  ( IM.IntMap Int -- 黒板の数のmultiset
  , IM.IntMap Int -- XORの値のmultiset
  )

mode1 (xm, am) x =
  case IM.lookup x xm of
    Just k  -> output1 0
    Nothing ->
      case (IM.lookupLT x xm, IM.lookupGT x xm) of
        (Nothing, Nothing) -> output0
        (Just (x0,_), Nothing) -> output1 (xor x0 x)
        (Nothing, Just (x2,_)) -> output1 (xor x2 x)
        (Just (x0,_), Just (x2,_)) -> output3 (xor x0 x2) (xor x0 x) (xor x2 x)
  where
    output am = (insertMS x xm, am)
    output0   = output am
    output1 a = output $ insertMS a am
    output3 a1 a2 a3 = output $ insertMS a3 $ insertMS a2 $ deleteMS a1 am

mode2 (xm, am) x =
  case IM.lookup x xm of
    Just k | k > 1 -> output1 0
    Just 1 ->
      case (IM.lookupLT x xm, IM.lookupGT x xm) of
        (Nothing, Nothing) -> output0
        (Just (x0,_), Nothing) -> output1 (xor x0 x)
        (Nothing, Just (x2,_)) -> output1 (xor x2 x)
        (Just (x0,_), Just (x2,_)) -> output3 (xor x0 x2) (xor x0 x) (xor x2 x)
  where
    output am = (deleteMS x xm, am)
    output0 = output am
    output1 a = output $ deleteMS a am
    output3 a1 a2 a3 = output $ insertMS a1 $ deleteMS a2 $ deleteMS a3 am

mode3 st@(_, am) = fst $ IM.findMin am

insertMS x ms = IM.insertWith (+) x 1 ms
deleteMS x ms = IM.update dec x ms
  where
    dec 1 = Nothing
    dec k = Just (pred k)

-- 公式解説のとおり
-- 不要な部分を削った

Submission Info

Submission Time
Task G - Minimum Xor Pair Query
User joetheshootingst
Language Haskell (GHC 8.8.3)
Score 600
Code Size 1998 Byte
Status AC
Exec Time 2351 ms
Memory 122188 KB

Compile Error

Loaded package environment from /home/contestant/.ghc/x86_64-linux-8.8.3/environments/default

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 1
AC × 25
Set Name Test Cases
Sample 00_sample_01.txt
All 00_sample_01.txt, 01_test_01.txt, 01_test_02.txt, 01_test_03.txt, 01_test_04.txt, 01_test_05.txt, 01_test_06.txt, 01_test_07.txt, 01_test_08.txt, 01_test_09.txt, 01_test_10.txt, 01_test_11.txt, 01_test_12.txt, 01_test_13.txt, 01_test_14.txt, 01_test_15.txt, 01_test_16.txt, 01_test_17.txt, 01_test_18.txt, 01_test_19.txt, 01_test_20.txt, 01_test_21.txt, 01_test_22.txt, 01_test_23.txt, 01_test_24.txt
Case Name Status Exec Time Memory
00_sample_01.txt AC 7 ms 3616 KB
01_test_01.txt AC 1165 ms 61148 KB
01_test_02.txt AC 1152 ms 61412 KB
01_test_03.txt AC 1193 ms 61776 KB
01_test_04.txt AC 1167 ms 61256 KB
01_test_05.txt AC 1164 ms 61816 KB
01_test_06.txt AC 1162 ms 61288 KB
01_test_07.txt AC 1196 ms 62148 KB
01_test_08.txt AC 1155 ms 61772 KB
01_test_09.txt AC 154 ms 4752 KB
01_test_10.txt AC 154 ms 4800 KB
01_test_11.txt AC 206 ms 4720 KB
01_test_12.txt AC 205 ms 4912 KB
01_test_13.txt AC 286 ms 5784 KB
01_test_14.txt AC 289 ms 6416 KB
01_test_15.txt AC 481 ms 8572 KB
01_test_16.txt AC 482 ms 7988 KB
01_test_17.txt AC 121 ms 22924 KB
01_test_18.txt AC 2345 ms 122188 KB
01_test_19.txt AC 2351 ms 122092 KB
01_test_20.txt AC 1145 ms 65804 KB
01_test_21.txt AC 1110 ms 65960 KB
01_test_22.txt AC 1563 ms 65924 KB
01_test_23.txt AC 1564 ms 65924 KB
01_test_24.txt AC 79 ms 25244 KB


2025-04-26 (Sat)
00:52:34 +00:00