結果
| 問題 |
No.878 Range High-Element Query
|
| コンテスト | |
| ユーザー |
sasa8uyauya
|
| 提出日時 | 2024-09-09 19:00:02 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 761 ms / 2,000 ms |
| コード長 | 644 bytes |
| コンパイル時間 | 252 ms |
| コンパイル使用メモリ | 82,184 KB |
| 実行使用メモリ | 113,432 KB |
| 最終ジャッジ日時 | 2024-09-09 19:00:10 |
| 合計ジャッジ時間 | 7,551 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 18 |
ソースコード
n,q=map(int,input().split())
a=list(map(int,input().split()))+[10**10]
e=[]
s=[-1]
for i in range(n):
while a[s[-1]]<a[i]:
s.pop()
e+=[(i,0,s[-1]+1,i)]
s+=[i]
for i in range(q):
t,l,r=map(int,input().split())
l-=1
r-=1
e+=[(r,1,l,i)]
e.sort()
B=317
st1=[0]*B*B
st2=[0]*B
ans=[0]*q
for _,f,p1,p2 in e:
if f==0:
l,r=p1,p2
st1[l]+=1
st2[l//B]+=1
st1[r+1]-=1
st2[(r+1)//B]-=1
else:
r,i=p1,p2
l=0
a=0
yl=l//B
yr=r//B
if yl==yr:
a+=sum(st1[l:r+1])
else:
a+=sum(st1[l:yl*B+B])
a+=sum(st1[yr*B:r+1])
a+=sum(st2[yl+1:yr])
ans[i]=a
print(*ans,sep="\n")
sasa8uyauya