CDQ模板 陌上花开

#include
using namespace std;

struct fastio
{
    fastio&operator-(int&a)
    {
        a=0; int n=0; char c=getchar();
        while(c<'0'||c>'9') c=='-'&&(n=1), c=getchar();
        while(c>='0'&&c<='9') a=a*10+(c&15), c=getchar();
        n&&(a=-a); return *this;
    }
}is;
const int N = 200005;
struct BIT
{
    int n, a[N];
    void add(int x, int delta)
    {
        for(;x<=n;x+=x&-x) a[x]+=delta;
    }
    int query(int x)
    {
        int ans = 0;
        for(;x;x-=x&-x) ans += a[x];
        return ans;
    }
}bit;

struct Object
{
    int x,y,z,c,ans;
}a[N];
bool cmpx(const Object&a, const Object&b)
{
    return
    a.x^b.x ?a.x>1;
    cdq(l, mid); cdq(mid+1, r);
    sort(a+l, a+mid+1, cmpy); sort(a+mid+1, a+r+1, cmpy);
    int i=mid+1, j=l;
    for(;i<=r; i++)
    {
        while(a[j].y<=a[i].y && j<=mid) bit.add(a[j].z, a[j].c), j++;
        a[i].ans += bit.query(a[i].z);
    }
    for(int k=l; k

你可能感兴趣的:(CDQ模板 陌上花开)