1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
| #pragma GCC optimize("Ofast")
#pragma loop_opt(on)
#include<bits/stdc++.h>
using namespace std;
template<class T> long long Mod(T a,T b){return ((a%b)+b)%b;}
#define endl '\n'
#define ll long long
#define IO ios_base::sync_with_stdio(0); cin.tie(0);
#define GETOUT cout.tie(0);
#define gc getchar()
#define cendl cout << endl;
#define fr(bob,n,l) for(int bob=(n);bob<(l);++bob)
#define fra(ns,a) for(auto (ns):a)
#define frc(bot,ns,l) for(int bot=(ns);bot<=(l);++bot)
#define frx(i,ns,l) for(int i=(ns);i<(l);++i)
#define mem(arr,initn) memset(arr,initn,sizeof(arr))
#define ALL(va) va.begin(),va.end()
#define printv(va) {fr(i,0,size((va))){cout<<(va)[i]<< ' ';}cendl;}
#define printa(va) {fr(i,0,sizeof((va))/sizeof((va)[0])){cout << (va)[i] << ' ';}cendl;}
//#define getpos(va,v) lower_bound((v).begin(),(v).end(),(va)) - (v).begin()
#define pb emplace_back
typedef pair<int,int> pii;
#define fi first
#define se second
//#define int long long
const int MAX=1e9+7;
const int MOD=998244353;
inline int nextint(){
int x=0,w=1;char ch=0;
while(ch<'0'||ch>'9'){
if(ch == '-')w=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9')x=x*10+(ch-'0'),ch=getchar();
return x*w;
}
const int N = 100011;
vector<int> T[4*N];
int a[N];
void build(int l,int r,int idx){
if(l==r){
T[idx].pb(a[l]);
return;
}
int mid=l+r>>1;
build(l,mid,idx<<1);
build(mid+1,r,(idx<<1)|1);
merge(ALL(T[idx<<1]),ALL(T[(idx<<1)|1]),back_inserter(T[idx]));
}
int query(int ql,int qr,int l,int r,int idx,int k){
if(ql>r||qr<l) return 0;
if(ql<=l&&r<=qr) return lower_bound(ALL(T[idx]),k) - T[idx].begin();
int mid = l+r>>1;
int rt=0;
rt+=query(ql,qr,l,mid,idx<<1,k);
rt+=query(ql,qr,mid+1,r,(idx<<1)|1,k);
return rt;
}
inline void solve(){
int n;
cin >> n;
frc(i,1,n) cin >> a[i];
build(1,n,1);
int q;
cin >> q;
while(q--){
int x,y,k;
cin >> x >> y >> k;
int ans = query(x,y,1,n,1,k);
cout << ans << endl;
}
}
signed main(){
IO;
GETOUT;
int t;
t=1;
while(t--)solve();
return 0;
}
|