Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- In the name of Allah, the Most Gracious, the Most Merciful.
- */
- #include <bits/stdc++.h>
- using namespace std;
- int block, ans;
- int fin[100005], cnt[55];
- struct Query
- {
- int L, R, F, I;
- };
- void add(int x) {
- cnt[x]++;
- }
- void sub(int x) {
- cnt[x]--;
- }
- bool compare(Query x, Query y)
- {
- if (x.L/block != y.L/block)
- return x.L/block < y.L/block;
- return x.R < y.R;
- }
- void fun(int ara[], int n, Query q[], int m)
- {
- block = sqrt(n);
- sort(q, q + m, compare);
- int currL = 0, currR = -1;
- for (int i=0; i<m; i++)
- {
- int L = q[i].L, R = q[i].R, ff = q[i].F;
- while (currR < R)
- {
- currR++;
- add(ara[currR]);
- }
- while (currR > R)
- {
- sub(ara[currR]);
- currR--;
- }
- while (currL < L)
- {
- sub(ara[currL]);
- currL++;
- }
- while (currL > L)
- {
- currL--;
- add(ara[currL]);
- }
- int pp = 0;
- for(int zz=1; zz<=50; zz++) {
- if(cnt[zz] >= ff) {
- pp++;
- }
- }
- fin[q[i].I] = pp;
- }
- }
- int main() {
- #ifdef _OFFLINE_
- freopen("in.txt", "r", stdin);
- #endif /// _OFFLINE_
- int n, m, r, l, f;
- scanf("%d", &n);
- int ara[n+5];
- for(int i=0; i<n; i++) {
- scanf("%d", &ara[i]);
- }
- scanf("%d", &m);
- Query q[m+5];
- for(int i=0; i<m; i++) {
- scanf("%d %d %d", &l, &r, &f);
- q[i].L = l-1;
- q[i].R = r-1;
- q[i].F = f;
- q[i].I = i;
- }
- fun(ara, n, q, m);
- for(int i=0; i<m; i++) {
- printf("%d\n", fin[i]);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement