Hey anyone got the correct solution, if yes the please share
#include<stdio.h>
#include
#include
#include
using namespace std;
typedef long long int ll;
// #define int ll
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mp make_pair
#define pb push_back
#define llM LONG_LONG_MAX
#define llm LONG_LONG_MIN
#define all(x) (x).begin(), (x).end()
#define endl â\nâ
#define file freopen(âinput.txtâ, ârâ, stdin), freopen(âoutput.txtâ, âwâ, stdout)
template
ostream& operator<<(ostream& COUT, vector& v){ for(int i=0 ; i<v.size() ; i++){ COUT<<v[i]<<" â; } COUT << endl; return COUT; }
template
ostream& operator<<(ostream& COUT, pair<T, T>& p){ cout << p.first <<â "<< p.second <<endl; return COUT; }
template
istream& operator>>(istream& CIN, vector& a){ for(int i=0 ; i<a.size() ; i++) CIN>>a[i]; return CIN; }
template
istream& operator>>(istream& CIN, pair<T, T>& p){ cin >> p.first >> p.second ; return CIN; }
template
T max(vector& v){ T m=v[0]; for(auto e : v){ m = max(m, e); } return m; }
template
T min(vector& v){ T m=v[0]; for(auto e : v){ m = min(m, e); } return m; }
ll mod = 1000000007;
vector tree[4*30000];
void build(int n, int l, int r, vector& a){
if(l==r) tree[n] = vector(1, a[l]);
else{
int m = (l+r)/2;
build(2n, l, m, a);
build(2n+1, m+1, r, a);
merge(tree[2n].begin(), tree[2n].end(), tree[2n+1].begin(), tree[2n+1].end(), back_inserter(tree[n]));
}
}
int query(int n, int l, int r, int ql, int qr, int k){
// cout<<ql<<" "<<qr<<endl;
if(ql>qr) return 0;
if(ql==l && qr==r){
return tree[n].end() - upper_bound(tree[n].begin(), tree[n].end(), k);
}
else{
int m = (l+r)/2;
return query(2n, l, m, ql, min(qr, m), k) +
query(2n+1, m+1, r, max(ql, m+1), qr, k);
}
}
void solve(){
int n;
cin >> n;
vector a(n);
cin >> a;
build(1, 0, n-1, a);
// cout << âdone<â<<endl;
int q;
cin >> q;
while(qâ){
int i, j, k;
cin >> i >> j >> k;
cout << query(1, 0, n-1, i-1, j-1, k) <<endl;
}
}
signed main()
{
//IOS
//file;
int T=1;
// cin >> T;
for (int i = 0; i < T; ++i){
// cout<<âCase #â<<i+1<<": ";
solve();
}
}
I am still getting TLE, please share some solution so that I can at least analyze/