KQUERY - K-query

Given a sequence of n numbers a1, a2, ..., an and a number of k- queries. A k-query is a triple (i, j, k) (1 ≤ i ≤ j ≤ n). For each k-query (i, j, k), you have to return the number of elements greater than k in the subsequence ai, ai+1, ..., aj.

Input

  • Line 1: n (1 ≤ n ≤ 30000).
  • Line 2: n numbers a1, a2 ... an (1 ≤ ai ≤ 109).
  • Line 3: q (1 ≤ q ≤ 200000), the number of k- queries.
  • In the next q lines, each line contains 3 numbers i, j, k representing a k-query (1 ≤ i ≤ j ≤ n, 1 ≤ k ≤ 109).

Output

  • For each k-query (i, j, k), print the number of elements greater than k in the subsequence ai, ai+1 ... aj in a single line.

Example

Input
5
5 1 2 3 4
3
2 4 1
4 4 4
1 5 2 

Output
2
0
3 


Được gửi lên bởi:Jimmy
Ngày:2008-10-26
Thời gian chạy:1s
Giới hạn mã nguồn:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Ngôn ngữ cho phép:Tất cả ngoại trừ: ERL GOSU JS-RHINO NODEJS PERL6 PYPY RUST SED VB.NET
Nguồn bài:Gomoku

hide comments
2021-05-27 18:01:17
Tham khảo: https://vnspoj.github.io/problems/KQUERY
2021-03-01 10:36:59
chỉ có gà mới bị TLE do cin cout
mlogm :))
2020-08-28 15:15:05
mèo méo meo mèo meooo, con mèo ngu ngok đáng iu ngọt ngào cu te phô mai we xin kính chào cả nhàaaa
kimochii ư ư yameteee kư đê sai ư ư ư
2020-03-13 08:49:16
đấm hoài ko AC ai giúp với
2019-12-21 14:51:32
Segment tree
CLQD K12
2019-12-21 14:50:37
hết giới hạn đến chuyện nhập xuất
chán á
2019-12-21 14:43:44
cứ tưởng AC hóa ra lại chạy bị lỗi :(((
2019-10-19 12:51:12
http://eunsetee.com/Y5An
2019-09-26 15:26:12
thím nào TLE o trâu thì đừng có cin nhé!!!!!!!
duonght_pro_xinhgainhathemattroi_:)
2019-07-31 17:41:00
13 đấm ac vì tràn mảng :))
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.