Submission #50881793
Source Code Expand
class ST
def initialize a,e,&op
@l = (1<<(a.size-1).bit_length)
@a = [e]*@l+a
@a<<e
@op = op
((@l+a.size-1)/2).downto(1){|i|
@a[i] = @op[*@a[i+i,2]]
}
end
def [] l,r
return if r<l
l += @l
r += @l
al = @a[l]
ar = @a[r]
while l+1<r
al = @op[al,@a[l+1]] if l&1<1
ar = @op[@a[r-1],ar] if 0<r&1
l /= 2
r /= 2
end
return l==r ? al : @op[al,ar]
end
def []= i,v
i += @l
@a[i] = v
@a[i] = @op[*@a[i+i,2]] while 0<i/=2
return v
end
end
N,Q = gets.split.map(&:to_i)
A = 0,*gets.split.map(&:to_i)
XSYT = ST.new(A.map{|a| [a,1,0,0] },[0,0,0,0]){|(x,a,y,b),(v,c,w,d)|
if x<v
if x<w
[v,c,w,d]
elsif w<x
[v,c,x,a]
else
[v,c,x,a+d]
end
elsif v<x
if y<v
[x,a,v,c]
elsif v<y
[x,a,y,b]
else
[x,a,y,b+c]
end
else
if y<w
[x,a+c,w,d]
elsif w<y
[x,a+c,y,b]
else
[x,a+c,y,b+d]
end
end
}
Q.times{
q,a,b = gets.split.map(&:to_i)
case q
when 1
XSYT[a] = [b,1,0,0]
when 2
puts XSYT[a,b][3]
end
}
Submission Info
Submission Time
2024-03-03 21:31:34+0900
Task
F - Second Largest Query
User
ds14050
Language
Ruby (ruby 3.2.2)
Score
525
Code Size
1063 Byte
Status
AC
Exec Time
1670 ms
Memory
93784 KiB
Judge Result
Set Name
Sample
All
Score / Max Score
0 / 0
525 / 525
Status
Set Name
Test Cases
Sample
sample00.txt, sample01.txt, sample02.txt
All
sample00.txt, sample01.txt, sample02.txt, testcase00.txt, testcase01.txt, testcase02.txt, testcase03.txt, testcase04.txt, testcase05.txt, testcase06.txt, testcase07.txt, testcase08.txt, testcase09.txt, testcase10.txt, testcase11.txt, testcase12.txt, testcase13.txt, testcase14.txt, testcase15.txt, testcase16.txt, testcase17.txt, testcase18.txt, testcase19.txt, testcase20.txt, testcase21.txt, testcase22.txt, testcase23.txt, testcase24.txt, testcase25.txt, testcase26.txt, testcase27.txt, testcase28.txt, testcase29.txt, testcase30.txt, testcase31.txt, testcase32.txt, testcase33.txt, testcase34.txt, testcase35.txt, testcase36.txt, testcase37.txt, testcase38.txt, testcase39.txt, testcase40.txt, testcase41.txt, testcase42.txt, testcase43.txt
Case Name
Status
Exec Time
Memory
sample00.txt
AC
135 ms
17128 KiB
sample01.txt
AC
47 ms
17072 KiB
sample02.txt
AC
47 ms
17396 KiB
testcase00.txt
AC
1600 ms
93568 KiB
testcase01.txt
AC
1633 ms
92868 KiB
testcase02.txt
AC
1514 ms
88836 KiB
testcase03.txt
AC
1618 ms
92912 KiB
testcase04.txt
AC
1420 ms
90592 KiB
testcase05.txt
AC
1503 ms
92856 KiB
testcase06.txt
AC
1541 ms
88624 KiB
testcase07.txt
AC
1650 ms
92728 KiB
testcase08.txt
AC
1634 ms
89864 KiB
testcase09.txt
AC
1646 ms
92896 KiB
testcase10.txt
AC
1483 ms
90408 KiB
testcase11.txt
AC
1529 ms
92816 KiB
testcase12.txt
AC
1542 ms
88592 KiB
testcase13.txt
AC
1670 ms
92900 KiB
testcase14.txt
AC
1562 ms
91988 KiB
testcase15.txt
AC
1655 ms
92616 KiB
testcase16.txt
AC
1561 ms
90180 KiB
testcase17.txt
AC
1492 ms
93764 KiB
testcase18.txt
AC
1579 ms
90536 KiB
testcase19.txt
AC
1597 ms
92876 KiB
testcase20.txt
AC
1536 ms
88228 KiB
testcase21.txt
AC
1635 ms
93784 KiB
testcase22.txt
AC
1538 ms
90088 KiB
testcase23.txt
AC
1643 ms
93500 KiB
testcase24.txt
AC
1530 ms
91704 KiB
testcase25.txt
AC
1614 ms
93032 KiB
testcase26.txt
AC
1537 ms
89408 KiB
testcase27.txt
AC
1632 ms
93596 KiB
testcase28.txt
AC
1597 ms
88476 KiB
testcase29.txt
AC
1660 ms
92968 KiB
testcase30.txt
AC
1571 ms
90148 KiB
testcase31.txt
AC
1647 ms
93608 KiB
testcase32.txt
AC
1644 ms
91848 KiB
testcase33.txt
AC
1644 ms
93056 KiB
testcase34.txt
AC
1625 ms
92680 KiB
testcase35.txt
AC
1660 ms
92980 KiB
testcase36.txt
AC
1581 ms
90436 KiB
testcase37.txt
AC
1659 ms
93036 KiB
testcase38.txt
AC
1580 ms
92532 KiB
testcase39.txt
AC
1653 ms
93440 KiB
testcase40.txt
AC
1617 ms
90328 KiB
testcase41.txt
AC
1643 ms
93672 KiB
testcase42.txt
AC
1540 ms
92980 KiB
testcase43.txt
AC
1643 ms
93580 KiB