Atcoder Beginner Contest 248D - Range Count Query Solution
Problem Link : https://atcoder.jp/contests/abc248/tasks/abc248_d
Solution in C++:
///La ilaha illellahu muhammadur rasulullah
///******Bismillahir-Rahmanir-Rahim******///
///Abul Hasnat Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
///**********ALLAH IS ALMIGHTY************///
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
vector<int> a(n);
vector<vector<int>>vv(n + 1);
for (int i = 0; i < n; i++)
{
cin >> a[i];
vv[a[i]].push_back(i);
}
int q;
cin >> q;
while (q--)
{
int l, r, x;
cin >> l >> r >> x;
l--;
r--;
auto rl = lower_bound(vv[x].begin(), vv[x].end(), l);
auto rr = upper_bound(vv[x].begin(), vv[x].end(), r);
cout << rr - rl << endl;
}
return 0;
}
No comments