# Bzoj 3262: 陌上花开(CDQ分治)

3262: 陌上花开
Time Limit: 20 Sec Memory Limit: 256 MB
Description

Input

Output

Sample Input
10 3
3 3 3
2 3 3
2 3 1
3 1 1
3 1 2
1 3 1
1 1 2
1 2 2
1 3 2
1 2 1
Sample Output
3
1
3
0
1
0
1
0
0
1
HINT
1 <= N <= 100,000, 1 <= K <= 200,000
Source

/*

*/
#include<cstdio>
#include<algorithm>
#include<cstring>
#define MAXN 200001
using namespace std;
int n,k,s[MAXN],tot,ans[MAXN],ansrank[MAXN];
struct data
{
int s,c,m,o,be,sum;
bool operator ==(const data &x)
{
return x.s==s&&x.c==c&&x.m==m;
}
}q[MAXN],tmp[MAXN];
{
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9') x=x*10+ch-48,ch=getchar();
return x*f;
}
{
while(x<=k) s[x]+=z,x+=x&-x;
return ;
}
int getsum(int x)
{
int sum=0;
while(x>0) sum+=s[x],x-=x&-x;
return sum;
}
bool cmp(const data &x,const data &y)
{
if(x.s==y.s&&x.c==y.c) return x.m<y.m;
if(x.s==y.s) return x.c<y.c;
return x.s<y.s;
}
bool cmp2(const data &x,const data &y)
{
if(x.c==y.c) return x.o<y.o;
return x.c<y.c;
}
void slove(int l,int r)
{
if(l==r) return ;
int mid=(l+r)>>1,ll=l,rr=mid+1,cut=0;;
for(int i=l;i<=mid;i++) q[i].o=1,tmp[ll++]=q[i];
for(int i=mid+1;i<=r;i++) q[i].o=2,tmp[rr++]=q[i];
//for(int i=l;i<=r;i++) q[i]=tmp[i];
sort(tmp+l,tmp+r+1,cmp2);
for(int i=l;i<=r;i++)
{
else ans[tmp[i].be]+=getsum(tmp[i].m);
}
slove(l,mid),slove(mid+1,r);
return ;
}
int main()
{
int t=0;
for(int i=1;i<=n;i++)
}