The problem is clearly a two-dimensional approach
to use the team offline to the query after the maintenance of two tree array, record the answer of two queries, for the second query, you can open an array, record the number of occurrences of each count
#include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <queue> #include <vector> #include <set> #include <map> #include <iostream> #include <algorithm> #
Define Lowbit (x) (x&) #define N 100010 using namespace std;
int SC () {int i=0,f=1; char C=getchar (); while (c> ' 9 ' | |
c< ' 0 ') {if (c== '-') F=-1;c=getchar ();}
while (c>= ' 0 ' &&c<= ' 9 ') i=i*10+c-' 0 ', C=getchar ();
return i*f; } struct W{int l,r,a,b,p;}
A[N*10];
int sum[n],tr[n],tr[n],v[n];
int bl[n],ans[n*10][2];
int n,m,block; BOOL CMP (W x,w y) {return bl[x.l]==bl[y.l]?x.r<y.r:bl[x.l]<bl[y.l];} void change (int x,int f,int *tr) {fo
R (; x<=n;x+=lowbit (x)) tr[x]+=f;
} int Ask (int x,int *tr) {if (x<1) return 0;
int ans=0;
for (; x;x-=lowbit (x)) ans+=tr[x];
return ans;
} void Add (int x) {change (X,1,TR);
sum[x]++;
if (sum[x]==1) change (X,1,TR);
} void del (int x) {change (X,-1,TR); SUM[X]--;
if (sum[x]==0) change (X,-1,TR);
} int main () {N=SC (), M=SC (); block=sqrt (n);
for (int i=1;i<=n;i++) {V[I]=SC ();
bl[i]= (i-1)/block+1;
} for (int i=1;i<=m;i++) A[I].L=SC (), A[I].R=SC (), A[I].A=SC (), A[I].B=SC (), a[i].p=i;
Sort (a+1,a+m+1,cmp);
int l=a[1].l,r=a[1].l-1;
for (int. i=1;i<=m;i++) {while (L<A[I].L) del (v[l++]);
while (L>A[I].L) add (V[--l]);
while (R>A[I].R) del (v[r--]);
while (R<A[I].R) add (V[++r]);
Ans[a[i].p][0]=ask (A[I].B,TR)-ask (A[I].A-1,TR);
Ans[a[i].p][1]=ask (A[I].B,TR)-ask (A[I].A-1,TR);
} for (int i=1;i<=m;i++) printf ("%d%d\n", ans[i][0],ans[i][1]);
return 0; }