"bzoj3809" Gty of two forced sister sequence December 21, 2014 1,03512descriptionautumn and Bakser again in the study of gty sister sequence! But they were confronted with a difficult problem. For a few girls, they want you to help find out the beauty of the beauty of the ∈[a,b] the number of species. For convenience, we stipulate that the beauty of the sisters is all in [1,n]. Given a positive integer sequence S (1<=si<=n) of length n (1<=n<=100000), for M (1<=m<=1000000) queries "L,r,a,b", each output SL...SR, weight ∈[a,b] The number of weights of the type. The first line of input consists of two integers, n,m (1<=n<=100000,1<=m<=1000000), representing the number of elements and the number of queries in the sequence S. The second line consists of n integers s1...sn (1<=si<=n). Next m line, each line consists of 4 integers l,r,a,b (1<=l<=r<=n,1<=a<=b<=n), the meaning is described in the topic. Ensure that all the numbers involved are within the C + + int. Ensure that the input is valid. Output for each query, outputs a single line that represents the number of weights of weights ∈[a,b] in the SL...SR value. Sample Input10 104 4 5 1 4 1 5 1 2 9 1 4 7 94 4 2 3 4 4 9 1 4 98 5 9 3 2 1 4Sample Output20 Part of the 02111012HINT sample explanation: 5 9 1 2 The subsequence is 4 1 5 1 2 The weights in [1,1,2] have a value of 2, so the answer is 2. 3 4 7 9 The sub-sequence is 5 1 in [7,9] weight has 5, there are 1, so the answer is 1. 4 4 2 5 The subsequence is 1 with no weights in [2,5], so the answer is 0. 2 3 4 7 A subsequence of 4 5 weights in [4,7] has 4, 5, so the answer is 2. Input/output optimizations are recommended.
I thought it was a split block,
then this block and Mo pair, let me see two different: Mo is to do with a block, but is an optimization of offline inquiry,
The process of getting the answer is still to transfer the route.
This one we block the color, ask an interval color of the kind of words, is O (sqrt (n)), and then M inquiry, Ask O (sqrt (n)), MO is n^1.5;
So the complexity is O ((m+n) *SQR (N);
1#include <iostream>
2#include <stdio.h>
3#include <string.h>
4#include <math.h>
5#include <algorithm>
6#include <queue>
7#include <vector>
8#include <stdlib.h>
9
Ten#defineINF 0x3f3f3f
One#defineN 1234567
A
-usingnamespaceStd
-
theintA[n],pos[n],block,b[n];
-intN,m,k;
-intF[n];
-structNode
+{
- intL,r,id,ans,a,b;
+}q[n];
A
atintCMP (node A,node b)
-{
-if(POS[A.L]==POS[B.L])returna.r<b.r;
- returnpos[a.l]<pos[b.l];
-}
-
in
-intCmpid (node A,node b)
to{
+returna.id<b.id;
-}
theintCn[n],b[n];
*voidAddintCintVal
${
Panax Notoginsengif(!cn[c]) ++b[pos[c];
-Cn[c]+=val;
the if(!cn[c])--b[pos[c];
+}
A
theintQueryintXintY
+{
-intans=0;
$if(Pos[x]==pos[y]) {
$ for(inti=x;i<=y;i++)
-if(Cn[i]) ans++;
-}
theElse
-{
Wuyi for(inti=pos[x]*block;i>=x;i--)
theif(Cn[i]) ans++;
- for(intI= (pos[y]-1) *block+1; i<=y;i++)
Wuif(Cn[i]) ans++;
- for(inti=pos[x]+1; i<pos[y];i++)
AboutAns+=b[i];
$}
-returnAns
-}
-voidSolve ()
A{
+intL=1, r=0;
the intans=0;
- for(intI=1; i<=m;i++)
${
the while(L<Q[I].L)
theAdd (a[l],-1), l++;//minus a[l] effects
the while(L>Q[I].L)
theL--, Add (A[l],1);//plus a[l] 's infection
- while(R>Q[I].R)
inAdd (a[r],-1), r--;//d The infection of A[r], note r-l
the while(R<Q[I].R)
theR++,add (A[r],1);//Add the infection of A[r]
About
theQ[i].ans=query (Q[I].A,Q[I].B);
the}
the}
+
-intMain ()
the{
Bayiscanf"%d%d", &n,&m);
the for(intI=1; i<=n;i++) scanf ("%d", &a[i]);
the
-BLOCK=SQRT (n);
-
the for(intI=1; i<=n;i++)
thepos[i]= (I-1)/block+1;
the
the for(intI=1; i<=m;i++)
-scanf"%d%d%d%d", &q[i].l,&q[i].r,&q[i].a,&q[i].b), q[i].id=i;
the
theSort (q+1, q+m+1, CMP);
theSolve ();
94Sort (q+1, q+m+1, cmpid);
the for(intI=1; i<=m;i++)
theprintf"%d\n", Q[i].ans);
the }
"bzoj3809" Gty's two-forced sister sequence