# bzoj3809 Gty的二逼妹子序列

27s太恐怖了

 1 #include<algorithm>
2 #include<iostream>
3 #include<cstdlib>
4 #include<cstring>
5 #include<cstdio>
6 #include<string>
7 #include<cmath>
8 #include<ctime>
9 #include<queue>
10 #include<stack>
11 #include<map>
12 #include<set>
13 #define rre(i,r,l) for(int i=(r);i>=(l);i--)
14 #define re(i,l,r) for(int i=(l);i<=(r);i++)
15 #define Clear(a,b) memset(a,b,sizeof(a))
16 #define inout(x) printf("%d",(x))
17 #define douin(x) scanf("%lf",&x)
18 #define strin(x) scanf("%s",(x))
19 #define LLin(x) scanf("%lld",&x)
20 #define op operator
21 #define CSC main
22 typedef unsigned long long ULL;
23 typedef const int cint;
24 typedef long long LL;
25 using namespace std;
26 void inin(int &ret)
27 {
28     ret=0;int f=0;char ch=getchar();
29     while(ch<'0'||ch>'9'){if(ch=='-')f=1;ch=getchar();}
30     while(ch>='0'&&ch<='9')ret*=10,ret+=ch-'0',ch=getchar();
31     ret=f?-ret:ret;
32 }
33 int n,m,a[100010],wei[100010],l[1010],r[1010],s[100010],shu[1010];
34 struct que
35 {
36     int l,r,a,b,id;
37     void in(int i){inin(l),inin(r),inin(a),inin(b),id=i;}
38     bool op < (const que &rhs)const {return wei[l]==wei[rhs.l]?r<rhs.r:l<rhs.l;}
39 }q[1000010];
40 int ans[1000010];
41 int query(int aa,int bb)
42 {
43     int ll=wei[aa],rr=wei[bb];
44     int ret=0;
45     re(i,ll+1,rr-1)ret+=shu[i];
46     if(ll==rr)
47     {
48         re(i,aa,bb)if(s[i])ret++;
49         return ret;
50     }
51     re(i,aa,r[ll])if(s[i])ret++;
52     re(i,l[rr],bb)if(s[i])ret++;
53     return ret;
54 }
56 {
57     s[x]++;
58     if(s[x]==1)shu[wei[x]]++;
59 }
60 void del(int x)
61 {
62     s[x]--;
63     if(s[x]==0)shu[wei[x]]--;
64 }
65 int CSC()
66 {
67     inin(n);inin(m);int nn=sqrt(n);
68     re(i,1,n)inin(a[i]);
69     re(i,1,n)
70     {
71         wei[i]=(i-1)/nn+1;
72         r[wei[i]]=i;
73         if(!l[wei[i]])l[wei[i]]=i;
74     }
75     re(i,1,m)q[i].in(i);
76     sort(q+1,q+m+1);
77     int l=1,r=0;
78     re(i,1,m)
79     {
88 }