Submission #43229129
Source Code Expand
class BIT def initialize a,n @a = a @n = n+1 # accessing 0..n-1, 1..n internally. end def [] i i += 1 s = 0 while 0<i s += @a[i] i &= i-1 end return s end def lb s i,t,b = 0,0,1<<(@n-1).bit_length t += @a[i|=b] if i|b<@n && t+@a[i|b]<s while 0<b >>= 1 return i if i<@n-1 # i は1大きい内部インデックス(もしくは 0)だけど、求めた添字が s 未満の値を返す最大の添字であり、s の lower_bound としては +1 したものを返したいから、足し引きして内部インデックスそのままの値を返す(アクセス可能な範囲(0...@n-1)なら)。 end def add i,d i += 1 while i<@n @a[i] += d i += i&-i end end def inc i; add i,1 end def dec i; add i,-1 end end Qry = gets.to_i.times.map{ gets.split.map(&:to_i) } Xs = Qry.map{_2}.compact.uniq.sort I = Xs.each_with_index.to_h A = [] X = BIT.new [0]*(I.size+1),I.size T = Hash.new w = 0 DT = Hash.new 0 XOR = BIT.new Hash.new(0),1<<30 Qry.each{|c,x| case c when 1 DT[x] += 1 when 2 DT[x] -= 1 else DT.each{|x,d| next if d==0 ix = I[x] t = T[x] T[x] += d w += 1 if t<2 && 1<T[x] w -= 1 if 1<t && T[x]<2 if t<1 X.inc ix xv = X[ix] l = Xs[X.lb xv-1] r = Xs[X.lb(xv+1)||I.size] XOR.inc l^x if 0<T[l] && l<x XOR.inc x^r if r XOR.dec l^r if 0<T[l] && l<x && r end if T[x]<1 xv = X[ix] l = Xs[X.lb xv-1] r = Xs[X.lb(xv+1)||I.size] X.dec ix XOR.dec l^x if 0<T[l] && l<x XOR.dec x^r if r XOR.inc l^r if 0<T[l] && l<x && r end }.clear A.push 0<w ? 0 : XOR.lb(1) end } puts A
Submission Info
Submission Time | |
---|---|
Task | G - Minimum Xor Pair Query |
User | ds14050 |
Language | Ruby (2.7.1) |
Score | 0 |
Code Size | 1702 Byte |
Status | TLE |
Exec Time | 3311 ms |
Memory | 123876 KiB |
Judge Result
Set Name | Sample | All | ||||||
---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 600 | ||||||
Status |
|
|
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 | 59 ms | 14248 KiB |
01_test_01.txt | TLE | 3292 ms | 68164 KiB |
01_test_02.txt | TLE | 3287 ms | 68200 KiB |
01_test_03.txt | TLE | 3234 ms | 68016 KiB |
01_test_04.txt | TLE | 3310 ms | 67688 KiB |
01_test_05.txt | TLE | 3310 ms | 68196 KiB |
01_test_06.txt | TLE | 3310 ms | 68232 KiB |
01_test_07.txt | TLE | 3310 ms | 68700 KiB |
01_test_08.txt | TLE | 3310 ms | 68328 KiB |
01_test_09.txt | AC | 2741 ms | 122372 KiB |
01_test_10.txt | AC | 2669 ms | 122412 KiB |
01_test_11.txt | AC | 2806 ms | 123704 KiB |
01_test_12.txt | AC | 2809 ms | 123876 KiB |
01_test_13.txt | AC | 2797 ms | 89076 KiB |
01_test_14.txt | AC | 2830 ms | 83800 KiB |
01_test_15.txt | AC | 2798 ms | 69440 KiB |
01_test_16.txt | AC | 2825 ms | 70016 KiB |
01_test_17.txt | AC | 504 ms | 42948 KiB |
01_test_18.txt | TLE | 3311 ms | 83328 KiB |
01_test_19.txt | TLE | 3311 ms | 86880 KiB |
01_test_20.txt | TLE | 3310 ms | 69568 KiB |
01_test_21.txt | TLE | 3310 ms | 68384 KiB |
01_test_22.txt | TLE | 3310 ms | 67300 KiB |
01_test_23.txt | TLE | 3310 ms | 67468 KiB |
01_test_24.txt | AC | 434 ms | 42668 KiB |